Skip to content

Commit

Permalink
refactor: extract getContainerNestedKeys
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Donizetti <jdbjunior@gmail.com>
  • Loading branch information
josedonizetti committed May 30, 2022
1 parent cc8c12a commit 9b6f12a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pkg/artifacts/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"}
}
}

0 comments on commit 9b6f12a

Please sign in to comment.