Skip to content
Merged
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
19 changes: 19 additions & 0 deletions pkg/splunk/controller/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,22 @@ func ApplyConfigMap(client splcommon.ControllerClient, configMap *corev1.ConfigM

return err
}

// getConfigMap gets the ConfigMap resource in a given namespace
func getConfigMap(client splcommon.ControllerClient, namespacedName types.NamespacedName) (corev1.ConfigMap, error) {
var configMap corev1.ConfigMap
err := client.Get(context.TODO(), namespacedName, &configMap)
if err != nil {
return configMap, err
}
return configMap, nil
}

// GetConfigMapResourceVersion gets the Resource version of a configMap
func GetConfigMapResourceVersion(client splcommon.ControllerClient, namespacedName types.NamespacedName) (string, error) {
configMap, err := getConfigMap(client, namespacedName)
if err != nil {
return "", err
}
return configMap.ResourceVersion, nil
}
17 changes: 16 additions & 1 deletion pkg/splunk/enterprise/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"

enterprisev1 "github.com/splunk/splunk-operator/pkg/apis/enterprise/v1alpha3"
splcommon "github.com/splunk/splunk-operator/pkg/splunk/common"
splctrl "github.com/splunk/splunk-operator/pkg/splunk/controller"
splutil "github.com/splunk/splunk-operator/pkg/splunk/util"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -477,14 +479,27 @@ func updateSplunkPodTemplateWithConfig(client splcommon.ControllerClient, podTem

// add inline defaults to all splunk containers other than MC(where CR spec defaults are not needed)
if spec.Defaults != "" && instanceType != SplunkMonitoringConsole {
configMapName := GetSplunkDefaultsName(cr.GetName(), instanceType)
addSplunkVolumeToTemplate(podTemplateSpec, "defaults", corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: GetSplunkDefaultsName(cr.GetName(), instanceType),
Name: configMapName,
},
DefaultMode: &configMapVolDefaultMode,
},
})

scopedLog := log.WithName("updateSplunkPodTemplateWithConfig").WithValues("name", cr.GetName(), "namespace", cr.GetNamespace())
namespacedName := types.NamespacedName{Namespace: cr.GetNamespace(), Name: configMapName}

// We will update the annotation for resource version in the pod template spec
// so that any change in the ConfigMap will lead to recycle of the pod.
configMapResourceVersion, err := splctrl.GetConfigMapResourceVersion(client, namespacedName)
if err == nil {
podTemplateSpec.ObjectMeta.Annotations["defaultConfigRev"] = configMapResourceVersion
} else {
scopedLog.Error(err, "Updation of default configMap annotation failed")
}
}

// update security context
Expand Down