Skip to content

Commit 0dcf9a3

Browse files
authored
Minor changes to align across controllers (netbox-community#372)
Alignment of controllers for variable names (o), spacing of kubebuilder markers, RequeueAfter
1 parent 568ea02 commit 0dcf9a3

File tree

10 files changed

+135
-131
lines changed

10 files changed

+135
-131
lines changed

api/v1/ipaddress_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type IpAddressStatus struct {
8888
//+kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.status.id`
8989
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`
9090
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
91-
// +kubebuilder:resource:shortName=ip
91+
//+kubebuilder:resource:shortName=ip
9292

9393
// IpAddress allows to create a NetBox IP Address. More info about NetBox IP Addresses: https://github.com/netbox-community/netbox/blob/main/docs/models/ipam/ipaddress.md
9494
type IpAddress struct {

api/v1/ipaddressclaim_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type IpAddressClaimStatus struct {
8989
//+kubebuilder:printcolumn:name="IpAssigned",type=string,JSONPath=`.status.conditions[?(@.type=="IPAssigned")].status`
9090
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
9191
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
92-
// +kubebuilder:resource:shortName=ipc
92+
//+kubebuilder:resource:shortName=ipc
9393

9494
// IpAddressClaim allows to claim a NetBox IP Address from an existing Prefix.
9595
// The IpAddressClaim Controller will try to assign an available IP Address

api/v1/iprange_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type IpRangeStatus struct {
9797
//+kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.status.id`
9898
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`
9999
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
100-
// +kubebuilder:resource:shortName=ipr
100+
//+kubebuilder:resource:shortName=ipr
101101

102102
// IpRange allows to create a NetBox IP Range. More info about NetBox IP Ranges: https://github.com/netbox-community/netbox/blob/main/docs/models/ipam/iprange.md
103103
type IpRange struct {

api/v1/iprangeclaim_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type IpRangeClaimStatus struct {
118118
//+kubebuilder:printcolumn:name="IpRangeAssigned",type=string,JSONPath=`.status.conditions[?(@.type=="IPRangeAssigned")].status`
119119
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
120120
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
121-
// +kubebuilder:resource:shortName=iprc
121+
//+kubebuilder:resource:shortName=iprc
122122

123123
// IpRangeClaim allows to claim a NetBox IP Range from an existing Prefix.
124124
// The IpRangeClaim Controller will try to assign an available IP Range

api/v1/prefix_types.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ type PrefixStatus struct {
8686
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
8787
}
8888

89-
// +kubebuilder:object:root=true
90-
// +kubebuilder:subresource:status
91-
// +kubebuilder:printcolumn:name="Prefix",type=string,JSONPath=`.spec.prefix`
92-
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
93-
// +kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.status.id`
94-
// +kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`
95-
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
96-
// +kubebuilder:resource:shortName=px
89+
//+kubebuilder:object:root=true
90+
//+kubebuilder:subresource:status
91+
//+kubebuilder:printcolumn:name="Prefix",type=string,JSONPath=`.spec.prefix`
92+
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
93+
//+kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.status.id`
94+
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`
95+
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
96+
//+kubebuilder:resource:shortName=px
9797

9898
// Prefix allows to create a NetBox Prefix. More info about NetBox Prefixes: https://github.com/netbox-community/netbox/blob/main/docs/models/ipam/prefix.md
9999
type Prefix struct {
@@ -108,7 +108,7 @@ func (p *Prefix) Conditions() *[]metav1.Condition {
108108
return &p.Status.Conditions
109109
}
110110

111-
// +kubebuilder:object:root=true
111+
//+kubebuilder:object:root=true
112112

113113
// PrefixList contains a list of Prefix
114114
type PrefixList struct {

api/v1/prefixclaim_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ type PrefixClaimStatus struct {
110110
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
111111
}
112112

113-
// +kubebuilder:object:root=true
114-
// +kubebuilder:subresource:status
115-
// +kubebuilder:printcolumn:name="Prefix",type=string,JSONPath=`.status.prefix`
116-
// +kubebuilder:printcolumn:name="PrefixAssigned",type=string,JSONPath=`.status.conditions[?(@.type=="PrefixAssigned")].status`
117-
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
118-
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
119-
// +kubebuilder:resource:shortName=pxc
113+
//+kubebuilder:object:root=true
114+
//+kubebuilder:subresource:status
115+
//+kubebuilder:printcolumn:name="Prefix",type=string,JSONPath=`.status.prefix`
116+
//+kubebuilder:printcolumn:name="PrefixAssigned",type=string,JSONPath=`.status.conditions[?(@.type=="PrefixAssigned")].status`
117+
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
118+
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
119+
//+kubebuilder:resource:shortName=pxc
120120

121121
// PrefixClaim allows to claim a NetBox Prefix from an existing Prefix
122122
// (parentPrefix) or a dynamically selected Prefix (parentPrefixSelector).
@@ -136,7 +136,7 @@ func (p *PrefixClaim) Conditions() *[]metav1.Condition {
136136
return &p.Status.Conditions
137137
}
138138

139-
// +kubebuilder:object:root=true
139+
//+kubebuilder:object:root=true
140140

141141
// PrefixClaimList contains a list of PrefixClaim
142142
type PrefixClaimList struct {

internal/controller/ipaddress_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ func generateNetboxIpAddressModelFromIpAddressSpec(spec *netboxv1.IpAddressSpec,
273273
}
274274

275275
// if a custom field was removed from the spec, add it with an empty value
276-
277276
for key := range lastAppliedCustomFields {
278277
_, ok := netboxCustomFields[key]
279278
if !ok {

internal/controller/iprange_controller.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"maps"
2525
"strconv"
2626
"strings"
27+
"time"
2728

2829
netboxv1 "github.com/netbox-community/netbox-operator/api/v1"
2930
"github.com/netbox-community/netbox-operator/pkg/config"
@@ -37,6 +38,7 @@ import (
3738
"k8s.io/client-go/rest"
3839
ctrl "sigs.k8s.io/controller-runtime"
3940
"sigs.k8s.io/controller-runtime/pkg/client"
41+
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
4042
"sigs.k8s.io/controller-runtime/pkg/log"
4143
)
4244

@@ -73,16 +75,17 @@ func (r *IpRangeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
7375

7476
// if being deleted
7577
if !o.ObjectMeta.DeletionTimestamp.IsZero() {
76-
if !o.Spec.PreserveInNetbox {
77-
err := r.NetboxClient.DeleteIpRange(o.Status.IpRangeId)
78-
if err != nil {
79-
err = r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionIpRangeReadyFalseDeletionFailed,
80-
corev1.EventTypeWarning, err)
78+
if controllerutil.ContainsFinalizer(o, IpRangeFinalizerName) {
79+
if !o.Spec.PreserveInNetbox {
80+
err := r.NetboxClient.DeleteIpRange(o.Status.IpRangeId)
8181
if err != nil {
82-
return ctrl.Result{}, err
82+
err = r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionIpRangeReadyFalseDeletionFailed,
83+
corev1.EventTypeWarning, err)
84+
if err != nil {
85+
return ctrl.Result{}, err
86+
}
87+
return ctrl.Result{Requeue: true}, nil
8388
}
84-
85-
return ctrl.Result{Requeue: true}, nil
8689
}
8790
}
8891

@@ -127,10 +130,11 @@ func (r *IpRangeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
127130
// create lock
128131
locked := ll.TryLock(lockCtx)
129132
if !locked {
130-
logger.Info(fmt.Sprintf("failed to lock parent prefix %s", parentPrefix))
131-
r.EventStatusRecorder.Recorder().Eventf(o, corev1.EventTypeWarning, "FailedToLockParentPrefix", "failed to lock parent prefix %s",
132-
parentPrefix)
133-
return ctrl.Result{Requeue: true}, nil
133+
errorMsg := fmt.Sprintf("failed to lock parent prefix %s", parentPrefix)
134+
r.EventStatusRecorder.Recorder().Eventf(o, corev1.EventTypeWarning, "FailedToLockParentPrefix", errorMsg)
135+
return ctrl.Result{
136+
RequeueAfter: 2 * time.Second,
137+
}, nil
134138
}
135139
logger.V(4).Info(fmt.Sprintf("successfully locked parent prefix %s", parentPrefix))
136140
}

internal/controller/prefix_controller.go

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ type PrefixReconciler struct {
5656
RestConfig *rest.Config
5757
}
5858

59-
// +kubebuilder:rbac:groups=netbox.dev,resources=prefixes,verbs=get;list;watch;create;update;patch;delete
60-
// +kubebuilder:rbac:groups=netbox.dev,resources=prefixes/status,verbs=get;update;patch
61-
// +kubebuilder:rbac:groups=netbox.dev,resources=prefixes/finalizers,verbs=update
59+
//+kubebuilder:rbac:groups=netbox.dev,resources=prefixes,verbs=get;list;watch;create;update;patch;delete
60+
//+kubebuilder:rbac:groups=netbox.dev,resources=prefixes/status,verbs=get;update;patch
61+
//+kubebuilder:rbac:groups=netbox.dev,resources=prefixes/finalizers,verbs=update
6262

6363
// Reconcile is part of the main kubernetes reconciliation loop which aims to
6464
// move the current state of the cluster closer to the desired state.
6565
func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
6666
logger := log.FromContext(ctx)
6767
debugLogger := logger.V(4)
6868

69-
logger.Info("prefix reconcile loop started")
69+
logger.Info("reconcile loop started")
7070

7171
/* 0. check if the matching Prefix object exists */
72-
prefix := &netboxv1.Prefix{}
73-
if err := r.Client.Get(ctx, req.NamespacedName, prefix); err != nil {
72+
o := &netboxv1.Prefix{}
73+
if err := r.Client.Get(ctx, req.NamespacedName, o); err != nil {
7474
return ctrl.Result{}, client.IgnoreNotFound(err)
7575
}
7676

7777
// if being deleted
78-
if !prefix.ObjectMeta.DeletionTimestamp.IsZero() {
79-
if controllerutil.ContainsFinalizer(prefix, PrefixFinalizerName) {
80-
if !prefix.Spec.PreserveInNetbox {
81-
if err := r.NetboxClient.DeletePrefix(prefix.Status.PrefixId); err != nil {
82-
if errReport := r.EventStatusRecorder.Report(ctx, prefix, netboxv1.ConditionPrefixReadyFalseDeletionFailed, corev1.EventTypeWarning, err); errReport != nil {
78+
if !o.ObjectMeta.DeletionTimestamp.IsZero() {
79+
if controllerutil.ContainsFinalizer(o, PrefixFinalizerName) {
80+
if !o.Spec.PreserveInNetbox {
81+
if err := r.NetboxClient.DeletePrefix(o.Status.PrefixId); err != nil {
82+
if errReport := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionPrefixReadyFalseDeletionFailed, corev1.EventTypeWarning, err); errReport != nil {
8383
return ctrl.Result{}, errReport
8484
}
8585

@@ -88,11 +88,11 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
8888
}
8989

9090
debugLogger.Info("removing the finalizer")
91-
if removed := controllerutil.RemoveFinalizer(prefix, PrefixFinalizerName); !removed {
91+
if removed := controllerutil.RemoveFinalizer(o, PrefixFinalizerName); !removed {
9292
return ctrl.Result{}, errors.New("failed to remove the finalizer")
9393
}
9494

95-
if err := r.Update(ctx, prefix); err != nil {
95+
if err := r.Update(ctx, o); err != nil {
9696
return ctrl.Result{}, err
9797
}
9898
}
@@ -102,18 +102,18 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
102102
}
103103

104104
// Set ready to false initially
105-
if apismeta.FindStatusCondition(prefix.Status.Conditions, netboxv1.ConditionReadyFalseNewResource.Type) == nil {
106-
err := r.EventStatusRecorder.Report(ctx, prefix, netboxv1.ConditionReadyFalseNewResource, corev1.EventTypeNormal, nil)
105+
if apismeta.FindStatusCondition(o.Status.Conditions, netboxv1.ConditionReadyFalseNewResource.Type) == nil {
106+
err := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionReadyFalseNewResource, corev1.EventTypeNormal, nil)
107107
if err != nil {
108108
return ctrl.Result{}, fmt.Errorf("failed to initialise Ready condition: %w, ", err)
109109
}
110110
}
111111

112112
// register finalizer if not yet registered
113-
if !prefix.Spec.PreserveInNetbox && !controllerutil.ContainsFinalizer(prefix, PrefixFinalizerName) {
113+
if !o.Spec.PreserveInNetbox && !controllerutil.ContainsFinalizer(o, PrefixFinalizerName) {
114114
debugLogger.Info("adding the finalizer")
115-
controllerutil.AddFinalizer(prefix, PrefixFinalizerName)
116-
if err := r.Update(ctx, prefix); err != nil {
115+
controllerutil.AddFinalizer(o, PrefixFinalizerName)
116+
if err := r.Update(ctx, o); err != nil {
117117
return ctrl.Result{}, err
118118
}
119119
}
@@ -123,10 +123,10 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
123123
- the prefix is owned by at least 1 prefixClaim
124124
- the prefix status condition is not ready
125125
*/
126-
ownerReferences := prefix.ObjectMeta.OwnerReferences
126+
ownerReferences := o.ObjectMeta.OwnerReferences
127127
var ll *leaselocker.LeaseLocker
128128
var err error
129-
if len(ownerReferences) > 0 /* len(nil array) = 0 */ && !apismeta.IsStatusConditionTrue(prefix.Status.Conditions, "Ready") {
129+
if len(ownerReferences) > 0 /* len(nil array) = 0 */ && !apismeta.IsStatusConditionTrue(o.Status.Conditions, "Ready") {
130130
// get prefixClaim
131131
ownerReferencesLookupKey := types.NamespacedName{
132132
Name: ownerReferences[0].Name, // TODO(henrybear327): Under what condition would we have more than 1 ownerReferences? What should we do with it?
@@ -139,7 +139,7 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
139139

140140
if prefixClaim.Status.SelectedParentPrefix == "" {
141141
// the parent prefix is not selected
142-
if errReport := r.EventStatusRecorder.Report(ctx, prefix, netboxv1.ConditionPrefixReadyFalse, corev1.EventTypeWarning, fmt.Errorf("%s", "the parent prefix is not selected")); errReport != nil {
142+
if errReport := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionPrefixReadyFalse, corev1.EventTypeWarning, fmt.Errorf("%s", "the parent prefix is not selected")); errReport != nil {
143143
return ctrl.Result{}, errReport
144144
}
145145
return ctrl.Result{
@@ -164,9 +164,10 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
164164
defer cancel()
165165

166166
// create lock
167-
if locked := ll.TryLock(lockCtx); !locked {
167+
locked := ll.TryLock(lockCtx)
168+
if !locked {
168169
errorMsg := fmt.Sprintf("failed to lock parent prefix %s", prefixClaim.Status.SelectedParentPrefix)
169-
r.EventStatusRecorder.Recorder().Eventf(prefix, corev1.EventTypeWarning, "FailedToLockParentPrefix", errorMsg)
170+
r.EventStatusRecorder.Recorder().Eventf(o, corev1.EventTypeWarning, "FailedToLockParentPrefix", errorMsg)
170171
return ctrl.Result{
171172
RequeueAfter: 2 * time.Second,
172173
}, nil
@@ -177,26 +178,26 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
177178

178179
/* 2. reserve or update Prefix in netbox */
179180
accessor := apismeta.NewAccessor()
180-
annotations, err := accessor.Annotations(prefix)
181+
annotations, err := accessor.Annotations(o)
181182
if err != nil {
182183
return ctrl.Result{}, err
183184
}
184185

185-
prefixModel, err := generateNetboxPrefixModelFromPrefixSpec(&prefix.Spec, req, annotations[PXManagedCustomFieldsAnnotationName])
186+
prefixModel, err := generateNetboxPrefixModelFromPrefixSpec(&o.Spec, req, annotations[PXManagedCustomFieldsAnnotationName])
186187
if err != nil {
187188
return ctrl.Result{}, err
188189
}
189190

190191
netboxPrefixModel, err := r.NetboxClient.ReserveOrUpdatePrefix(prefixModel)
191192
if err != nil {
192-
if errors.Is(err, api.ErrRestorationHashMismatch) && prefix.Status.PrefixId == 0 {
193+
if errors.Is(err, api.ErrRestorationHashMismatch) && o.Status.PrefixId == 0 {
193194
// if there is a restoration hash mismatch and the PrefixId status field is not set,
194195
// delete the prefix so it can be recreated by the prefix claim controller
195196
// this will only affect resources that are created by a claim controller (and have a restoration hash custom field
196-
logger.Info("restoration hash mismatch, deleting prefix custom resource", "prefix", prefix.Spec.Prefix)
197-
err = r.Client.Delete(ctx, prefix)
197+
logger.Info("restoration hash mismatch, deleting prefix custom resource", "prefix", o.Spec.Prefix)
198+
err = r.Client.Delete(ctx, o)
198199
if err != nil {
199-
if updateStatusErr := r.EventStatusRecorder.Report(ctx, prefix, netboxv1.ConditionPrefixReadyFalse,
200+
if updateStatusErr := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionPrefixReadyFalse,
200201
corev1.EventTypeWarning, err); updateStatusErr != nil {
201202
return ctrl.Result{}, fmt.Errorf("failed to update prefix status: %w, "+
202203
"after deletion of prefix cr failed: %w", updateStatusErr, err)
@@ -206,7 +207,7 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
206207
return ctrl.Result{}, nil
207208
}
208209

209-
if updateStatusErr := r.EventStatusRecorder.Report(ctx, prefix, netboxv1.ConditionPrefixReadyFalse,
210+
if updateStatusErr := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionPrefixReadyFalse,
210211
corev1.EventTypeWarning, err); updateStatusErr != nil {
211212
return ctrl.Result{}, fmt.Errorf("failed to update prefix status: %w, "+
212213
"after reservation of prefix netbox failed: %w", updateStatusErr, err)
@@ -220,9 +221,9 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
220221
}
221222

222223
/* 4. update status fields */
223-
prefix.Status.PrefixId = netboxPrefixModel.ID
224-
prefix.Status.PrefixUrl = config.GetBaseUrl() + "/ipam/prefixes/" + strconv.FormatInt(netboxPrefixModel.ID, 10)
225-
err = r.Client.Status().Update(ctx, prefix)
224+
o.Status.PrefixId = netboxPrefixModel.ID
225+
o.Status.PrefixUrl = config.GetBaseUrl() + "/ipam/prefixes/" + strconv.FormatInt(netboxPrefixModel.ID, 10)
226+
err = r.Client.Status().Update(ctx, o)
226227
if err != nil {
227228
return ctrl.Result{}, err
228229
}
@@ -231,33 +232,33 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
231232
annotations = make(map[string]string, 1)
232233
}
233234

234-
annotations[PXManagedCustomFieldsAnnotationName], err = generateManagedCustomFieldsAnnotation(prefix.Spec.CustomFields)
235+
annotations[PXManagedCustomFieldsAnnotationName], err = generateManagedCustomFieldsAnnotation(o.Spec.CustomFields)
235236
if err != nil {
236237
logger.Error(err, "failed to update last metadata annotation")
237238
return ctrl.Result{Requeue: true}, nil
238239
}
239240

240-
err = accessor.SetAnnotations(prefix, annotations)
241+
err = accessor.SetAnnotations(o, annotations)
241242
if err != nil {
242243
return ctrl.Result{}, err
243244
}
244245

245246
// update object to store lastIpAddressMetadata annotation
246-
if err := r.Update(ctx, prefix); err != nil {
247+
if err := r.Update(ctx, o); err != nil {
247248
return ctrl.Result{}, err
248249
}
249250

250251
// check if the created prefix contains the entire description from spec
251-
if _, found := strings.CutPrefix(netboxPrefixModel.Description, req.NamespacedName.String()+" // "+prefix.Spec.Description); !found {
252-
r.EventStatusRecorder.Recorder().Event(prefix, corev1.EventTypeWarning, "PrefixDescriptionTruncated", "prefix was created with truncated description")
252+
if _, found := strings.CutPrefix(netboxPrefixModel.Description, req.NamespacedName.String()+" // "+o.Spec.Description); !found {
253+
r.EventStatusRecorder.Recorder().Event(o, corev1.EventTypeWarning, "PrefixDescriptionTruncated", "prefix was created with truncated description")
253254
}
254255

255-
debugLogger.Info(fmt.Sprintf("reserved prefix in netbox, prefix: %s", prefix.Spec.Prefix))
256-
if err = r.EventStatusRecorder.Report(ctx, prefix, netboxv1.ConditionPrefixReadyTrue, corev1.EventTypeNormal, nil); err != nil {
256+
debugLogger.Info(fmt.Sprintf("reserved prefix in netbox, prefix: %s", o.Spec.Prefix))
257+
if err = r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionPrefixReadyTrue, corev1.EventTypeNormal, nil); err != nil {
257258
return ctrl.Result{}, err
258259
}
259260

260-
logger.Info("prefix reconcile loop finished")
261+
logger.Info("reconcile loop finished")
261262

262263
return ctrl.Result{}, nil
263264
}

0 commit comments

Comments
 (0)