@@ -29,6 +29,7 @@ import (
29
29
"github.com/pkg/errors"
30
30
corev1 "k8s.io/api/core/v1"
31
31
apierrors "k8s.io/apimachinery/pkg/api/errors"
32
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
33
"k8s.io/apimachinery/pkg/runtime"
33
34
"k8s.io/apimachinery/pkg/types"
34
35
"k8s.io/client-go/tools/record"
@@ -174,6 +175,16 @@ func (r *OCIClusterReconciler) reconcileComponent(ctx context.Context, cluster *
174
175
return nil
175
176
}
176
177
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
+
177
188
func (r * OCIClusterReconciler ) reconcile (ctx context.Context , logger logr.Logger , clusterScope scope.ClusterScopeClient , cluster * infrastructurev1beta2.OCICluster ) (ctrl.Result , error ) {
178
189
// If the OCICluster doesn't have our finalizer, add it.
179
190
controllerutil .AddFinalizer (cluster , infrastructurev1beta2 .ClusterFinalizer )
@@ -245,18 +256,22 @@ func (r *OCIClusterReconciler) reconcile(ctx context.Context, logger logr.Logger
245
256
return ctrl.Result {}, err
246
257
}
247
258
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
+ }
254
272
}
255
273
} 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" )
260
275
}
261
276
262
277
conditions .MarkTrue (cluster , infrastructurev1beta2 .ClusterReadyCondition )
@@ -338,20 +353,24 @@ func (r *OCIClusterReconciler) reconcileDelete(ctx context.Context, logger logr.
338
353
// Declare the err variable before the if-else block
339
354
var err error
340
355
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
+ }
350
366
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" )
355
374
}
356
375
357
376
// This below if condition specifies if the network related infrastructure needs to be reconciled. Any new
0 commit comments