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

Ignore secret checks in the indexercluster when the pod is not yet created #1430

Open
wants to merge 1 commit 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
14 changes: 12 additions & 2 deletions pkg/splunk/enterprise/indexercluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,17 +653,27 @@ func ApplyIdxcSecret(ctx context.Context, mgr *indexerClusterPodManager, replica
// Get Indexer's name
indexerPodName := GetSplunkStatefulsetPodName(SplunkIndexer, mgr.cr.GetName(), i)

// Check if pod exists before updating secrets
pod := &corev1.Pod{}
namespacedName := types.NamespacedName{Namespace: mgr.cr.GetNamespace(), Name: indexerPodName}
scopedLog.Info("Check if pod is created before updating its secrets")
err := mgr.c.Get(ctx, namespacedName, pod)
if err != nil {
mgr.log.Info("Peer doesn't exists", "peerName", indexerPodName)
continue
}

// Retrieve secret from pod
podSecret, err := splutil.GetSecretFromPod(ctx, mgr.c, indexerPodName, mgr.cr.GetNamespace())
if err != nil {
return fmt.Errorf(fmt.Sprintf(splcommon.PodSecretNotFoundError, indexerPodName))
return fmt.Errorf(splcommon.PodSecretNotFoundError, indexerPodName)
}

// Retrieve idxc_secret token
if indIdxcSecretByte, ok := podSecret.Data[splcommon.IdxcSecret]; ok {
indIdxcSecret = string(indIdxcSecretByte)
} else {
return fmt.Errorf(fmt.Sprintf(splcommon.SecretTokenNotRetrievable, splcommon.IdxcSecret))
return fmt.Errorf(splcommon.SecretTokenNotRetrievable, splcommon.IdxcSecret)
}

// If idxc secret is different from namespace scoped secret change it
Expand Down
14 changes: 14 additions & 0 deletions pkg/splunk/enterprise/indexercluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,20 @@ func TestApplyIdxcSecret(t *testing.T) {
if err.Error() != fmt.Sprintf(splcommon.PodSecretNotFoundError, podName) {
t.Errorf("Couldn't recognize missing secret from Pod, error: %s", err.Error())
}

// Test the secret update is skipped when the pod is not existing
err = splutil.UpdateResource(ctx, c, secrets)
if err != nil {
t.Errorf("Couldn't update resource %v, err: %v", secrets, err)
}
err = splutil.DeleteResource(ctx, c, pod)
if err != nil {
t.Errorf("Couldn't update resource %v, err: %v", pod, err)
}
err = ApplyIdxcSecret(ctx, mgr, 1, mockPodExecClient)
if err != nil {
t.Errorf("Couldn't recognize missing idxc secret %s", err.Error())
}
}

func TestInvalidIndexerClusterSpec(t *testing.T) {
Expand Down
Loading