Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/v1alpha1/nodereadinessrule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ type NodeReadinessRuleSpec struct {
//
// +optional
DryRun bool `json:"dryRun,omitempty"` //nolint:kubeapilinter

// suspend tells the controller to suspend operations for this NodeReadinessRule.
//
// +optional
Suspend bool `json:"suspend,omitempty"`
}

// ConditionRequirement defines a specific Node condition and the status value
Expand Down Expand Up @@ -327,6 +332,7 @@ type DryRunResults struct {
// +kubebuilder:printcolumn:name="Effect",type=string,JSONPath=`.spec.taint.effect`,description="The taint effect: NoSchedule, PreferNoSchedule or NoExecute."
// +kubebuilder:printcolumn:name="DryRun",type=boolean,JSONPath=`.spec.dryRun`,description="Whether the rule is in dry-run mode and only previews taint changes."
// +kubebuilder:selectablefield:JSONPath=`.spec.dryRun`
// +kubebuilder:printcolumn:name="Suspend",type=boolean,JSONPath=`.spec.suspend`,description="Whether operations for this rule are suspended."
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="The age of this resource"

// NodeReadinessRule is the Schema for the NodeReadinessRules API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ spec:
jsonPath: .spec.dryRun
name: DryRun
type: boolean
- description: Whether operations for this rule are suspended.
jsonPath: .spec.suspend
name: Suspend
type: boolean
- description: The age of this resource
jsonPath: .metadata.creationTimestamp
name: Age
Expand Down Expand Up @@ -185,6 +189,10 @@ spec:
x-kubernetes-validations:
- message: nodeSelector is immutable
rule: self == oldSelf
suspend:
description: suspend tells the controller to suspend operations for
this NodeReadinessRule.
type: boolean
taint:
description: |-
taint defines the specific Taint (Key, Value, and Effect) to be managed
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/nodereadinessrule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ func (r *RuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
log = log.WithValues("ruleName", rule.Name)
ctx = ctrl.LoggerInto(ctx, log)

if rule.Spec.Suspend {
log.Info("NodeReadinessRule is suspended, skipping reconciliation")
return ctrl.Result{}, nil
}

// Add finalizer first if not set to avoid the race condition between init and delete.
if finalizerAdded, err := r.ensureFinalizer(ctx, rule, finalizerName); err != nil {
return ctrl.Result{}, err
Expand Down
40 changes: 40 additions & 0 deletions internal/controller/nodereadinessrule_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,46 @@ var _ = Describe("NodeReadinessRule Controller", func() {
})

Context("Rule Reconciliation", func() {
It("should skip reconciliation when rule is suspended", func() {
rule := &nodereadinessiov1alpha1.NodeReadinessRule{
ObjectMeta: metav1.ObjectMeta{
Name: "test-rule-suspend",
},
Spec: nodereadinessiov1alpha1.NodeReadinessRuleSpec{
Suspend: true,
Conditions: []nodereadinessiov1alpha1.ConditionRequirement{
{Type: "Ready", RequiredStatus: corev1.ConditionTrue},
},
NodeSelector: metav1.LabelSelector{
MatchLabels: map[string]string{
"node-role.kubernetes.io/worker": "",
},
},
Taint: corev1.Taint{
Key: "readiness.k8s.io/test-taint",
Effect: corev1.TaintEffectNoSchedule,
},
EnforcementMode: nodereadinessiov1alpha1.EnforcementModeContinuous,
},
}

Expect(k8sClient.Create(ctx, rule)).To(Succeed())

res, err := ruleReconciler.Reconcile(ctx, reconcile.Request{
NamespacedName: types.NamespacedName{Name: "test-rule-suspend"},
})
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(reconcile.Result{}))

// Verify finalizer is NOT added to the rule
updatedRule := &nodereadinessiov1alpha1.NodeReadinessRule{}
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: "test-rule-suspend"}, updatedRule)).To(Succeed())
Expect(updatedRule.Finalizers).To(BeEmpty())

// Cleanup
Expect(k8sClient.Delete(ctx, rule)).To(Succeed())
})

It("should handle rule creation and add the finalizer to the rule", func() {
rule := &nodereadinessiov1alpha1.NodeReadinessRule{
ObjectMeta: metav1.ObjectMeta{
Expand Down