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

Fix indexer deletion in upgrade scenario #1153

Open
wants to merge 3 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions pkg/splunk/enterprise/indexercluster.go
Expand Up @@ -185,7 +185,7 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
for _, owner := range v.GetOwnerReferences() {
if owner.UID == statefulSet.UID {
// get the pod image name
if v.Spec.Containers[0].Image != cr.Spec.Image {
if imageUpdatedTo9(v.Spec.Containers[0].Image, cr.Spec.Image) {
// image do not match that means its image upgrade
versionUpgrade = true
break
Expand Down Expand Up @@ -428,11 +428,8 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
for _, v := range statefulsetPods.Items {
for _, owner := range v.GetOwnerReferences() {
if owner.UID == statefulSet.UID {
previousImage := v.Spec.Containers[0].Image
currentImage := cr.Spec.Image
// get the pod image name
if strings.HasPrefix(previousImage, "8") &&
strings.HasPrefix(currentImage, "9") {
if imageUpdatedTo9(v.Spec.Containers[0].Image, cr.Spec.Image) {
// image do not match that means its image upgrade
versionUpgrade = true
break
Expand Down Expand Up @@ -1069,3 +1066,14 @@ func RetrieveCMSpec(ctx context.Context, client splcommon.ControllerClient, cr *

return "", nil
}

// Tells if there is an image migration from 8.x.x to 9.x.x
func imageUpdatedTo9(previousImage string, currentImage string) bool {
// If there is no colon, version can't be detected
if !strings.Contains(previousImage, ":") || !strings.Contains(currentImage, ":") {
return false
}
previousVersion := strings.Split(previousImage, ":")[1]
currentVersion := strings.Split(currentImage, ":")[1]
return strings.HasPrefix(previousVersion, "8") && strings.HasPrefix(currentVersion, "9")
}
18 changes: 18 additions & 0 deletions pkg/splunk/enterprise/indexercluster_test.go
Expand Up @@ -1875,3 +1875,21 @@ func TestIndexerClusterWithReadyState(t *testing.T) {
debug.PrintStack()
}
}

func TestImageUpdatedTo9(t *testing.T) {
if !imageUpdatedTo9("splunk/splunk:8.2.6", "splunk/splunk:9.0.0") {
t.Errorf("Should have detected an upgrade from 8 to 9")
}
if imageUpdatedTo9("splunk/splunk:9.0.3", "splunk/splunk:9.0.4") {
t.Errorf("Should not have detected an upgrade from 8 to 9")
}
if imageUpdatedTo9("splunk/splunk:8.2.6", "splunk/splunk:latest") {
t.Errorf("Should not have detected an upgrade from 8 to 9, latest doesn't allow to know the version")
}
if imageUpdatedTo9("splunk/splunk", "splunk/splunk") {
t.Errorf("Should not have detected an upgrade from 8 to 9, there is no colon and version")
}
if imageUpdatedTo9("splunk/splunk:", "splunk/splunk:") {
t.Errorf("Should not have detected an upgrade from 8 to 9, there is no version")
}
}