diff --git a/Dockerfile b/Dockerfile index c1659317d..dd819eaa5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build the manager binary -FROM golang:1.21.1 as builder +FROM golang:1.21.1 AS builder WORKDIR /workspace # Copy the Go Modules manifests diff --git a/config/default/kustomization-cluster.yaml b/config/default/kustomization-cluster.yaml index fa36d8a21..ca162baf7 100644 --- a/config/default/kustomization-cluster.yaml +++ b/config/default/kustomization-cluster.yaml @@ -130,4 +130,8 @@ patches: - name: POD_NAME valueFrom: fieldRef: - fieldPath: metadata.name \ No newline at end of file + fieldPath: metadata.name + - name: OPERATOR_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace \ No newline at end of file diff --git a/config/default/kustomization-namespace.yaml b/config/default/kustomization-namespace.yaml index c8d7cf58d..ce0d66eac 100644 --- a/config/default/kustomization-namespace.yaml +++ b/config/default/kustomization-namespace.yaml @@ -132,4 +132,8 @@ patches: - name: POD_NAME valueFrom: fieldRef: - fieldPath: metadata.name \ No newline at end of file + fieldPath: metadata.name + - name: OPERATOR_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace \ No newline at end of file diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 71bb89d95..66fe644db 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -130,4 +130,8 @@ patches: - name: POD_NAME valueFrom: fieldRef: - fieldPath: metadata.name \ No newline at end of file + fieldPath: metadata.name + - name: OPERATOR_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace \ No newline at end of file diff --git a/config/manager/config.properties b/config/manager/config.properties index d7e9cf677..8a6dd175c 100644 --- a/config/manager/config.properties +++ b/config/manager/config.properties @@ -1,3 +1,4 @@ OPERATOR_NAME="splunk-operator" WATCH_NAMESPACE -RELATED_IMAGE_SPLUNK_ENTERPRISE \ No newline at end of file +RELATED_IMAGE_SPLUNK_ENTERPRISE +SPLUNK_LEVEL_2=true \ No newline at end of file diff --git a/pkg/splunk/enterprise/clustermanager.go b/pkg/splunk/enterprise/clustermanager.go index 4ba7ca38a..ddc9ace75 100644 --- a/pkg/splunk/enterprise/clustermanager.go +++ b/pkg/splunk/enterprise/clustermanager.go @@ -185,10 +185,13 @@ func ApplyClusterManager(ctx context.Context, client splcommon.ControllerClient, return result, err } - // check if the ClusterManager is ready for version upgrade, if required - continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, nil) - if err != nil || !continueReconcile { - return result, err + supported, err := CheckSplunkLevel2Config(ctx, client) + if err != nil && supported { + // check if the ClusterManager is ready for version upgrade, if required + continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, nil) + if err != nil || !continueReconcile { + return result, err + } } clusterManagerManager := splctrl.DefaultStatefulSetPodManager{} diff --git a/pkg/splunk/enterprise/indexercluster.go b/pkg/splunk/enterprise/indexercluster.go index 723e3c1a6..aea2e7c7a 100644 --- a/pkg/splunk/enterprise/indexercluster.go +++ b/pkg/splunk/enterprise/indexercluster.go @@ -203,9 +203,12 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller // check if the IndexerCluster is ready for version upgrade cr.Kind = "IndexerCluster" - continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, &mgr) - if err != nil || !continueReconcile { - return result, err + supported, err := CheckSplunkLevel2Config(ctx, client) + if err != nil && supported { + continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, &mgr) + if err != nil || !continueReconcile { + return result, err + } } // check if version upgrade is set @@ -455,9 +458,12 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient, // check if the IndexerCluster is ready for version upgrade cr.Kind = "IndexerCluster" - continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, &mgr) - if err != nil || !continueReconcile { - return result, err + supported, err := CheckSplunkLevel2Config(ctx, client) + if err != nil && supported { + continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, &mgr) + if err != nil || !continueReconcile { + return result, err + } } // check if version upgrade is set diff --git a/pkg/splunk/enterprise/monitoringconsole.go b/pkg/splunk/enterprise/monitoringconsole.go index 83af4a482..e9c4ac546 100644 --- a/pkg/splunk/enterprise/monitoringconsole.go +++ b/pkg/splunk/enterprise/monitoringconsole.go @@ -141,10 +141,13 @@ func ApplyMonitoringConsole(ctx context.Context, client splcommon.ControllerClie return result, err } - // check if the Monitoring Console is ready for version upgrade, if required - continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, nil) - if err != nil || !continueReconcile { - return result, err + supported, err := CheckSplunkLevel2Config(ctx, client) + if err != nil && supported { + // check if the Monitoring Console is ready for version upgrade, if required + continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, nil) + if err != nil || !continueReconcile { + return result, err + } } mgr := splctrl.DefaultStatefulSetPodManager{} diff --git a/pkg/splunk/enterprise/searchheadcluster.go b/pkg/splunk/enterprise/searchheadcluster.go index fcaabe6cc..adc0ff437 100644 --- a/pkg/splunk/enterprise/searchheadcluster.go +++ b/pkg/splunk/enterprise/searchheadcluster.go @@ -166,9 +166,12 @@ func ApplySearchHeadCluster(ctx context.Context, client splcommon.ControllerClie return result, err } - continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, nil) - if err != nil || !continueReconcile { - return result, err + supported, err := CheckSplunkLevel2Config(ctx, client) + if err != nil && supported { + continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, nil) + if err != nil || !continueReconcile { + return result, err + } } deployerManager := splctrl.DefaultStatefulSetPodManager{} diff --git a/pkg/splunk/enterprise/util.go b/pkg/splunk/enterprise/util.go index 4a70f0d6b..4d21ab354 100644 --- a/pkg/splunk/enterprise/util.go +++ b/pkg/splunk/enterprise/util.go @@ -2368,3 +2368,42 @@ func changeAnnotations(ctx context.Context, c splcommon.ControllerClient, image err := c.Update(ctx, cr) return err } + +// CheckSplunkLevel2Config checks the "splunk-operator-config" ConfigMap in the namespace +// specified by the "OPERATOR_NAME" environment variable. It returns true if the key +// "SPLUNK_LEVEL_2" is not set to "false" or if there is an error fetching the ConfigMap. +func CheckSplunkLevel2Config(ctx context.Context, c client.Client) (bool, error) { + // Define the ConfigMap object + var configMap corev1.ConfigMap + + reqLogger := log.FromContext(ctx) + scopedLog := reqLogger.WithName("CheckSplunkLevel2Config").WithValues() + + // Read the namespace from the environment variable "OPERATOR_NAME" + namespace := os.Getenv("OPERATOR_NAMESPACE") + if namespace == "" { + return true, fmt.Errorf("environment variable OPERATOR_NAME is not set") + } + + // Attempt to get the ConfigMap named "splunk-operator-config" in the provided namespace + err := c.Get(ctx, types.NamespacedName{Name: "splunk-operator-config", Namespace: namespace}, &configMap) + if err != nil { + // Log the error and return true, as per requirements + scopedLog.Error(err, "Failed to fetch ConfigMap") + return true, err + } + + // Extract data from the ConfigMap + configData := configMap.Data + + // Check for the key "SPLUNK_LEVEL_2" + if value, exists := configData["SPLUNK_LEVEL_2"]; exists { + // If the value is "false", return false + if value == "false" { + return false, nil + } + } + + // For any other condition, return true + return true, nil +}