diff --git a/.images.yaml b/.images.yaml new file mode 100755 index 0000000..50cf5b3 --- /dev/null +++ b/.images.yaml @@ -0,0 +1,9 @@ +target: + host: myregistry.nu +sources: +- repository: some/image + host: otherhost.com + tag: v1.0.0 +- repository: other/jobimage + host: yetanotherhost.com + tag: "234" diff --git a/internal/manifest/kubernetes.go b/internal/manifest/kubernetes.go index c794207..cfad863 100644 --- a/internal/manifest/kubernetes.go +++ b/internal/manifest/kubernetes.go @@ -13,6 +13,7 @@ import ( promv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1" kubeyaml "github.com/ghodss/yaml" + batchv1beta1 "k8s.io/api/batch/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -149,6 +150,15 @@ func getImagesFromResource(resource string) ([]string, error) { return podImages, nil } + if typeMeta.Kind == "CronJob" { + cronJobImages, err := getCronJobImages(byteResource) + if err != nil { + return nil, fmt.Errorf("get cronjob images: %w", err) + } + + return cronJobImages, nil + } + type BaseSpec struct { Template corev1.PodTemplateSpec `json:"template" protobuf:"bytes,3,opt,name=template"` } @@ -224,6 +234,19 @@ func getPodImages(resource []byte) ([]string, error) { return images, nil } +func getCronJobImages(resource []byte) ([]string, error) { + var cj batchv1beta1.CronJob + if err := kubeyaml.Unmarshal(resource, &cj); err != nil { + return nil, fmt.Errorf("unmarshal cronjob: %w", err) + } + + var images []string + images = append(images, getImagesFromContainers(cj.Spec.JobTemplate.Spec.Template.Spec.Containers)...) + images = append(images, getImagesFromContainers(cj.Spec.JobTemplate.Spec.Template.Spec.InitContainers)...) + + return images, nil +} + func getImagesFromContainers(containers []corev1.Container) []string { var images []string diff --git a/test/create/bundle.yaml b/test/create/bundle.yaml index 7d70ff5..d300029 100644 --- a/test/create/bundle.yaml +++ b/test/create/bundle.yaml @@ -5,4 +5,21 @@ metadata: spec: containers: - image: otherhost.com/some/image:v1.0.0 - name: test-create \ No newline at end of file + name: test-create +--- +apiVersion: batch/v1beta1 +kind: CronJob +metadata: + name: test-cronjob +spec: + schedule: '*/1 * * * *' + jobTemplate: + metadata: + name: test-job + spec: + template: + spec: + containers: + - image: yetanotherhost.com/other/jobimage:234 + name: test-job + restartPolicy: OnFailure diff --git a/test/create/expected-images.yaml b/test/create/expected-images.yaml index b50f07c..4b44969 100644 --- a/test/create/expected-images.yaml +++ b/test/create/expected-images.yaml @@ -4,3 +4,6 @@ sources: - repository: some/image host: otherhost.com tag: v1.0.0 +- repository: other/jobimage + host: yetanotherhost.com + tag: "234"