@@ -29,6 +29,7 @@ import (
2929 "github.com/pkg/errors"
3030 corev1 "k8s.io/api/core/v1"
3131 apierrors "k8s.io/apimachinery/pkg/api/errors"
32+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3233 "k8s.io/apimachinery/pkg/runtime"
3334 "k8s.io/apimachinery/pkg/types"
3435 "k8s.io/client-go/tools/record"
@@ -174,6 +175,16 @@ func (r *OCIClusterReconciler) reconcileComponent(ctx context.Context, cluster *
174175 return nil
175176}
176177
178+ // SkipApiserverManagement is a hack to check for the annotation "cluster.x-k8s.io/skip-apiserver-management"
179+ func skipApiserverManagement (o metav1.Object ) bool {
180+ annotations := o .GetAnnotations ()
181+ if annotations == nil {
182+ return false
183+ }
184+ _ , ok := annotations ["cluster.x-k8s.io/skip-apiserver-lb-management" ]
185+ return ok
186+ }
187+
177188func (r * OCIClusterReconciler ) reconcile (ctx context.Context , logger logr.Logger , clusterScope scope.ClusterScopeClient , cluster * infrastructurev1beta2.OCICluster ) (ctrl.Result , error ) {
178189 // If the OCICluster doesn't have our finalizer, add it.
179190 controllerutil .AddFinalizer (cluster , infrastructurev1beta2 .ClusterFinalizer )
@@ -245,18 +256,22 @@ func (r *OCIClusterReconciler) reconcile(ctx context.Context, logger logr.Logger
245256 return ctrl.Result {}, err
246257 }
247258
248- // Reconcile the API Server LoadBalancer based on the specified LoadBalancerType.
249- loadBalancerType := cluster .Spec .NetworkSpec .APIServerLB .LoadBalancerType
250- if loadBalancerType == infrastructurev1beta2 .LoadBalancerTypeLB {
251- if err := r .reconcileComponent (ctx , cluster , clusterScope .ReconcileApiServerLB , "Api Server Loadbalancer" ,
252- infrastructurev1beta2 .APIServerLoadBalancerFailedReason , infrastructurev1beta2 .ApiServerLoadBalancerEventReady ); err != nil {
253- return ctrl.Result {}, err
259+ if ! skipApiserverManagement (cluster ) {
260+ // Reconcile the API Server LoadBalancer based on the specified LoadBalancerType.
261+ loadBalancerType := cluster .Spec .NetworkSpec .APIServerLB .LoadBalancerType
262+ if loadBalancerType == infrastructurev1beta2 .LoadBalancerTypeLB {
263+ if err := r .reconcileComponent (ctx , cluster , clusterScope .ReconcileApiServerLB , "Api Server Loadbalancer" ,
264+ infrastructurev1beta2 .APIServerLoadBalancerFailedReason , infrastructurev1beta2 .ApiServerLoadBalancerEventReady ); err != nil {
265+ return ctrl.Result {}, err
266+ }
267+ } else {
268+ if err := r .reconcileComponent (ctx , cluster , clusterScope .ReconcileApiServerNLB , "Api Server Network Loadbalancer" ,
269+ infrastructurev1beta2 .APIServerLoadBalancerFailedReason , infrastructurev1beta2 .ApiServerLoadBalancerEventReady ); err != nil {
270+ return ctrl.Result {}, err
271+ }
254272 }
255273 } else {
256- if err := r .reconcileComponent (ctx , cluster , clusterScope .ReconcileApiServerNLB , "Api Server Network Loadbalancer" ,
257- infrastructurev1beta2 .APIServerLoadBalancerFailedReason , infrastructurev1beta2 .ApiServerLoadBalancerEventReady ); err != nil {
258- return ctrl.Result {}, err
259- }
274+ logger .Info ("ApiServer Loadbalancer Reconciliation is skipped" )
260275 }
261276
262277 conditions .MarkTrue (cluster , infrastructurev1beta2 .ClusterReadyCondition )
@@ -338,20 +353,24 @@ func (r *OCIClusterReconciler) reconcileDelete(ctx context.Context, logger logr.
338353 // Declare the err variable before the if-else block
339354 var err error
340355
341- // Delete API Server LoadBalancer based on the specified LoadBalancerType
342- // If the type is LB, it calls DeleteApiServerLbsLB(),
343- // If no specific type is provided, it defaults to calling DeleteApiServerLB().
344- loadBalancerType := cluster .Spec .NetworkSpec .APIServerLB .LoadBalancerType
345- if loadBalancerType == infrastructurev1beta2 .LoadBalancerTypeLB {
346- err = clusterScope .DeleteApiServerLB (ctx )
347- } else {
348- err = clusterScope .DeleteApiServerNLB (ctx )
349- }
356+ if ! skipApiserverManagement (cluster ) {
357+ // Delete API Server LoadBalancer based on the specified LoadBalancerType
358+ // If the type is LB, it calls DeleteApiServerLbsLB(),
359+ // If no specific type is provided, it defaults to calling DeleteApiServerLB().
360+ loadBalancerType := cluster .Spec .NetworkSpec .APIServerLB .LoadBalancerType
361+ if loadBalancerType == infrastructurev1beta2 .LoadBalancerTypeLB {
362+ err = clusterScope .DeleteApiServerLB (ctx )
363+ } else {
364+ err = clusterScope .DeleteApiServerNLB (ctx )
365+ }
350366
351- if err != nil {
352- r .Recorder .Event (cluster , corev1 .EventTypeWarning , "ReconcileError" , errors .Wrapf (err , "failed to delete Api Server Loadbalancer" ).Error ())
353- conditions .MarkFalse (cluster , infrastructurev1beta2 .ClusterReadyCondition , infrastructurev1beta2 .APIServerLoadBalancerFailedReason , clusterv1 .ConditionSeverityError , "" )
354- return ctrl.Result {}, errors .Wrapf (err , "failed to delete apiserver LB for OCICluster %s/%s" , cluster .Namespace , cluster .Name )
367+ if err != nil {
368+ r .Recorder .Event (cluster , corev1 .EventTypeWarning , "ReconcileError" , errors .Wrapf (err , "failed to delete Api Server Loadbalancer" ).Error ())
369+ conditions .MarkFalse (cluster , infrastructurev1beta2 .ClusterReadyCondition , infrastructurev1beta2 .APIServerLoadBalancerFailedReason , clusterv1 .ConditionSeverityError , "" )
370+ return ctrl.Result {}, errors .Wrapf (err , "failed to delete apiserver LB for OCICluster %s/%s" , cluster .Namespace , cluster .Name )
371+ }
372+ } else {
373+ logger .Info ("ApiServer LB Reconciliation is skipped, the ApiServer Loadbalancer will not be deleted" )
355374 }
356375
357376 // This below if condition specifies if the network related infrastructure needs to be reconciled. Any new
0 commit comments