Skip to content

Commit c18b8ae

Browse files
authored
Merge pull request #409 from anfredette/app-pending
Make the bpfman-operator report status of "Pending" instead of "Error" when appropriate
2 parents 593cf31 + 0ab324d commit c18b8ae

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

controllers/bpfman-operator/common.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func reconcileBpfApplication[T BpfProgOper, TL BpfProgListOper[T]](
130130
}
131131
}
132132

133+
pendingBpfApplications := []string{}
133134
failedBpfApplications := []string{}
134135
finalApplied := []string{}
135136
// Make sure no BpfApplications had any issues in the loading or unloading process
@@ -142,6 +143,8 @@ func reconcileBpfApplication[T BpfProgOper, TL BpfProgListOper[T]](
142143
status := bpfAppState.GetStatus()
143144
if bpfmanHelpers.IsBpfAppStateConditionFailure(&status.Conditions) {
144145
failedBpfApplications = append(failedBpfApplications, bpfAppState.GetName())
146+
} else if bpfmanHelpers.IsBpfAppStateConditionPending(&status.Conditions) {
147+
pendingBpfApplications = append(pendingBpfApplications, bpfAppState.GetName())
145148
}
146149
}
147150

@@ -153,18 +156,17 @@ func reconcileBpfApplication[T BpfProgOper, TL BpfProgListOper[T]](
153156
return r.removeFinalizer(ctx, app, internal.BpfmanOperatorFinalizer)
154157
}
155158

156-
// Causes Requeue
157159
return rec.updateStatus(ctx, appNamespace, appName, bpfmaniov1alpha1.BpfAppCondDeleteError,
158160
fmt.Sprintf("Program Deletion failed on the following BpfApplicationState objects: %v", finalApplied))
159161
}
160162

161163
if len(failedBpfApplications) != 0 {
162-
// Causes Requeue
163164
return rec.updateStatus(ctx, appNamespace, appName, bpfmaniov1alpha1.BpfAppCondError,
164-
fmt.Sprintf("bpfProgramReconciliation failed on the following BpfApplicationState objects: %v", failedBpfApplications))
165+
fmt.Sprintf("BpfApplication Reconciliation failed on the following BpfApplicationState objects: %v", failedBpfApplications))
166+
} else if len(pendingBpfApplications) != 0 {
167+
return rec.updateStatus(ctx, appNamespace, appName, bpfmaniov1alpha1.BpfAppCondPending,
168+
fmt.Sprintf("BpfApplication Reconciliation is pending on the following BpfApplicationState objects: %v", pendingBpfApplications))
165169
}
166-
167-
// Causes Requeue
168170
return rec.updateStatus(ctx, appNamespace, appName, bpfmaniov1alpha1.BpfAppCondSuccess, "")
169171
}
170172

controllers/bpfman-operator/configmap.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ func (r *BpfmanConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request
8686
r.Logger.Error(err, "failed adding bpfman-operator finalizer to bpfman config")
8787
return ctrl.Result{Requeue: true, RequeueAfter: retryDurationOperator}, nil
8888
}
89-
} else {
90-
return r.ReconcileBpfmanConfig(ctx, req, bpfmanConfig)
9189
}
90+
return r.ReconcileBpfmanConfig(ctx, req, bpfmanConfig)
9291
}
9392

9493
return ctrl.Result{}, nil

pkg/helpers/helpers.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func IsBpfmanDeployed() bool {
154154
return false
155155
}
156156

157-
func IsBpfApplicationConditionFailure(conditions *[]metav1.Condition) bool {
157+
func IsBpfAppStateConditionFailure(conditions *[]metav1.Condition) bool {
158158
if conditions == nil || *conditions == nil || len(*conditions) == 0 {
159159
return true
160160
}
@@ -167,16 +167,12 @@ func IsBpfApplicationConditionFailure(conditions *[]metav1.Condition) bool {
167167
log.Info("more than one condition found", "numConditions", numConditions)
168168
}
169169

170-
if (*conditions)[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondPending) ||
171-
(*conditions)[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondError) ||
172-
(*conditions)[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondProgramListChangedError) {
173-
return true
174-
}
175-
176-
return false
170+
return (*conditions)[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondError) ||
171+
(*conditions)[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondProgramListChangedError) ||
172+
(*conditions)[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondDeleteError)
177173
}
178174

179-
func IsBpfAppStateConditionFailure(conditions *[]metav1.Condition) bool {
175+
func IsBpfAppStateConditionPending(conditions *[]metav1.Condition) bool {
180176
if conditions == nil || *conditions == nil || len(*conditions) == 0 {
181177
return true
182178
}
@@ -189,9 +185,5 @@ func IsBpfAppStateConditionFailure(conditions *[]metav1.Condition) bool {
189185
log.Info("more than one condition found", "numConditions", numConditions)
190186
}
191187

192-
if (*conditions)[0].Type == string(bpfmaniov1alpha1.BpfAppCondSuccess) {
193-
return false
194-
} else {
195-
return true
196-
}
188+
return (*conditions)[0].Type == string(bpfmaniov1alpha1.BpfAppCondPending)
197189
}

0 commit comments

Comments
 (0)