Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Oct 17, 2024
1 parent 3117e57 commit 5dcd739
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 0 additions & 6 deletions api/v1beta1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,6 @@ const (
MachineDeletingV1Beta2Condition = DeletingV1Beta2Condition
)

// Machine's Paused condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// MachinePausedV1Beta2Condition is true if the Machine or the Cluster it belongs to are paused.
MachinePausedV1Beta2Condition = PausedV1Beta2Condition
)

// ANCHOR: MachineSpec

// MachineSpec defines the desired state of Machine.
Expand Down
12 changes: 9 additions & 3 deletions util/paused/paused.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/annotations"
Expand All @@ -41,7 +43,7 @@ type ConditionSetter interface {
// EnsurePausedCondition sets the paused condition on the object and returns if it should be considered as paused.
func EnsurePausedCondition(ctx context.Context, c client.Client, cluster *clusterv1.Cluster, obj ConditionSetter) (isPaused bool, conditionChanged bool, err error) {
oldCondition := v1beta2conditions.Get(obj, clusterv1.PausedV1Beta2Condition)
newCondition := pausedCondition(cluster, obj, clusterv1.PausedV1Beta2Condition)
newCondition := pausedCondition(c.Scheme(), cluster, obj, clusterv1.PausedV1Beta2Condition)

isPaused = newCondition.Status == metav1.ConditionTrue

Expand Down Expand Up @@ -78,14 +80,18 @@ func EnsurePausedCondition(ctx context.Context, c client.Client, cluster *cluste
}

// pausedCondition sets the paused condition on the object and returns if it should be considered as paused.
func pausedCondition(cluster *clusterv1.Cluster, obj ConditionSetter, targetConditionType string) metav1.Condition {
func pausedCondition(scheme *runtime.Scheme, cluster *clusterv1.Cluster, obj ConditionSetter, targetConditionType string) metav1.Condition {
if (cluster != nil && cluster.Spec.Paused) || annotations.HasPaused(obj) {
var messages []string
if cluster != nil && cluster.Spec.Paused {
messages = append(messages, "Cluster spec.paused is set to true")
}
if annotations.HasPaused(obj) {
messages = append(messages, fmt.Sprintf("%s has the cluster.x-k8s.io/paused annotation", obj.GetObjectKind().GroupVersionKind().Kind))
kind := "Object"
if gvk, err := apiutil.GVKForObject(obj, scheme); err == nil {
kind = gvk.Kind
}
messages = append(messages, fmt.Sprintf("%s has the cluster.x-k8s.io/paused annotation", kind))
}

return metav1.Condition{
Expand Down
2 changes: 1 addition & 1 deletion util/paused/paused_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestEnsurePausedCondition(t *testing.T) {

// Object case 2: paused
pausedObj := obj.DeepCopy()
pausedObj.SetAnnotations(map[string]string{clusterv1.PausedAnnotation: "true"})
pausedObj.SetAnnotations(map[string]string{clusterv1.PausedAnnotation: ""})

tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion util/predicates/cluster_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func ClusterControlPlaneInitialized(scheme *runtime.Scheme, logger logr.Logger)
// ClusterPausedTransitionsOrInfrastructureReady returns a Predicate that returns true on Cluster Update events where
// either Cluster.Spec.Paused transitions or Cluster.Status.InfrastructureReady transitions to true.
// This implements a common requirement for some cluster-api and provider controllers (such as Machine Infrastructure
// controllers) to resume reconciliation when the Cluster is gets paused or unpaused and when the infrastructure becomes ready.
// controllers) to resume reconciliation when the Cluster gets paused or unpaused and when the infrastructure becomes ready.
// Example use:
//
// err := controller.Watch(
Expand Down

0 comments on commit 5dcd739

Please sign in to comment.