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

CSPL-465: Fix the updation of ConfigMap by adding resource version of ConfigMap as annotation in the CR #131

Merged
merged 7 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions pkg/splunk/enterprise/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package enterprise

import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"

logf "sigs.k8s.io/controller-runtime/pkg/log"

Expand Down Expand Up @@ -47,11 +49,34 @@ func ApplySplunkConfig(client splcommon.ControllerClient, cr splcommon.MetaObjec
if err = splctrl.ApplyConfigMap(client, defaultsMap); err != nil {
return nil, err
}
// We will update the annotation for resource version in the pod template spec
// of the CR, so that any change in the ConfigMap will lead to recycle of the pod.
err = updateDefaultConfigMapAnnotations(client, cr, defaultsMap)
if err != nil {
return nil, err
}
}

return namespaceScopedSecret, nil
}

// updateDefaultConfigMapAnnotations checks and gets the default config map and updates the annotation
// for the resource version of the ConfigMap in the pod template spec for the CR.
func updateDefaultConfigMapAnnotations(client splcommon.ControllerClient, cr splcommon.MetaObject, configMap *corev1.ConfigMap) error {
namespacedName := types.NamespacedName{Namespace: configMap.GetNamespace(), Name: configMap.GetName()}
var current corev1.ConfigMap

err := client.Get(context.TODO(), namespacedName, &current)
if err != nil {
return err
}
annotationsMap := cr.GetObjectMeta().GetAnnotations()
gaurav-splunk marked this conversation as resolved.
Show resolved Hide resolved
if annotationsMap != nil {
gaurav-splunk marked this conversation as resolved.
Show resolved Hide resolved
annotationsMap["defaultConfigRev"] = current.ObjectMeta.ResourceVersion
}
return nil
}

// getIndexerExtraEnv returns extra environment variables used by indexer clusters
func getIndexerExtraEnv(cr splcommon.MetaObject, replicas int32) []corev1.EnvVar {
return []corev1.EnvVar{
Expand Down
3 changes: 2 additions & 1 deletion pkg/splunk/enterprise/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func TestApplySplunkConfig(t *testing.T) {
funcCalls := []spltest.MockFuncCall{
{MetaName: "*v1.Secret-test-splunk-test-secret"},
{MetaName: "*v1.ConfigMap-test-splunk-stack1-search-head-defaults"},
{MetaName: "*v1.ConfigMap-test-splunk-stack1-search-head-defaults"},
}
createCalls := map[string][]spltest.MockFuncCall{"Get": funcCalls, "Create": funcCalls}
createCalls := map[string][]spltest.MockFuncCall{"Get": funcCalls, "Create": {funcCalls[0], funcCalls[1]}}
updateCalls := map[string][]spltest.MockFuncCall{"Get": funcCalls}
searchHeadCR := enterprisev1.SearchHeadCluster{
TypeMeta: metav1.TypeMeta{
Expand Down