Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft]: CSPL-2758: Optional level 2 validation in SOK #1371

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion config/default/kustomization-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ patches:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
fieldPath: metadata.name
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
6 changes: 5 additions & 1 deletion config/default/kustomization-namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,8 @@ patches:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
fieldPath: metadata.name
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
6 changes: 5 additions & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ patches:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
fieldPath: metadata.name
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
3 changes: 2 additions & 1 deletion config/manager/config.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
OPERATOR_NAME="splunk-operator"
WATCH_NAMESPACE
RELATED_IMAGE_SPLUNK_ENTERPRISE
RELATED_IMAGE_SPLUNK_ENTERPRISE
SPLUNK_LEVEL_2=true
11 changes: 7 additions & 4 deletions pkg/splunk/enterprise/clustermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
18 changes: 12 additions & 6 deletions pkg/splunk/enterprise/indexercluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions pkg/splunk/enterprise/monitoringconsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
9 changes: 6 additions & 3 deletions pkg/splunk/enterprise/searchheadcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
39 changes: 39 additions & 0 deletions pkg/splunk/enterprise/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading