diff --git a/pkg/splunk/enterprise/indexercluster.go b/pkg/splunk/enterprise/indexercluster.go index 8ad327b38..c52528713 100644 --- a/pkg/splunk/enterprise/indexercluster.go +++ b/pkg/splunk/enterprise/indexercluster.go @@ -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 @@ -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 @@ -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") +} diff --git a/pkg/splunk/enterprise/indexercluster_test.go b/pkg/splunk/enterprise/indexercluster_test.go index 73bfb698b..1eeda101b 100644 --- a/pkg/splunk/enterprise/indexercluster_test.go +++ b/pkg/splunk/enterprise/indexercluster_test.go @@ -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") + } +}