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
9 changes: 9 additions & 0 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,15 @@ func SetHelmImage(app *v1alpha1.Application, newImage *image.ContainerImage) err
return nil
}

// recordOriginalTag saves the original tag as an annotation (digest strategy only)
func RecordOriginalTag(app *v1alpha1.Application, imageName, originalTag string) {
if app.Annotations == nil {
app.Annotations = make(map[string]string)
}
key := fmt.Sprintf("argocd-image-updater.argoproj.io/original-tag.%s", imageName)
app.Annotations[key] = originalTag
}

// GetKustomizeImage gets the image set in Application source matching new image
// or an empty string if match is not found
func GetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage) (string, error) {
Expand Down
40 changes: 40 additions & 0 deletions pkg/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,43 @@
assert.Equal(t, "baz", imgs[0].KustomizeImage.ImageName)
})
}

func Test_RecordOriginalTag(t *testing.T) {
tests := []struct {
name string
app *v1alpha1.Application
imageName string
originalTag string
}{
{
name: "when annotations already exist",
app: &v1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{

Check failure on line 1249 in pkg/argocd/argocd_test.go

View workflow job for this annotation

GitHub Actions / Ensure code is correctly linted

undefined: metav1

Check failure on line 1249 in pkg/argocd/argocd_test.go

View workflow job for this annotation

GitHub Actions / Ensure unit tests are passing

undefined: metav1
Annotations: map[string]string{},
},
},
imageName: "nginx",
originalTag: "1.14.2",
},
{
name: "when annotations is nil",
app: &v1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{

Check failure on line 1259 in pkg/argocd/argocd_test.go

View workflow job for this annotation

GitHub Actions / Ensure code is correctly linted

undefined: metav1 (typecheck)

Check failure on line 1259 in pkg/argocd/argocd_test.go

View workflow job for this annotation

GitHub Actions / Ensure unit tests are passing

undefined: metav1
Annotations: nil,
},
},
imageName: "redis",
originalTag: "6.0",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
RecordOriginalTag(tt.app, tt.imageName, tt.originalTag)

key := fmt.Sprintf("argocd-image-updater.argoproj.io/original-tag.%s", tt.imageName)
require.NotNil(t, tt.app.Annotations)
require.Equal(t, tt.originalTag, tt.app.Annotations[key])
})
}
}
9 changes: 9 additions & 0 deletions pkg/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
}

if needsUpdate(updateableImage, applicationImage, latest, vc.Strategy) {

if vc.Strategy == image.StrategyDigest && applicationImage.ImageTag != nil {
RecordOriginalTag(
&updateConf.UpdateApp.Application,
applicationImage.ImageName,
applicationImage.ImageTag.TagName,
)
}

appImageWithTag := applicationImage.WithTag(latest)
appImageFullNameWithTag := appImageWithTag.GetFullNameWithTag()

Expand Down
Loading