Skip to content

Commit

Permalink
change hold file contents and selection approach
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Gee <[email protected]>
  • Loading branch information
rgee0 committed Nov 21, 2024
1 parent 35817a0 commit 9d5e9bb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 73 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ db:
Associated hold file:

```
postgres:16
db.image
```

```bash
Expand All @@ -413,7 +413,7 @@ arkade chart upgrade -f \
2023/01/03 10:12:54 [nats] 2.9.2 => 2.9.10
```

Within the uprgade activity `postgres:16` is no longer included.
Within the upgrade activity `postgres:16` is no longer included.

Supported:

Expand Down
9 changes: 5 additions & 4 deletions cmd/chart/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Otherwise, it returns a non-zero exit code and the updated values.yaml file.`,
return err
}

filtered := helm.FilterImagesUptoDepth(values, depth)
filtered := helm.FilterImagesUptoDepth(values, depth, 0, "")
if len(filtered) == 0 {
return fmt.Errorf("no images found in %s", file)
}
Expand Down Expand Up @@ -144,8 +144,8 @@ Otherwise, it returns a non-zero exit code and the updated values.yaml file.`,
}()
}

for k := range filtered {
workChan <- k
for _, v := range filtered {
workChan <- v
}

close(workChan)
Expand Down Expand Up @@ -297,8 +297,9 @@ func readFileLines(filename string) ([]string, error) {
func removeHoldImages(fullset map[string]string, held []string) map[string]string {

for _, h := range held {
serviceName := strings.TrimSuffix(h, ".image")
for k := range fullset {
if strings.EqualFold(h, k[len(k)-len(h):]) {
if strings.EqualFold(serviceName, k) {
delete(fullset, k)
}
}
Expand Down
82 changes: 19 additions & 63 deletions cmd/chart/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,91 +384,47 @@ func TestRemoveHoldImages(t *testing.T) {
{
name: "Basic exclusion",
fullset: map[string]string{
"registry/img1:16": "going",
"registry/img1:17": "staying",
"registry/img1:18": "staying",
"going": "registry/img1:16",
"staying1": "registry/img1:17",
"staying2": "registry/img1:18",
},
held: []string{
"img1:16",
"going.image",
},
expected: map[string]string{
"registry/img1:17": "staying",
"registry/img1:18": "staying",
"staying1": "registry/img1:17",
"staying2": "registry/img1:18",
},
},
{
name: "Basic exclusion / muli-match",
fullset: map[string]string{
"registry/img1:16": "going",
"registry/img1:17": "going",
"registry/img1:18": "staying",
"going1": "registry/img1:16",
"going2": "registry/img1:17",
"staying": "registry/img1:18",
},
held: []string{
"img1:16",
"img1:17",
"going1.image",
"going2.image",
},
expected: map[string]string{
"registry/img1:18": "staying",
"staying": "registry/img1:18",
},
},
{
name: "No match",
fullset: map[string]string{
"registry/img1:17": "staying",
"registry/img1:18": "staying",
"registry/img1:19": "staying",
"staying1": "registry/img1:17",
"staying2": "registry/img1:18",
"staying3": "registry/img1:19",
},
held: []string{
"img1:16",
"going.image",
},
expected: map[string]string{
"registry/img1:17": "staying",
"registry/img1:18": "staying",
"registry/img1:19": "staying",
},
},
{
name: "Different Repos images match",
fullset: map[string]string{
"registry/repo/img1:16": "going",
"registry/repo2/img1:16": "going",
"registry/repo3/img1:18": "staying",
},
held: []string{
"img1:16",
},
expected: map[string]string{
"registry/repo3/img1:18": "staying",
},
},
{
name: "Different Repos images match / full path exclude",
fullset: map[string]string{
"registry/repo/img1:16": "going",
"registry/repo2/img1:16": "staying",
"registry/repo3/img1:18": "staying",
},
held: []string{
"registry/repo/img1:16",
},
expected: map[string]string{
"registry/repo2/img1:16": "staying",
"registry/repo3/img1:18": "staying",
},
},
{
name: "Different Repos images match / two exclude",
fullset: map[string]string{
"registry/repo/img1:16": "going",
"registry/repo2/img1:16": "going",
"registry/repo3/img1:18": "staying",
},
held: []string{
"registry/repo/img1:16",
"img1:16",
},
expected: map[string]string{
"registry/repo3/img1:18": "staying",
"staying1": "registry/img1:17",
"staying2": "registry/img1:18",
"staying3": "registry/img1:19",
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/chart/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ autoscaler ghcr.io/openfaasltd/autoscaler:0.2.5
return err
}

filtered := helm.FilterImagesUptoDepth(values, depth)
filtered := helm.FilterImagesUptoDepth(values, depth, 0, "")
if len(filtered) == 0 {
return fmt.Errorf("no images found in %s", file)
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/helm/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ func ReplaceValuesInHelmValuesFile(values map[string]string, yamlPath string) (s

// FilterImagesUptoDepth takes a ValuesMap and returns a map of images that
// were found upto max level
func FilterImagesUptoDepth(values ValuesMap, depth int) map[string]string {
func FilterImagesUptoDepth(values ValuesMap, depth int, level int, component string) map[string]string {
images := map[string]string{}

for k, v := range values {

if level == 1 {
component = k
}

if k == "image" && reflect.TypeOf(v).Kind() == reflect.String {
imageUrl := v.(string)
images[imageUrl] = imageUrl
images[component] = imageUrl
}

if c, ok := v.(ValuesMap); ok && depth > 0 {
images = mergeMaps(images, FilterImagesUptoDepth(c, depth-1))
images = mergeMaps(images, FilterImagesUptoDepth(c, depth-1, level+1, component))
}
}
return images
Expand Down

0 comments on commit 9d5e9bb

Please sign in to comment.