From d17ac16ff75ed8a8d9c7e73bb605e125604c3fe0 Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Tue, 19 Nov 2024 10:22:36 +0100 Subject: [PATCH] Fix typo --- api/v1/prefixclaim_types.go | 2 +- internal/controller/prefix_controller.go | 10 ++++---- internal/controller/prefixclaim_controller.go | 24 +++++++++---------- .../controller/prefixclaim_helpers_test.go | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/v1/prefixclaim_types.go b/api/v1/prefixclaim_types.go index f60a1feb..826a9909 100644 --- a/api/v1/prefixclaim_types.go +++ b/api/v1/prefixclaim_types.go @@ -75,7 +75,7 @@ type PrefixClaimStatus struct { // Due to the fact that the parent prefix can be specified directly in `ParentPrefix` or selected from `ParentPrefixSelector`, // we use this field to store exactly which parent prefix we are using for all subsequent reconcile loop calls, // as Spec.ParentPrefix is an immutable field, we can't overwrite it - SelectedParendPrefix string `json:"parentPrefix,omitempty"` + SelectedParentPrefix string `json:"parentPrefix,omitempty"` Prefix string `json:"prefix,omitempty"` PrefixName string `json:"prefixName,omitempty"` Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` diff --git a/internal/controller/prefix_controller.go b/internal/controller/prefix_controller.go index 73dd03b3..ad634714 100644 --- a/internal/controller/prefix_controller.go +++ b/internal/controller/prefix_controller.go @@ -132,7 +132,7 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr return ctrl.Result{}, err } - if prefixClaim.Status.SelectedParendPrefix == "" { + if prefixClaim.Status.SelectedParentPrefix == "" { // the parent prefix is not selected if err := r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionPrefixReadyFalse, corev1.EventTypeWarning, "the parent prefix is not selected"); err != nil { return ctrl.Result{}, err @@ -142,12 +142,12 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr }, nil } - if prefixClaim.Status.SelectedParendPrefix != msgCanNotInferParentPrefix { + if prefixClaim.Status.SelectedParentPrefix != msgCanNotInferParentPrefix { // we can't restore from the restoration hash // get the name of the parent prefix leaseLockerNSN := types.NamespacedName{ - Name: convertCIDRToLeaseLockName(prefixClaim.Status.SelectedParendPrefix), + Name: convertCIDRToLeaseLockName(prefixClaim.Status.SelectedParentPrefix), Namespace: r.OperatorNamespace, } ll, err = leaselocker.NewLeaseLocker(r.RestConfig, leaseLockerNSN, req.NamespacedName.String()) @@ -160,13 +160,13 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr // create lock if locked := ll.TryLock(lockCtx); !locked { - errorMsg := fmt.Sprintf("failed to lock parent prefix %s", prefixClaim.Status.SelectedParendPrefix) + errorMsg := fmt.Sprintf("failed to lock parent prefix %s", prefixClaim.Status.SelectedParentPrefix) r.Recorder.Eventf(prefix, corev1.EventTypeWarning, "FailedToLockParentPrefix", errorMsg) return ctrl.Result{ RequeueAfter: 2 * time.Second, }, nil } - debugLogger.Info("successfully locked parent prefix %s", prefixClaim.Status.SelectedParendPrefix) + debugLogger.Info("successfully locked parent prefix %s", prefixClaim.Status.SelectedParentPrefix) } } diff --git a/internal/controller/prefixclaim_controller.go b/internal/controller/prefixclaim_controller.go index 8d5282f6..fa35f9b9 100644 --- a/internal/controller/prefixclaim_controller.go +++ b/internal/controller/prefixclaim_controller.go @@ -83,12 +83,12 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) /* 1. compute and assign the parent prefix if required */ // The current design will use prefixClaim.Status.ParentPrefix for storing the selected parent prefix, // and as the source of truth for future parent prefix references - if prefixClaim.Status.SelectedParendPrefix == "" /* parent prefix not yet selected/assigned */ { + if prefixClaim.Status.SelectedParentPrefix == "" /* parent prefix not yet selected/assigned */ { if prefixClaim.Spec.ParentPrefix != "" { - prefixClaim.Status.SelectedParendPrefix = prefixClaim.Spec.ParentPrefix + prefixClaim.Status.SelectedParentPrefix = prefixClaim.Spec.ParentPrefix // set status, and condition field - msg := fmt.Sprintf("parentPrefix is provided in CR: %v", prefixClaim.Status.SelectedParendPrefix) + msg := fmt.Sprintf("parentPrefix is provided in CR: %v", prefixClaim.Status.SelectedParentPrefix) if err := r.SetConditionAndCreateEvent(ctx, prefixClaim, netboxv1.ConditionParentPrefixSelectedTrue, corev1.EventTypeNormal, msg); err != nil { return ctrl.Result{}, err } @@ -137,7 +137,7 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) // since we can't infer the parent prefix // we write a special string in the ParentPrefix status field indicating the situation - prefixClaim.Status.SelectedParendPrefix = msgCanNotInferParentPrefix + prefixClaim.Status.SelectedParentPrefix = msgCanNotInferParentPrefix if err := r.SetConditionAndCreateEvent(ctx, prefixClaim, netboxv1.ConditionParentPrefixSelectedTrue, corev1.EventTypeNormal, msgCanNotInferParentPrefix); err != nil { return ctrl.Result{}, err @@ -162,10 +162,10 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) // TODO(henrybear327): use best-fit algorithm to pick a parent prefix parentPrefixCandidate := parentPrefixCandidates[0] - prefixClaim.Status.SelectedParendPrefix = parentPrefixCandidate.Prefix + prefixClaim.Status.SelectedParentPrefix = parentPrefixCandidate.Prefix // set status, and condition field - msg := fmt.Sprintf("parentPrefix is selected: %v", prefixClaim.Status.SelectedParendPrefix) + msg := fmt.Sprintf("parentPrefix is selected: %v", prefixClaim.Status.SelectedParentPrefix) if err := r.SetConditionAndCreateEvent(ctx, prefixClaim, netboxv1.ConditionParentPrefixSelectedTrue, corev1.EventTypeNormal, msg); err != nil { return ctrl.Result{}, err } @@ -193,12 +193,12 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) } debugLogger.Info("the prefix was not found, will create a new prefix object now") - if prefixClaim.Status.SelectedParendPrefix != msgCanNotInferParentPrefix { + if prefixClaim.Status.SelectedParentPrefix != msgCanNotInferParentPrefix { // we can't restore from the restoration hash /* 3. check if the lease for parent prefix is available */ leaseLockerNSN := types.NamespacedName{ - Name: convertCIDRToLeaseLockName(prefixClaim.Status.SelectedParendPrefix), + Name: convertCIDRToLeaseLockName(prefixClaim.Status.SelectedParentPrefix), Namespace: r.OperatorNamespace, } ll, err := leaselocker.NewLeaseLocker(r.RestConfig, leaseLockerNSN, req.Namespace+"/"+prefixName) @@ -213,13 +213,13 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) locked := ll.TryLock(lockCtx) if !locked { // lock for parent prefix was not available, rescheduling - errorMsg := fmt.Sprintf("failed to lock parent prefix %s", prefixClaim.Status.SelectedParendPrefix) + errorMsg := fmt.Sprintf("failed to lock parent prefix %s", prefixClaim.Status.SelectedParentPrefix) r.Recorder.Eventf(prefixClaim, corev1.EventTypeWarning, "FailedToLockParentPrefix", errorMsg) return ctrl.Result{ RequeueAfter: 2 * time.Second, }, nil } - debugLogger.Info(fmt.Sprintf("successfully locked parent prefix %s", prefixClaim.Status.SelectedParendPrefix)) + debugLogger.Info(fmt.Sprintf("successfully locked parent prefix %s", prefixClaim.Status.SelectedParentPrefix)) } // else { // we can restore from the restoration hash // we skip directly to try to reclaim Prefix using restorationHash @@ -242,7 +242,7 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) // get available Prefix under parent prefix in netbox with equal mask length prefixModel, err = r.NetboxClient.GetAvailablePrefixByClaim( &models.PrefixClaim{ - ParentPrefix: prefixClaim.Status.SelectedParendPrefix, + ParentPrefix: prefixClaim.Status.SelectedParentPrefix, PrefixLength: prefixClaim.Spec.PrefixLength, Metadata: &models.NetboxMetadata{ Tenant: prefixClaim.Spec.Tenant, @@ -257,7 +257,7 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) } // we reset the selected parent prefix, since this one is already exhausted - prefixClaim.Status.SelectedParendPrefix = "" + prefixClaim.Status.SelectedParentPrefix = "" return ctrl.Result{Requeue: true}, nil } diff --git a/internal/controller/prefixclaim_helpers_test.go b/internal/controller/prefixclaim_helpers_test.go index cad67682..8486e372 100644 --- a/internal/controller/prefixclaim_helpers_test.go +++ b/internal/controller/prefixclaim_helpers_test.go @@ -43,7 +43,7 @@ func TestBackwardCompatibilityOfGeneratePrefixRestorationHash(t *testing.T) { ParentPrefixSelector: nil, // TODO(henrybear327): check the default value of this }, Status: netboxv1.PrefixClaimStatus{ - SelectedParendPrefix: "2.0.0.0/16", + SelectedParentPrefix: "2.0.0.0/16", }, } prefixClaim.Namespace = "default"