-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add pause handling for AzureCluster controller #3735
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,24 @@ func (s *azureClusterService) Reconcile(ctx context.Context) error { | |
return nil | ||
} | ||
|
||
// Pause pauses all components making up the cluster. | ||
func (s *azureClusterService) Pause(ctx context.Context) error { | ||
ctx, _, done := tele.StartSpanWithLogger(ctx, "controllers.azureClusterService.Pause") | ||
defer done() | ||
|
||
for _, service := range s.services { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the order in which services are paused is significant, at least for ASO. |
||
pauser, ok := service.(azure.Pauser) | ||
if !ok { | ||
continue | ||
} | ||
if err := pauser.Pause(ctx); err != nil { | ||
return errors.Wrapf(err, "failed to pause AzureCluster service %s", service.Name()) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Delete reconciles all the services in a predetermined order. | ||
func (s *azureClusterService) Delete(ctx context.Context) error { | ||
ctx, _, done := tele.StartSpanWithLogger(ctx, "controllers.azureClusterService.Delete") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import ( | |
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/klog/v2" | ||
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" | ||
"sigs.k8s.io/cluster-api-provider-azure/azure" | ||
"sigs.k8s.io/cluster-api-provider-azure/azure/scope" | ||
|
@@ -53,7 +54,9 @@ import ( | |
"sigs.k8s.io/controller-runtime/pkg/client/apiutil" | ||
"sigs.k8s.io/controller-runtime/pkg/controller" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/handler" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
) | ||
|
||
|
@@ -1023,3 +1026,33 @@ func MachinePoolToAzureManagedControlPlaneMapFunc(ctx context.Context, c client. | |
return nil | ||
} | ||
} | ||
|
||
// ClusterUpdatePauseChange returns a predicate that returns true for an update event when a cluster's | ||
// Spec.Paused changes between any two distinct values. | ||
func ClusterUpdatePauseChange(logger logr.Logger) predicate.Funcs { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mostly copy-paste from CAPI's |
||
return predicate.Funcs{ | ||
UpdateFunc: func(e event.UpdateEvent) bool { | ||
log := logger.WithValues("predicate", "ClusterUpdatePauseChange", "eventType", "update") | ||
|
||
oldCluster, ok := e.ObjectOld.(*clusterv1.Cluster) | ||
if !ok { | ||
log.V(4).Info("Expected Cluster", "type", fmt.Sprintf("%T", e.ObjectOld)) | ||
return false | ||
} | ||
log = log.WithValues("Cluster", klog.KObj(oldCluster)) | ||
|
||
newCluster := e.ObjectNew.(*clusterv1.Cluster) | ||
|
||
if oldCluster.Spec.Paused != newCluster.Spec.Paused { | ||
log.V(4).Info("Cluster paused status changed, allowing further processing") | ||
return true | ||
} | ||
|
||
log.V(6).Info("Cluster paused status remained the same, blocking further processing") | ||
return false | ||
}, | ||
CreateFunc: func(e event.CreateEvent) bool { return false }, | ||
DeleteFunc: func(e event.DeleteEvent) bool { return false }, | ||
GenericFunc: func(e event.GenericEvent) bool { return false }, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally tried to specify this test like the one above with envtest, but the race detector was flagging something in the logging calls whenever two objects were being created, even serially and with a 10s sleep in between. It was easier to rework this test to use a fake client than try to fix the race which seemed unrelated to the rest of these changes. The test itself hasn't lost any fidelity during that rewrite AFAICT.