@@ -593,15 +593,24 @@ func GetImagesFromApplication(app *v1alpha1.Application) image.ContainerImageLis
593
593
annotations := app .Annotations
594
594
for _ , img := range * parseImageList (annotations ) {
595
595
if img .HasForceUpdateOptionAnnotation (annotations , common .ImageUpdaterAnnotationPrefix ) {
596
- // for force-update images, try to get the current image tag from the spec
597
- // this helps handle cases where there are 0 replicas
598
- currentImage := getImageFromSpec (app , img )
599
- if currentImage != nil {
600
- img .ImageTag = currentImage .ImageTag
601
- } else {
602
- img .ImageTag = nil
596
+ // Check if this image is already in the list from status
597
+ found := false
598
+ for _ , existingImg := range images {
599
+ if existingImg .ImageName == img .ImageName {
600
+ found = true
601
+ break
602
+ }
603
+ }
604
+
605
+ if ! found {
606
+ currentImage := getImageFromSpec (app , img )
607
+ if currentImage != nil {
608
+ img .ImageTag = currentImage .ImageTag
609
+ } else {
610
+ img .ImageTag = nil
611
+ }
612
+ images = append (images , img )
603
613
}
604
- images = append (images , img )
605
614
}
606
615
}
607
616
@@ -751,25 +760,63 @@ func getImageFromSpec(app *v1alpha1.Application, targetImage *image.ContainerIma
751
760
switch appType {
752
761
case ApplicationTypeHelm :
753
762
if source .Helm != nil && source .Helm .Parameters != nil {
754
- // Define regex patterns for tag/version parameters
755
- tagPatterns := []* regexp.Regexp {
756
- regexp .MustCompile (`^(.+\.)?(tag|version|imageTag)$` ),
757
- regexp .MustCompile (`^(image|container)\.(.+\.)?(tag|version)$` ),
763
+ // Try to find image name and tag parameters
764
+ var imageName , imageTag string
765
+ imageNameParam := targetImage .GetParameterHelmImageName (app .Annotations , common .ImageUpdaterAnnotationPrefix )
766
+ imageTagParam := targetImage .GetParameterHelmImageTag (app .Annotations , common .ImageUpdaterAnnotationPrefix )
767
+
768
+ if imageNameParam == "" {
769
+ imageNameParam = registryCommon .DefaultHelmImageName
770
+ }
771
+ if imageTagParam == "" {
772
+ imageTagParam = registryCommon .DefaultHelmImageTag
758
773
}
759
-
774
+
760
775
for _ , param := range source .Helm .Parameters {
761
- // Check if parameter matches tag/version patterns
762
- for _ , pattern := range tagPatterns {
763
- if pattern .MatchString (param .Name ) {
764
- foundImage := image .NewFromIdentifier (fmt .Sprintf ("%s:%s" , targetImage .ImageName , param .Value ))
765
- if foundImage != nil && foundImage .ImageName == targetImage .ImageName {
766
- return foundImage
776
+ if param .Name == imageNameParam {
777
+ imageName = param .Value
778
+ }
779
+ if param .Name == imageTagParam {
780
+ imageTag = param .Value
781
+ }
782
+ }
783
+
784
+ if imageName != "" && imageTag != "" && imageName == targetImage .GetFullNameWithoutTag () {
785
+ foundImage := image .NewFromIdentifier (fmt .Sprintf ("%s:%s" , imageName , imageTag ))
786
+ if foundImage != nil {
787
+ return foundImage
788
+ }
789
+ }
790
+
791
+ if imageTag == "" {
792
+ tagPatterns := []* regexp.Regexp {
793
+ regexp .MustCompile (`^(.+\.)?(tag|version|imageTag)$` ),
794
+ regexp .MustCompile (`^(image|container)\.(.+\.)?(tag|version)$` ),
795
+ }
796
+
797
+ for _ , param := range source .Helm .Parameters {
798
+ for _ , pattern := range tagPatterns {
799
+ if pattern .MatchString (param .Name ) && param .Value != "" {
800
+ prefix := strings .TrimSuffix (param .Name , ".tag" )
801
+ prefix = strings .TrimSuffix (prefix , ".version" )
802
+ prefix = strings .TrimSuffix (prefix , ".imageTag" )
803
+
804
+ for _ , p := range source .Helm .Parameters {
805
+ if (p .Name == prefix || p .Name == prefix + ".name" || p .Name == prefix + ".repository" ) &&
806
+ p .Value == targetImage .GetFullNameWithoutTag () {
807
+ foundImage := image .NewFromIdentifier (fmt .Sprintf ("%s:%s" , targetImage .GetFullNameWithoutTag (), param .Value ))
808
+ if foundImage != nil {
809
+ return foundImage
810
+ }
811
+ }
812
+ }
767
813
}
768
- break
769
814
}
770
815
}
771
-
772
- if param .Name == "image" || param .Name == "image.repository" {
816
+ }
817
+
818
+ for _ , param := range source .Helm .Parameters {
819
+ if param .Name == "image" || param .Name == "image.repository" || param .Name == registryCommon .DefaultHelmImageName {
773
820
foundImage := image .NewFromIdentifier (param .Value )
774
821
if foundImage != nil && foundImage .ImageName == targetImage .ImageName {
775
822
return foundImage
0 commit comments