Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: cannot use set-context as reusable workflow #310

Open
Krikooo opened this issue Feb 28, 2024 · 1 comment
Open

Bug: cannot use set-context as reusable workflow #310

Krikooo opened this issue Feb 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Krikooo
Copy link

Krikooo commented Feb 28, 2024

What happened?

Hello folks!

I tried to the set-context as an reusable job (https://docs.github.com/en/actions/using-workflows/reusing-workflows) like this:

name: k8s_connection_to_cluster
on:
  workflow_call:
jobs:
  connection:
    name: Setup k8s client
    runs-on: self-hosted
    steps:
        - name: Setup k8s client
          uses: azure/setup-kubectl@v3
          with:
            version: v1.28.6 # default is latest stable
          id: install
        - name: Connect to k8s cluster
          uses: azure/k8s-set-context@v3
          with:
            method: kubeconfig
            kubeconfig: ${{ secrets.K8S_PROD_CONFIG }}
            context: kubernetes-admin@kubernetes # current-context from kubeconfig is used as default

And then call it in my workflow like this:


name: Deploy cronjobs on k8s
on:
  push:
    branches:
      - master
    paths:
      - 'infra/kubernetes/**'
  workflow_dispatch:

    
jobs:
    setup_kubectl:
      name: Setup client & connect to cluster
      uses: foobar/infrastructure/.github/workflows/deploy_kubernetes_connection.yaml@main
      secrets: inherit

    kubernetes:
      needs: setup_kubectl
      runs-on: self-hosted
  
      steps:
        - uses: actions/checkout@v4
        - name: Create old envfile as secret
          uses: azure/k8s-create-secret@v2
          with:
            namespace: foobar
            secret-type: 'generic'
            secret-name: envfile-old
            string-data: ${{ secrets.K8S_ENV_OLD_CRON }}
        - name: Deploy configmap yml files on k8s
          uses: Azure/k8s-deploy@v4
          with:
            namespace: 'foobar'
            manifests: |
                infra/kubernetes/configmap.*.yml
        - name: Deploy cronjob yml files on k8s
          uses: Azure/k8s-deploy@v4
          with:
            namespace: 'foobar'
            manifests: |
                infra/kubernetes/cronjob.*.yml
    clean:
      if: always()
      needs: kubernetes
      uses: foobar/infrastructure/.github/workflows/deploy_docker_clean.yaml@main```

But when the workflow had run and I get this:

Error: Error: Cluster context not set. Use k8s-set-context/aks-set-context action to set cluster context


### Version

- [X] I am using the latest version

### Runner

self-hosted

### Relevant log output

##[debug]Evaluating condition for step: 'Create old envfile as secret'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Create old envfile as secret
##[debug]Loading inputs
##[debug]Evaluating: secrets.K8S_ENV_OLD_CRON
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'K8S_ENV_OLD_CRON'
##[debug]=> '***
##[debug]'
##[debug]Result: '***
##[debug]'
##[debug]Loading env
Run azure/k8s-create-secret@v[2](https://github.com/foobar/foobar/actions/runs/8068795893/job/22068903639#step:4:2)
  with:
    namespace: foobar
    secret-type: generic
    secret-name: envfile-old
    string-data: ***
  
Error: Error: Cluster context not set. Use k[8](https://github.com/foobar/foobar/actions/runs/8068795893/job/22068903639#step:4:8)s-set-context/aks-set-context action to set cluster context
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Create old envfile as secret
@Krikooo Krikooo added the bug Something isn't working label Feb 28, 2024
@OliverMKing
Copy link
Collaborator

OliverMKing commented Mar 12, 2024

The set-context action downloads the Kubectl context to the Job. Its context only applies to the GitHub Job it runs in. You are running k8s-deploy in a separate Job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants