@@ -175,7 +175,7 @@ func (r *ClBpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
175175 bpfAppStateOriginal = r .currentAppState .DeepCopy ()
176176 }
177177
178- r .Logger .Info ("From getBpfAppState " , "new" , bpfAppStateNew )
178+ r .Logger .Info ("BpfApplicationState status " , "new" , bpfAppStateNew )
179179
180180 if bpfAppStateNew {
181181 // Create the object and return. We'll get the updated object in the
@@ -248,9 +248,9 @@ func (r *ClBpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
248248
249249 err = rec .reconcileProgram (ctx , rec , r .isBeingDeleted ())
250250 if err != nil {
251- r .Logger .Info ("Error reconciling program" , "Name" , rec .getProgName (), "Index" , appProgramIndex )
251+ r .Logger .Info ("Error reconciling program" , "Name" , rec .getProgName ())
252252 } else {
253- r .Logger .Info ("Successfully reconciled program" , "Name" , rec .getProgName (), "Index" , appProgramIndex )
253+ r .Logger .Info ("Successfully reconciled program" , "Name" , rec .getProgName ())
254254 }
255255 }
256256
@@ -789,3 +789,47 @@ func (r *ClBpfApplicationReconciler) deleteLinks(program *bpfmaniov1alpha1.ClBpf
789789 r .Logger .Error (fmt .Errorf ("unexpected EBPFProgType" ), "unexpected EBPFProgType" , "Type" , program .Type )
790790 }
791791}
792+
793+ // validateProgramList checks the BpfApplicationPrograms to ensure that none
794+ // have been added or deleted.
795+ func (r * ClBpfApplicationReconciler ) validateProgramList () error {
796+ // Create a map of the programs in r.currentAppState.Spec.Programs to make
797+ // the checks more efficient.
798+ appStateProgMap := make (map [string ]bool )
799+ for _ , program := range r .currentAppState .Spec .Programs {
800+ appStateProgMap [program .Name ] = true
801+ }
802+
803+ // Check that all the programs in r.currentApp.Spec.Programs are on the
804+ // list. If not, that indicates that the program has been added, which is
805+ // not allowed. Remove them if they are on the list so we can check if any
806+ // are left over which would indicate that they have been removed from the
807+ // list.
808+ addedPrograms := ""
809+ for _ , program := range r .currentApp .Spec .Programs {
810+ if _ , ok := appStateProgMap [program .Name ]; ! ok {
811+ addedPrograms = addedPrograms + program .Name + " "
812+ } else {
813+ delete (appStateProgMap , program .Name )
814+ }
815+ }
816+
817+ if addedPrograms != "" {
818+ r .Logger .Info ("Programs added error" , "Programs" , addedPrograms )
819+ return fmt .Errorf ("programs have been added: %s" , addedPrograms )
820+ }
821+
822+ // Now, see if there are any programs left on the list, which would indicate that
823+ // they have been removed from the list.
824+ if len (appStateProgMap ) > 0 {
825+ // create a string containing the names of the programs that have been removed
826+ removedPrograms := ""
827+ for program := range appStateProgMap {
828+ removedPrograms = removedPrograms + program + " "
829+ }
830+ r .Logger .Info ("Programs removed error" , "Programs" , removedPrograms )
831+ return fmt .Errorf ("programs have been removed: %s" , removedPrograms )
832+ }
833+
834+ return nil
835+ }
0 commit comments