Skip to content

Commit

Permalink
Fix indexer deletion in upgrade scenario (#1240)
Browse files Browse the repository at this point in the history
Co-authored-by: Tanguy Maltaverne <[email protected]>
Co-authored-by: Arjun Kondur <[email protected]>
Co-authored-by: gaurav-splunk <[email protected]>
  • Loading branch information
4 people authored Oct 6, 2023
1 parent 1aa2ca7 commit e7606aa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/splunk/enterprise/indexercluster.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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")
}
}

0 comments on commit e7606aa

Please sign in to comment.