hey I'm using the kubernetes module in Garden aco...
# 🤖|ask-kapa
m
Please stand by @bright-policeman-43626 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
---------------------- You can replace a value from a manifest with the output of the Docker image built by using the
patchResources
field in your Garden configuration. This allows you to overwrite any field in your manifests without modifying the underlying manifest. Here's an example of how you can do this:
Copy code
yaml
kind: Build
type: container
name: api
---
kind: Deploy
type: kubernetes
name: api
dependencies: [build.api]
spec:
 files: [my-manifests.yml]
 patchResources:
 - name: api # <--- The name of the resource to patch, should match the name in the K8s manifest
 kind: Deployment # <--- The kind of the resource to patch
 patch:
 spec:
 template:
 spec:
 containers:
 - name: api # <--- Should match the container name from the K8s manifest
 image: ${actions.build.api.outputs.deployment-image-id} # <--- The output from the Build action above
In this example, the
patchResources
field is used to overwrite the
image
field in the corresponding manifest with the output from the Build action. This ensures that the correct version of the image is deployed. You can find more information about this approach in the Garden documentation (). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
Let me check the knowledge base for you. One moment! :books:
b
@microscopic-river-74022 this is the manifest I wanna change:
Copy code
apiVersion: batch/v1
kind: CronJob
metadata:
  name: ci-cleanup-job
  namespace: ci-cleaner
spec:
  schedule: "* * * * *" # This schedule is just an example; adjust according to your needs
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: ci-cleaner-sa
          containers:
          - name: ci-cleaner-job
            image: gcr.io/ci-ns-cleaner:master
            command:
            - /bin/bash
            - -c
          restartPolicy: OnFailure
Specifically under containers.ci-cleaner-job.image
m
---------------------- You can replace the
image
field in your Kubernetes manifest using Garden template strings. Here's how you can do it:
Copy code
yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: ci-cleanup-job
  namespace: ci-cleaner
spec:
  schedule: "* * * * *" # This schedule is just an example; adjust according to your needs
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: ci-cleaner-sa
          containers:
          - name: ci-cleaner-job
            image: ${actions.build.api.outputs.deployment-image-id} # <--- Garden will resolve this to the correct image before applying the manifest
            command:
            - /bin/bash
            - -c
          restartPolicy: OnFailure
In this example,
${actions.build.api.outputs.deployment-image-id}
is a Garden template string that will be resolved to the correct image before applying the manifest. You would replace
api
with the name of your build action. You can find more information about this approach in the Garden documentation (). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
b
@microscopic-river-74022 I'm using garden 0.12 so actions don't exist
m
Let me check the knowledge base for you. One moment! :books:
---------------------- I see, you're using Garden Acorn (0.12) which doesn't support actions as they were introduced in Garden Bonsai (0.13). In Garden Acorn, you would use modules to define your services, tests, and tasks. To replace a value in a Kubernetes manifest with the ID of a built Docker image, you can use the
modules
field in your Garden configuration. Here's an example:
Copy code
yaml
kind: Module
type: container
name: ci-cleaner-job
dockerfile: Dockerfile
---
kind: Module
type: kubernetes
name: ci-cleanup-job
include: [ci-cleanup-job.yaml]
services:
- name: ci-cleanup-job
  dependencies: [ci-cleaner-job]
  manifests:
  - apiVersion: batch/v1
    kind: CronJob
    metadata:
      name: ci-cleanup-job
      namespace: ci-cleaner
    spec:
      schedule: "* * * * *"
      jobTemplate:
        spec:
          template:
            spec:
              serviceAccountName: ci-cleaner-sa
              containers:
              - name: ci-cleaner-job
                image: ${modules.ci-cleaner-job.outputs.deployment-image-id}
                command:
                - /bin/bash
                - -c
              restartPolicy: OnFailure
In this example,
${modules.ci-cleaner-job.outputs.deployment-image-id}
is a Garden template string that will be resolved to the correct image before applying the manifest. Please note that you might need to adjust the
dockerfile
and
include
paths according to your project structure. For more information on how to use modules in Garden Acorn, you can refer to the Garden 0.12 documentation (). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
2 Views