Deploy CronJob Manifest Issue : Unable to bind docker image to Cronjob
Issue Summary:
Cannot bind docker image artifact as part of CronJob through Spinnaker UI. It does not replace the specific image tag specified in the configuration.
Exception ( Monitor Deploy ) The following required artifacts could not be bound: '[ArtifactKey(type=docker/image, name=gcr.io/myproject/abc-job, version=, location=null, reference=gcr.io/myproject/abc-job)]'. Check that the Docker image name above matches the name used in the image field of your manifest. Failing the stage as this is likely a configuration error.
Cloud Provider(s):
Google Cloud - Google Kubernetes Engine
Environment:
GKE - I am running Spinnaker using the images in google container registry to deploy to GKE. Spinnaker version - 1.22.2
Feature Area:
spinnaker/clouddriver
Description:
While deploying CronJob through Spinnaker (using the - following recommended halyard option)
name: my-k8s-v2-acccount
customResources:
- kubernetesKind: cronJob
I am unable to bind a docker image to the cronjob - my cronjob manifest looks like the following -
apiVersion: batch/v1beta1
kind: CronJob
metadata:
namespace: dev
name: abc-job
spec:
schedule: "0 */8 * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
metadata:
name: abc-job
namespace: dev
spec:
containers:
- name: abc-job-container
image: gcr.io/myproject/abc-job
volumeMounts:
- name: config-volume
mountPath: /config
readOnly: true
volumes:
- name: config-volume
configMap:
name: abc-job
items:
- key: application.yaml
path: application.yaml
restartPolicy: Never
When I dug through this code - https://github.com/spinnaker/clouddriver/pull/2691/files - I noticed that in the dockerImageReplacerMethod() -
.replacePath("$..spec.template.spec.containers.[?( @.image == \"{%name%}\" )].image") .findPath("$..spec.template.spec.containers.*.image" )
The above code will probably not replace the docker image because the path is .spec.jobTemplate and not .spec.template as per the manifest file as the per apiVersion: batch/v1beta1.
Hence to get the image bounded correctly from Spinnaker UI, don't you think the above change is necessary?
Steps to Reproduce:

Additional Details:
This is a trigger based spinnaker pipeline which looks for tag being passed to spinnaker when a new build happens a new docker image is generated in the GCR. In the logs
Thanks for opening this issue! It does indeed look like we're not accounting for the fact that CronJob stores its template in spec.jobTemplate as you noticed.
It probably makes sense to add a new Replacer that replaces docker images in cron jobs, and use that in CronJobHandler. There's a great example of adding new handlers in #5037.
@sgrmgj777 : Is this a change you'd be interested in making?
Either way I'll add the beginner-friendly label as (particularly given the great example I linked above) this would be a great first contribution for someone.
I can definitely attempt to make the change @ezimanyi - however it would really nice if you could share how I can become a contributor - i mean are there any specific steps I need to take.
@sgrmgj777 : There is a contributing guide with some info on how to contribute. We don't require you to sign a Contributor License Agreement to accept contributions; you can just directly open a pull request with your contribution.
Of course I'm happy to help with any specific questions as you work on this!
@ezimanyi this pr should fix the issue https://github.com/spinnaker/clouddriver/pull/5554
We're facing the same issue now after we upgraded from Spinnaker 1.26.6 to 1.28.1.
We have a pipeline that produces two docker image artifacts, which are later bound to the job template of a CronJob. One of the image artifacts belongs to an initContainer and this started failing with the same error as in the issue summary now. It used to work without any problems until now. Was support for init containers somehow removed?
We're facing the same issue now after we upgraded from Spinnaker 1.26.6 to 1.28.1.
We have a pipeline that produces two docker image artifacts, which are later bound to the job template of a
CronJob. One of the image artifacts belongs to aninitContainerand this started failing with the same error as in the issue summary now. It used to work without any problems until now. Was support for init containers somehow removed?
@martinohmann I suspect https://github.com/spinnaker/clouddriver/pull/5876 fixes your issue.