Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release 1.0] Only extract container images from specific Kubernetes objects when parsing Helm charts #461

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

## Bug Fixes

* [#442](https://github.com/suse-edge/edge-image-builder/issues/442) - Only get images from specific Kubernetes objects
* [#429](https://github.com/suse-edge/edge-image-builder/issues/429) - Automatically set execute bit on scripts

---
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
Loading