From 045f363b0e67928386724e7a54e7d746daf2a68d Mon Sep 17 00:00:00 2001 From: Alex Buchanan Date: Fri, 11 Oct 2024 13:39:38 -0700 Subject: [PATCH] change the image set data structure --- internal/cmd/images/manifest_cmd.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/internal/cmd/images/manifest_cmd.go b/internal/cmd/images/manifest_cmd.go index 16a04ef..e257b68 100644 --- a/internal/cmd/images/manifest_cmd.go +++ b/internal/cmd/images/manifest_cmd.go @@ -84,7 +84,7 @@ func findImagesFromChart(client helm.Client, valuesYaml, chartName, chartVersion // It returns a unique, sorted list of images found. func findAllImages(chartYaml string) []string { objs := decodeK8sResources(chartYaml) - imageSet := map[string]bool{} + imageSet := set[string]{} for _, obj := range objs { @@ -94,7 +94,7 @@ func findAllImages(chartYaml string) []string { if strings.HasSuffix(z.Name, "airbyte-env") { for k, v := range z.Data { if strings.HasSuffix(k, "_IMAGE") { - imageSet[v] = true + imageSet.add(v) } } } @@ -112,15 +112,15 @@ func findAllImages(chartYaml string) []string { } for _, c := range podSpec.InitContainers { - imageSet[c.Image] = true + imageSet.add(c.Image) } for _, c := range podSpec.Containers { - imageSet[c.Image] = true + imageSet.add(c.Image) } } var out []string - for k := range imageSet { + for _, k := range imageSet.items() { if k != "" { out = append(out, k) } @@ -145,3 +145,22 @@ func decodeK8sResources(renderedYaml string) []runtime.Object { } return out } + +type set[T comparable] struct { + vals map[T]struct{} +} + +func (s *set[T]) add(v T) { + if s.vals == nil { + s.vals = map[T]struct{}{} + } + s.vals[v] = struct{}{} +} + +func (s *set[T]) items() []T { + out := make([]T, len(s.vals)) + for k := range s.vals { + out = append(out, k) + } + return out +} \ No newline at end of file