diff --git a/pkg/splunk/enterprise/monitoringconsole.go b/pkg/splunk/enterprise/monitoringconsole.go index 95484c9cb..d85fc6fc5 100644 --- a/pkg/splunk/enterprise/monitoringconsole.go +++ b/pkg/splunk/enterprise/monitoringconsole.go @@ -150,7 +150,9 @@ func ApplyMonitoringConsole(ctx context.Context, client splcommon.ControllerClie finalResult := handleAppFrameworkActivity(ctx, client, cr, &cr.Status.AppContext, &cr.Spec.AppFrameworkConfig) result = *finalResult - // trigger SearchHeadCluster reconcile by changing the splunk/image-tag annotation + // TODO: Fix the Change Annotation logic/ find an alternative (eg. state machine); right now the search head deployer + // starts terminating with this and few replicas do not come up properly after that + // err = changeSearchHeadAnnotations(ctx, client, cr) // if err != nil { // return result, err diff --git a/pkg/splunk/enterprise/searchheadcluster.go b/pkg/splunk/enterprise/searchheadcluster.go index 758f4c716..7a1a345a5 100644 --- a/pkg/splunk/enterprise/searchheadcluster.go +++ b/pkg/splunk/enterprise/searchheadcluster.go @@ -36,7 +36,6 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/remotecommand" "sigs.k8s.io/controller-runtime/pkg/client" - rclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -735,55 +734,3 @@ func isSearchHeadReadyForUpgrade(ctx context.Context, c splcommon.ControllerClie return true, nil } - -// changeSearchHeadAnnotations updates the splunk/image-tag field of the SearchHeadCluster annotations to trigger the reconcile loop -// on update, and returns error if something is wrong. -func changeSearchHeadAnnotations(ctx context.Context, client splcommon.ControllerClient, cr *enterpriseApi.MonitoringConsole) error { - reqLogger := log.FromContext(ctx) - scopedLog := reqLogger.WithName("changeSearchHeadAnnotations").WithValues("name", cr.GetName(), "namespace", cr.GetNamespace()) - eventPublisher, _ := newK8EventPublisher(client, cr) - - searchHeadClusterInstance := enterpriseApi.SearchHeadCluster{} - - // List out all the SearchHeadCluster instances in the namespace - opts := []rclient.ListOption{ - rclient.InNamespace(cr.GetNamespace()), - } - objectList := enterpriseApi.SearchHeadClusterList{} - err := client.List(ctx, &objectList, opts...) - if err != nil { - if err.Error() == "NotFound" { - return nil - } - return err - } - if len(objectList.Items) == 0 { - return nil - } - - // check if instance has the required MonitoringConsoleRef - for _, shc := range objectList.Items { - if shc.Spec.MonitoringConsoleRef.Name == cr.GetName() { - searchHeadClusterInstance = shc - } - } - if len(searchHeadClusterInstance.GetName()) == 0 { - return nil - } - - image, err := getCurrentImage(ctx, client, cr, SplunkMonitoringConsole) - if err != nil { - eventPublisher.Warning(ctx, "changeSearchHeadAnnotations", fmt.Sprintf("Could not get the MonitoringConsole Image. Reason %v", err)) - scopedLog.Error(err, "Get MonitoringConsole Image failed with", "error", err) - return err - } - - err = changeAnnotations(ctx, client, image, &searchHeadClusterInstance) - if err != nil { - eventPublisher.Warning(ctx, "changeSearchHeadAnnotations", fmt.Sprintf("Could not update annotations. Reason %v", err)) - scopedLog.Error(err, "SearchHeadCluster types update after changing annotations failed with", "error", err) - return err - } - - return nil -} diff --git a/pkg/splunk/enterprise/searchheadcluster_test.go b/pkg/splunk/enterprise/searchheadcluster_test.go index eab663ba5..a755f4bd5 100644 --- a/pkg/splunk/enterprise/searchheadcluster_test.go +++ b/pkg/splunk/enterprise/searchheadcluster_test.go @@ -1961,83 +1961,3 @@ func TestIsSearchHeadReadyForUpgrade(t *testing.T) { t.Errorf("isSearchHeadReadyForUpgrade: SHC should be ready for upgrade") } } - -func TestChangeSearchHeadAnnotations(t *testing.T) { - ctx := context.TODO() - - // define MC and SHC - mc := &enterpriseApi.MonitoringConsole{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test", - Namespace: "test", - }, - Spec: enterpriseApi.MonitoringConsoleSpec{ - CommonSplunkSpec: enterpriseApi.CommonSplunkSpec{ - Spec: enterpriseApi.Spec{ - ImagePullPolicy: "Always", - }, - Volumes: []corev1.Volume{}, - }, - }, - } - - shc := &enterpriseApi.SearchHeadCluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test", - Namespace: "test", - }, - Spec: enterpriseApi.SearchHeadClusterSpec{ - CommonSplunkSpec: enterpriseApi.CommonSplunkSpec{ - Spec: enterpriseApi.Spec{ - ImagePullPolicy: "Always", - }, - Volumes: []corev1.Volume{}, - MonitoringConsoleRef: corev1.ObjectReference{ - Name: "test", - }, - }, - }, - } - mc.Spec.Image = "splunk/splunk:latest" - - builder := fake.NewClientBuilder() - client := builder.Build() - utilruntime.Must(enterpriseApi.AddToScheme(clientgoscheme.Scheme)) - - // Create the instances - client.Create(ctx, mc) - _, err := ApplyMonitoringConsole(ctx, client, mc) - if err != nil { - t.Errorf("applyMonitoringConsole should not have returned error; err=%v", err) - } - mc.Status.Phase = enterpriseApi.PhaseReady - err = client.Status().Update(ctx, mc) - if err != nil { - t.Errorf("Unexpected update pod %v", err) - debug.PrintStack() - } - client.Create(ctx, shc) - _, err = ApplySearchHeadCluster(ctx, client, shc) - if err != nil { - t.Errorf("applySearchHeadCluster should not have returned error; err=%v", err) - } - - err = changeSearchHeadAnnotations(ctx, client, mc) - if err != nil { - t.Errorf("changeSearchHeadAnnotations should not have returned error=%v", err) - } - searchHeadCluster := &enterpriseApi.SearchHeadCluster{} - namespacedName := types.NamespacedName{ - Name: shc.Name, - Namespace: shc.Namespace, - } - err = client.Get(ctx, namespacedName, searchHeadCluster) - if err != nil { - t.Errorf("changeSearchHeadAnnotations should not have returned error=%v", err) - } - - annotations := searchHeadCluster.GetAnnotations() - if annotations["splunk/image-tag"] != mc.Spec.Image { - t.Errorf("changeSearchHeadAnnotations should have set the splunk/image-tag annotation field to the current image") - } -}