Skip to content

Commit 50f7777

Browse files
committed
fix: Only fetch metadata when it is required by update-strategy (#32)
* fix: Only fetch metadata when it is required by update-strategy * Update CHANGELOG
1 parent aa6b869 commit 50f7777

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ handling on your side.
88

99
### Upgrade notes (no really, you MUST read this)
1010

11+
### Bug fixes
12+
13+
* fix: Only fetch metadata when require by update strategy
14+
15+
### New features
16+
17+
### Other changes
18+
19+
## 2020-08-10 - Release v0.3.0
20+
21+
### Upgrade notes (no really, you MUST read this)
22+
1123
* Syntax change for running: `argocd-image-updater run [flags]` instead of `argocd-image-updater [flags]` has now to be used
1224
* **Attention:** Helm annotation names have changed from `<image_alias>.image-{name,tag,spec}` to `<image_alias>.helm.image-{name,tag,spec}`
1325
* Specifying target image name for Kustomize applications now require their own annotation, the image alias is not re-used for this anymore

cmd/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,6 @@ func updateApplication(argoClient *argocd.ArgoCD, kubeClient *client.KubernetesC
9090
continue
9191
}
9292

93-
// Get list of available image tags from the repository
94-
tags, err := rep.GetTags(applicationImage, kubeClient)
95-
if err != nil {
96-
imgCtx.Errorf("Could not get tags from registry: %v", err)
97-
result.NumErrors += 1
98-
continue
99-
}
100-
101-
imgCtx.Tracef("List of available tags found: %v", tags.Tags())
102-
10393
var vc image.VersionConstraint
10494
if updateableImage.ImageTag != nil {
10595
vc.Constraint = updateableImage.ImageTag.TagName
@@ -110,6 +100,16 @@ func updateApplication(argoClient *argocd.ArgoCD, kubeClient *client.KubernetesC
110100

111101
vc.SortMode = updateableImage.GetParameterUpdateStrategy(curApplication.Application.Annotations)
112102

103+
// Get list of available image tags from the repository
104+
tags, err := rep.GetTags(applicationImage, kubeClient, &vc)
105+
if err != nil {
106+
imgCtx.Errorf("Could not get tags from registry: %v", err)
107+
result.NumErrors += 1
108+
continue
109+
}
110+
111+
imgCtx.Tracef("List of available tags found: %v", tags.Tags())
112+
113113
// Get the latest available tag matching any constraint that might be set
114114
// for allowed updates.
115115
latest, err := applicationImage.GetNewestVersionFromTags(&vc, tags)

pkg/registry/registry.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
// GetTags returns a list of available tags for the given image
23-
func (clientInfo *RegistryEndpoint) GetTags(img *image.ContainerImage, kubeClient *client.KubernetesClient) (*tag.ImageTagList, error) {
23+
func (clientInfo *RegistryEndpoint) GetTags(img *image.ContainerImage, kubeClient *client.KubernetesClient, vc *image.VersionConstraint) (*tag.ImageTagList, error) {
2424
var tagList *tag.ImageTagList = tag.NewImageTagList()
2525
var imgTag *tag.ImageTag
2626
var err error
@@ -51,6 +51,16 @@ func (clientInfo *RegistryEndpoint) GetTags(img *image.ContainerImage, kubeClien
5151
return nil, err
5252
}
5353

54+
// If we don't want to fetch meta data, just build the taglist and return it
55+
// with dummy meta data.
56+
if vc.SortMode != image.VersionSortLatest {
57+
for _, tagStr := range tags {
58+
imgTag = tag.NewImageTag(tagStr, time.Unix(0, 0))
59+
tagList.Add(imgTag)
60+
}
61+
return tagList, nil
62+
}
63+
5464
// Fetch the manifest for the tag -- we need v1, because it contains history
5565
// information that we require.
5666
for _, tagStr := range tags {

0 commit comments

Comments
 (0)