Skip to content
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
75 changes: 57 additions & 18 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,60 @@
return fmt.Errorf("cannot set Helm params on non-Helm application")
}

appName := app.GetName()
appNamespace := app.GetNamespace()
desiredReleaseName := newImage.GetParameterHelmReleaseName(app.Annotations, common.ImageUpdaterAnnotationPrefix)

Check failure on line 433 in pkg/argocd/argocd.go

View workflow job for this annotation

GitHub Actions / Ensure code is correctly linted

newImage.GetParameterHelmReleaseName undefined (type *"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image".ContainerImage has no field or method GetParameterHelmReleaseName)) (typecheck)

Check failure on line 433 in pkg/argocd/argocd.go

View workflow job for this annotation

GitHub Actions / Ensure code is correctly linted

newImage.GetParameterHelmReleaseName undefined (type *"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image".ContainerImage has no field or method GetParameterHelmReleaseName) (typecheck)

Check failure on line 433 in pkg/argocd/argocd.go

View workflow job for this annotation

GitHub Actions / Ensure registry-scanner Go modules synchronicity and run tests

newImage.GetParameterHelmReleaseName undefined (type *"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image".ContainerImage has no field or method GetParameterHelmReleaseName)

Check failure on line 433 in pkg/argocd/argocd.go

View workflow job for this annotation

GitHub Actions / Ensure unit tests are passing

newImage.GetParameterHelmReleaseName undefined (type *"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image".ContainerImage has no field or method GetParameterHelmReleaseName)

var matchedSource *v1alpha1.ApplicationSource
if app.Spec.HasMultipleSources() {
for i := range app.Spec.Sources {
source := &app.Spec.Sources[i]
if source.Helm == nil {
continue
}
if desiredReleaseName != "" {
if source.Helm.ReleaseName == desiredReleaseName {
matchedSource = source
break
}
}
}
if matchedSource == nil {
if desiredReleaseName != "" {
log.WithContext().
AddField("application", app.GetName()).
Warnf("No matching source found for release name %q", desiredReleaseName)
return nil
}
for i := range app.Spec.Sources {
if app.Spec.Sources[i].Helm != nil {
matchedSource = &app.Spec.Sources[i]
break
}
}
}
} else {
matchedSource = app.Spec.Source
}

if matchedSource == nil {
return fmt.Errorf("no valid Helm source found")
}

if matchedSource.Helm == nil {
matchedSource.Helm = &v1alpha1.ApplicationSourceHelm{}
}

if matchedSource.Helm.Parameters == nil {
matchedSource.Helm.Parameters = make([]v1alpha1.HelmParameter, 0)
}

actualReleaseName := matchedSource.Helm.ReleaseName
if desiredReleaseName != "" && actualReleaseName != "" && desiredReleaseName != actualReleaseName {
log.WithContext().
AddField("application", app.GetName()).
Warnf("Skipping image update for %s: annotation release-name=%q but actual Helm releaseName=%q",
newImage.GetFullNameWithTag(), desiredReleaseName, actualReleaseName)
return nil
}

var hpImageName, hpImageTag, hpImageSpec string

Expand All @@ -449,16 +501,13 @@
}

log.WithContext().
AddField("application", appName).
AddField("application", app.GetName()).
AddField("image", newImage.GetFullNameWithoutTag()).
AddField("namespace", appNamespace).
AddField("release", actualReleaseName).
Debugf("target parameters: image-spec=%s image-name=%s, image-tag=%s", hpImageSpec, hpImageName, hpImageTag)

mergeParams := make([]v1alpha1.HelmParameter, 0)

// The logic behind this is that image-spec is an override - if this is set,
// we simply ignore any image-name and image-tag parameters that might be
// there.
if hpImageSpec != "" {
p := v1alpha1.HelmParameter{Name: hpImageSpec, Value: newImage.GetFullNameWithTag(), ForceString: true}
mergeParams = append(mergeParams, p)
Expand All @@ -473,17 +522,7 @@
}
}

appSource := getApplicationSource(app)

if appSource.Helm == nil {
appSource.Helm = &v1alpha1.ApplicationSourceHelm{}
}

if appSource.Helm.Parameters == nil {
appSource.Helm.Parameters = make([]v1alpha1.HelmParameter, 0)
}

appSource.Helm.Parameters = mergeHelmParams(appSource.Helm.Parameters, mergeParams)
matchedSource.Helm.Parameters = mergeHelmParams(matchedSource.Helm.Parameters, mergeParams)

return nil
}
Expand Down
7 changes: 4 additions & 3 deletions registry-scanner/pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const (

// Helm related annotations
const (
HelmParamImageNameAnnotationSuffix = "/%s.helm.image-name"
HelmParamImageTagAnnotationSuffix = "/%s.helm.image-tag"
HelmParamImageSpecAnnotationSuffix = "/%s.helm.image-spec"
HelmParamImageNameAnnotationSuffix = "/%s.helm.image-name"
HelmParamImageTagAnnotationSuffix = "/%s.helm.image-tag"
HelmParamImageSpecAnnotationSuffix = "/%s.helm.image-spec"
HelmParamReleaseNameAnnotationSuffix = "/%s.helm.release-name"
)

// Kustomize related annotations
Expand Down
11 changes: 11 additions & 0 deletions registry-scanner/pkg/image/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ func (img *ContainerImage) GetParameterHelmImageSpec(annotations map[string]stri
return val
}

// GetParameterHelmReleaseName gets the value for release-name option for the
// image from a set of annotations
func (img *ContainerImage) GetParameterHelmReleaseName(annotations map[string]string, annotationPrefix string) string {
key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.HelmParamReleaseNameAnnotationSuffix), img.normalizedSymbolicName())
val, ok := annotations[key]
if !ok {
return ""
}
return val
}

// GetParameterKustomizeImageName gets the value for image-spec option for the
// image from a set of annotations
func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string]string, annotationPrefix string) string {
Expand Down
Loading