From 9b6f12ab47a6fe012ef82fdd8033aaea8ce7f138 Mon Sep 17 00:00:00 2001 From: Jose Donizetti Date: Fri, 20 May 2022 15:11:44 -0300 Subject: [PATCH] refactor: extract getContainerNestedKeys Signed-off-by: Jose Donizetti --- pkg/artifacts/artifacts.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg/artifacts/artifacts.go b/pkg/artifacts/artifacts.go index dbb0236..f01d83e 100644 --- a/pkg/artifacts/artifacts.go +++ b/pkg/artifacts/artifacts.go @@ -17,16 +17,7 @@ type Artifact struct { // FromResource is a factory method to create an Artifact from an unstructured.Unstructured func FromResource(resource unstructured.Unstructured) (*Artifact, error) { - var nestedKeys []string - - switch resource.GetKind() { - case k8s.KindPod: - nestedKeys = []string{"spec"} - case k8s.KindCronJob: - nestedKeys = []string{"spec", "jobTemplate", "spec", "template", "spec"} - default: - nestedKeys = []string{"spec", "template", "spec"} - } + nestedKeys := getContainerNestedKeys(resource.GetKind()) images := make([]string, 0) @@ -87,3 +78,14 @@ func extractImages(resource unstructured.Unstructured, keys []string) ([]string, return images, nil } + +func getContainerNestedKeys(kind string) []string { + switch kind { + case k8s.KindPod: + return []string{"spec"} + case k8s.KindCronJob: + return []string{"spec", "jobTemplate", "spec", "template", "spec"} + default: + return []string{"spec", "template", "spec"} + } +}