Azure / k8s-deploy

GitHub Action for deploying to Kubernetes clusters
MIT License
252 stars 103 forks source link

Bug: Deployment.yaml fails with ghcr.io #284

Closed christopheriainhansen closed 1 year ago

christopheriainhansen commented 1 year ago

What happened?

When running a job using Azure/k8s-deploy action:

 deploy:
    name: Deploy to kubernetes
    runs-on: ubuntu-latest
    needs: docker
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup kubectl
        uses: Azure/setup-kubectl@v3

      - name: Setup cluster context
        uses: Azure/k8s-set-context@v3
        with:
          method: kubeconfig
          kubeconfig: ${{ secrets.K8_DEPLOY_KUBECONFIG }}

      - name: Deploy to Azure
        uses: Azure/k8s-deploy@v4
        with:
          manifests: |
            manifests/test/deployment.yml
            manifests/test/service.yml
            manifests/test/ingress.yml
          images: |
            ghcr.io/${{ env.image_name }}:${{ needs.release-on-push.outputs.version }}
          pull-images: false
          annotate-namespace: false

and my deployment.yml file looks like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: localizer
  labels:
    app: localizer
    domain: frontend
spec:
  revisionHistoryLimit: 2
  replicas: 2
  selector:
    matchLabels:
      app: localizer
  strategy:
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  template:
    metadata:
      labels:
        app: localizer
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers:
        - name: localizer
          image: ghcr.io/akusasdesign/localizer
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 250m
              memory: 256Mi
          ports:
            - name: http-in
              containerPort: 8080
          env:
            - name: NODE_ENV
              value: "test"
          imagePullPolicy: Always
          livenessProbe:
            httpGet:
              port: http-in
              path: /ping
            failureThreshold: 3
            periodSeconds: 30
          startupProbe:
            httpGet:
              port: http-in
              path: /ping
            failureThreshold: 12
            periodSeconds: 10
      imagePullSecrets:
        - name: github-container-registry

I've used this exercise as a guidance. When using the image in the exercise (mcr.microsoft.com/mslearn/samples/contoso-website), then everything seems to "run" fine, but when changing out the image with ghcr.io/****, then I recieve an error for parsing the YAML file. error: error parsing /tmp/deployment.yml: error converting YAML to JSON: yaml: line 27: mapping values are not allowed in this context

This causes the action to fail.

Version

Runner

ubuntu-latest

Relevant log output

##[debug]Evaluating condition for step: 'Deploy to Azure'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Deploy to Azure
##[debug]Loading inputs
##[debug]Evaluating: format('ghcr.io/{0}:{[1](https://github.com/AkusasDesign/localizer/actions/runs/4846714703/jobs/8642572870#step:5:1)}
##[debug]', env.image_name, needs.release-on-push.outputs.version)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> 'ghcr.io/{0}:{1}
##[debug]'
##[debug]..Evaluating Index:
##[debug]....Evaluating env:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'image_name'
##[debug]..=> '***/localizer'
##[debug]..Evaluating Index:
##[debug]....Evaluating Index:
##[debug]......Evaluating Index:
##[debug]........Evaluating needs:
##[debug]........=> Object
##[debug]........Evaluating String:
##[debug]........=> 'release-on-push'
##[debug]......=> null
##[debug]....=> null
##[debug]..=> null
##[debug]=> 'ghcr.io/***/localizer:
##[debug]'
##[debug]Result: 'ghcr.io/***/localizer:
##[debug]'
##[debug]Evaluating: github.token
##[debug]Evaluating Index:
##[debug]..Evaluating github:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'token'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Loading env
Run Azure/k8s-deploy@v4
##[debug]Input manifest files: /tmp/deployment.yml,/tmp/service.yml,/tmp/ingress.yml
::group::Deploying manifests
Deploying manifests
  ##[debug]Kubectl run with command: /opt/hostedtoolcache/kubectl/1.[2](https://github.com/AkusasDesign/localizer/actions/runs/4846714703/jobs/8642572870#step:5:2)7.1/x6[4](https://github.com/AkusasDesign/localizer/actions/runs/4846714703/jobs/8642572870#step:5:4)/kubectl apply,-f,/tmp/deployment.yml,/tmp/service.yml,/tmp/ingress.yml,--namespace,default
  /opt/hostedtoolcache/kubectl/1.27.1/x[6](https://github.com/AkusasDesign/localizer/actions/runs/4846714703/jobs/8642572870#step:5:6)4/kubectl apply -f /tmp/deployment.yml,/tmp/service.yml,/tmp/ingress.yml --namespace default
  service/localizer unchanged
  ingress.networking.k8s.io/localizer unchanged
  error: error parsing /tmp/deployment.yml: error converting YAML to JSON: yaml: line 2[7](https://github.com/AkusasDesign/localizer/actions/runs/4846714703/jobs/8642572870#step:5:7): mapping values are not allowed in this context
  ##[debug]Kubectl apply failed:Error: The process '/opt/hostedtoolcache/kubectl/1.[27](https://github.com/AkusasDesign/localizer/actions/runs/4846714703/jobs/8642572870#step:5:27).1/x64/kubectl' failed with exit code 1
  Error: Error: undefined
  ##[debug]Node Action run completed with exit code 1
  ##[debug]Finishing: Deploy to Azure
christopheriainhansen commented 1 year ago

The problem was due to the version tag being empty