@@ -55,23 +55,23 @@ type BpfProgListOper[T any] interface {
5555 GetItems () []T
5656}
5757
58- type ReconcilerCommon [ T BpfProgOper , TL BpfProgListOper [ T ]] struct {
58+ type ReconcilerCommon struct {
5959 client.Client
6060 Scheme * runtime.Scheme
6161 Logger logr.Logger
6262}
6363
6464// ApplicationReconciler defines a k8s reconciler which can program bpfman.
65- type ApplicationReconciler [ T BpfProgOper , TL BpfProgListOper [ T ]] interface {
65+ type ApplicationReconciler interface {
6666 // BPF Cluster of Namespaced Reconciler
6767 getAppStateList (ctx context.Context ,
6868 appName string ,
6969 appNamespace string ,
70- ) (* TL , error )
71- containsFinalizer (bpfApplication * T , finalizer string ) bool
70+ ) (client. ObjectList , error )
71+ containsFinalizer (bpfApplication client. Object , finalizer string ) bool
7272
7373 // *Program Reconciler
74- getRecCommon () * ReconcilerCommon [ T , TL ]
74+ getRecCommon () * ReconcilerCommon
7575 updateStatus (ctx context.Context ,
7676 namespace string ,
7777 name string ,
@@ -80,9 +80,23 @@ type ApplicationReconciler[T BpfProgOper, TL BpfProgListOper[T]] interface {
8080 getFinalizer () string
8181}
8282
83- func reconcileBpfApplication [T BpfProgOper , TL BpfProgListOper [T ]](
83+ // ValidReconciler encompasses BpfApplicationReconciler and BpfNSApplicationReconciler.
84+ type ValidReconciler interface {
85+ ValidReconcilerMethods
86+ * BpfApplicationReconciler | * BpfNsApplicationReconciler
87+ }
88+
89+ type ValidReconcilerMethods interface {
90+ getRecCommon () * ReconcilerCommon
91+ getAppStateList (ctx context.Context , appName string , appNamespace string ) (client.ObjectList , error )
92+ updateStatus (ctx context.Context , namespace string , name string , cond bpfmaniov1alpha1.BpfApplicationConditionType , message string ) (ctrl.Result , error )
93+ containsFinalizer (bpfApplication client.Object , finalizer string ) bool
94+ getFinalizer () string
95+ }
96+
97+ func reconcileBpfApplication [T ValidReconciler ](
8498 ctx context.Context ,
85- rec ApplicationReconciler [ T , TL ] ,
99+ rec T ,
86100 app client.Object ,
87101) (ctrl.Result , error ) {
88102 r := rec .getRecCommon ()
@@ -103,6 +117,12 @@ func reconcileBpfApplication[T BpfProgOper, TL BpfProgListOper[T]](
103117 r .Logger .Error (err , "failed to get freshPrograms for full reconcile" )
104118 return ctrl.Result {}, nil
105119 }
120+ var bpfAppStateList []client.Object
121+ _ = meta .EachListItem (bpfAppStateObjs , func (obj runtime.Object ) error {
122+ appState := obj .(client.Object )
123+ bpfAppStateList = append (bpfAppStateList , appState )
124+ return nil
125+ })
106126
107127 // List all nodes since a BpfApplicationState object will always be created for each
108128 nodes := & corev1.NodeList {}
@@ -116,7 +136,7 @@ func reconcileBpfApplication[T BpfProgOper, TL BpfProgListOper[T]](
116136 if app .GetDeletionTimestamp ().IsZero () {
117137 for _ , node := range nodes .Items {
118138 nodeFound := false
119- for _ , appState := range ( * bpfAppStateObjs ). GetItems () {
139+ for _ , appState := range bpfAppStateList {
120140 bpfProgramState := appState .GetLabels ()[internal .K8sHostLabel ]
121141 if node .Name == bpfProgramState {
122142 nodeFound = true
@@ -129,17 +149,30 @@ func reconcileBpfApplication[T BpfProgOper, TL BpfProgListOper[T]](
129149 }
130150 }
131151
152+ getBpfApplicationConditions := func (bpfAppState client.Object ) ([]metav1.Condition , error ) {
153+ switch v := bpfAppState .(type ) {
154+ case * bpfmaniov1alpha1.ClusterBpfApplicationState :
155+ return v .Status .Conditions , nil
156+ case * bpfmaniov1alpha1.BpfApplicationState :
157+ return v .Status .Conditions , nil
158+ }
159+ return nil , fmt .Errorf ("this error should never be triggered as only " +
160+ "*BpfApplicationReconciler | *BpfNsApplicationReconciler are valid types for rec" )
161+ }
162+
132163 pendingBpfApplications := []string {}
133164 failedBpfApplications := []string {}
134165 finalApplied := []string {}
135166 // Make sure no BpfApplications had any issues in the loading or unloading process
136- for _ , bpfAppState := range (* bpfAppStateObjs ).GetItems () {
137-
138- if rec .containsFinalizer (& bpfAppState , rec .getFinalizer ()) {
167+ for _ , bpfAppState := range bpfAppStateList {
168+ if rec .containsFinalizer (bpfAppState , rec .getFinalizer ()) {
139169 finalApplied = append (finalApplied , bpfAppState .GetName ())
140170 }
141171
142- conditions := bpfAppState .GetConditions ()
172+ conditions , err := getBpfApplicationConditions (bpfAppState )
173+ if err != nil {
174+ return ctrl.Result {}, err
175+ }
143176 if bpfmanHelpers .IsBpfAppStateConditionFailure (conditions ) {
144177 failedBpfApplications = append (failedBpfApplications , bpfAppState .GetName ())
145178 } else if bpfmanHelpers .IsBpfAppStateConditionPending (conditions ) {
@@ -169,7 +202,7 @@ func reconcileBpfApplication[T BpfProgOper, TL BpfProgListOper[T]](
169202 return rec .updateStatus (ctx , appNamespace , appName , bpfmaniov1alpha1 .BpfAppCondSuccess , "" )
170203}
171204
172- func (r * ReconcilerCommon [ T , TL ] ) removeFinalizer (ctx context.Context , bpfApp client.Object , finalizer string ) (ctrl.Result , error ) {
205+ func (r * ReconcilerCommon ) removeFinalizer (ctx context.Context , bpfApp client.Object , finalizer string ) (ctrl.Result , error ) {
173206 r .Logger .Info ("Calling KubeAPI to delete Program Finalizer" , "Type" , bpfApp .GetObjectKind ().GroupVersionKind ().Kind , "Name" , bpfApp .GetName ())
174207
175208 if changed := controllerutil .RemoveFinalizer (bpfApp , finalizer ); changed {
@@ -183,7 +216,7 @@ func (r *ReconcilerCommon[T, TL]) removeFinalizer(ctx context.Context, bpfApp cl
183216 return ctrl.Result {}, nil
184217}
185218
186- func (r * ReconcilerCommon [ T , TL ] ) addFinalizer (ctx context.Context , app client.Object , finalizer string ) (ctrl.Result , error ) {
219+ func (r * ReconcilerCommon ) addFinalizer (ctx context.Context , app client.Object , finalizer string ) (ctrl.Result , error ) {
187220 controllerutil .AddFinalizer (app , finalizer )
188221
189222 r .Logger .Info ("Calling KubeAPI to add Program Finalizer" , "Type" , app .GetObjectKind ().GroupVersionKind ().Kind , "Name" , app .GetName ())
@@ -196,7 +229,7 @@ func (r *ReconcilerCommon[T, TL]) addFinalizer(ctx context.Context, app client.O
196229 return ctrl.Result {}, nil
197230}
198231
199- func (r * ReconcilerCommon [ T , TL ] ) updateCondition (
232+ func (r * ReconcilerCommon ) updateCondition (
200233 ctx context.Context ,
201234 obj client.Object ,
202235 conditions * []metav1.Condition ,
0 commit comments