Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybear327 committed Nov 19, 2024
1 parent 143c69e commit d17ac16
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/v1/prefixclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/prefix_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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)
}
}

Expand Down
24 changes: 12 additions & 12 deletions internal/controller/prefixclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/prefixclaim_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d17ac16

Please sign in to comment.