@@ -176,7 +176,7 @@ func (r *NsBpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
176176 bpfAppStateOriginal = r .currentAppState .DeepCopy ()
177177 }
178178
179- r .Logger .Info ("From getBpfAppState " , "new" , bpfAppStateNew )
179+ r .Logger .Info ("BpfApplicationState status " , "new" , bpfAppStateNew )
180180
181181 if bpfAppStateNew {
182182 // Create the object and return. We'll get the updated object in the
@@ -249,9 +249,9 @@ func (r *NsBpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
249249
250250 err = rec .reconcileProgram (ctx , rec , r .isBeingDeleted ())
251251 if err != nil {
252- r .Logger .Info ("Error reconciling program" , "Name" , rec .getProgName (), "Index" , appProgramIndex )
252+ r .Logger .Info ("Error reconciling program" , "Name" , rec .getProgName ())
253253 } else {
254- r .Logger .Info ("Successfully reconciled program" , "Name" , rec .getProgName (), "Index" , appProgramIndex )
254+ r .Logger .Info ("Successfully reconciled program" , "Name" , rec .getProgName ())
255255 }
256256 }
257257
@@ -717,3 +717,49 @@ func (r *NsBpfApplicationReconciler) deleteLinks(program *bpfmaniov1alpha1.BpfAp
717717 r .Logger .Error (fmt .Errorf ("unexpected EBPFProgType" ), "unexpected EBPFProgType" , "Type" , program .Type )
718718 }
719719}
720+
721+ // validateProgramList checks the BpfApplicationPrograms to ensure that none
722+ // have been added or deleted.
723+ func (r * NsBpfApplicationReconciler ) validateProgramList () error {
724+ if len (r .currentAppState .Spec .Programs ) != len (r .currentApp .Spec .Programs ) {
725+ return fmt .Errorf ("program list has changed" )
726+ }
727+
728+ // Create a map of the programs in r.currentAppState.Spec.Programs so we can
729+ // quickly check if a program is in the list.
730+ appStateProgMap := make (map [string ]bool )
731+ for _ , program := range r .currentAppState .Spec .Programs {
732+ appStateProgMap [program .Name ] = true
733+ }
734+
735+ // Check that all the programs in r.currentApp.Spec.Programs are on the
736+ // list. If not, that indicates that the program has been added, which is
737+ // not allowed. Remove them if they are on the list so we can check if any
738+ // are left over which would indicate that they have been removed from the
739+ // list.
740+ addedPrograms := ""
741+ for _ , program := range r .currentApp .Spec .Programs {
742+ if _ , ok := appStateProgMap [program .Name ]; ! ok {
743+ addedPrograms = addedPrograms + program .Name + " "
744+ } else {
745+ delete (appStateProgMap , program .Name )
746+ }
747+ }
748+
749+ if addedPrograms != "" {
750+ return fmt .Errorf ("programs have been added: %s" , addedPrograms )
751+ }
752+
753+ // Now, see if there are any programs left on the list, which would indicate that
754+ // they have been removed from the list.
755+ if len (appStateProgMap ) > 0 {
756+ // create a string containing the names of the programs that have been removed
757+ removedPrograms := ""
758+ for program := range appStateProgMap {
759+ removedPrograms = removedPrograms + program + " "
760+ }
761+ return fmt .Errorf ("programs have been removed: %s" , removedPrograms )
762+ }
763+
764+ return nil
765+ }
0 commit comments