Skip to content

Commit

Permalink
Helm Template Changes (#446)
Browse files Browse the repository at this point in the history
* Update helm.go

* updates based on feedback

* add unit test
  • Loading branch information
dbw7 authored and atanasdinov committed Jun 3, 2024
1 parent a8ba33b commit 89bb656
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions pkg/registry/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"strings"

"github.com/suse-edge/edge-image-builder/pkg/http"
Expand Down Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions pkg/registry/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/testdata/sample-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: "custom.example.com/v1"
kind: ComplexApplication
kind: Deployment
metadata:
name: my-complex-app
labels:
Expand Down

0 comments on commit 89bb656

Please sign in to comment.