From 89bb656f6ec0e0203d920226cbfb09cc27f15e53 Mon Sep 17 00:00:00 2001 From: dbw7 Date: Mon, 20 May 2024 13:51:31 -0400 Subject: [PATCH] Helm Template Changes (#446) * Update helm.go * updates based on feedback * add unit test --- RELEASE_NOTES.md | 2 ++ pkg/registry/manifests.go | 16 ++++++++++++++++ pkg/registry/manifests_test.go | 23 +++++++++++++++++++++++ pkg/registry/testdata/sample-crd.yaml | 2 +- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 187e1677..a575a5ef 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -12,6 +12,8 @@ ## Bug Fixes +* [#442](https://github.com/suse-edge/edge-image-builder/issues/442) - Only get images from specific Kubernetes objects + --- # v1.0.1 diff --git a/pkg/registry/manifests.go b/pkg/registry/manifests.go index a0a833fb..63826a8b 100644 --- a/pkg/registry/manifests.go +++ b/pkg/registry/manifests.go @@ -7,6 +7,7 @@ import ( "io" "os" "path/filepath" + "slices" "strings" "github.com/suse-edge/edge-image-builder/pkg/http" @@ -85,6 +86,21 @@ func readManifest(manifestPath string) ([]map[string]any, error) { } func storeManifestImages(resource map[string]any, images map[string]bool) { + var k8sKinds = []string{ + "Pod", + "Deployment", + "StatefulSet", + "DaemonSet", + "ReplicaSet", + "Job", + "CronJob", + } + + kind, _ := resource["kind"].(string) + if !slices.Contains(k8sKinds, kind) { + return + } + var findImages func(data any) findImages = func(data any) { diff --git a/pkg/registry/manifests_test.go b/pkg/registry/manifests_test.go index b7629d26..daefc062 100644 --- a/pkg/registry/manifests_test.go +++ b/pkg/registry/manifests_test.go @@ -92,6 +92,29 @@ func TestStoreManifestImages(t *testing.T) { assert.ElementsMatch(t, expectedImages, allImages) } +func TestStoreManifestImages_InvalidKinds(t *testing.T) { + // Setup + var extractedImagesSet = make(map[string]bool) + manifestData := map[string]any{ + "apiVersion": "apps/v1", + "kind": "InvalidKind", + "spec": map[string]any{ + "containers": []any{ + map[string]any{ + "name": "nginx", + "image": "nginx:1.14.2", + }, + }, + }, + } + + // Test + storeManifestImages(manifestData, extractedImagesSet) + + // Verify + assert.Equal(t, map[string]bool{}, extractedImagesSet) +} + func TestStoreManifestImages_EmptyManifest(t *testing.T) { // Setup var extractedImagesSet = make(map[string]bool) diff --git a/pkg/registry/testdata/sample-crd.yaml b/pkg/registry/testdata/sample-crd.yaml index 710b7425..8864e9a6 100644 --- a/pkg/registry/testdata/sample-crd.yaml +++ b/pkg/registry/testdata/sample-crd.yaml @@ -1,5 +1,5 @@ apiVersion: "custom.example.com/v1" -kind: ComplexApplication +kind: Deployment metadata: name: my-complex-app labels: