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

Option to rename the generated kubectl context #86

Closed
abonander opened this issue Aug 5, 2021 · 5 comments · Fixed by #159
Closed

Option to rename the generated kubectl context #86

abonander opened this issue Aug 5, 2021 · 5 comments · Fixed by #159
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@abonander
Copy link

TL;DR

We have local build-and-deploy shell scripts that I'm trying to incorporate into a Github Actions workflow, and these scripts use kubectl --context=<context name> so as to ensure the correct context is used even if the current-context is different.

However, the context name you get locally when you run gcloud container clusters get-credentials looks something like this:

gke_{project}_{region/zone}_{cluster}

Whereas this Action names the context the same as the cluster, which means having to rename the context before invoking our script:

kubectl config rename-context $GKE_CLUSTER <expected context name>
./script/deploy.sh

Design

I'd just like to be able to pass the name that should be used for the generated context:

      - uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e
        with:
          cluster_name: ${{ env.GKE_CLUSTER }}
          location: ${{ env.GKE_ZONE }}
          credentials: ${{ secrets.GKE_SA_KEY }}
          context_name: <expected context name>
@bharathkkb
Copy link
Contributor

Thanks for the FR @abonander
This is good idea, I think we could even default to gke_{project}_{location}_{cluster} to align with gcloud.

@bharathkkb bharathkkb added enhancement New feature or request good first issue Good for newcomers P3 labels Aug 5, 2021
@abonander
Copy link
Author

I was going to suggest that, though I was concerned about possibly breaking existing workflows.

@bharathkkb
Copy link
Contributor

Currently we use a random name and set KUBECONFIG, so I think we should be okay.

@abonander
Copy link
Author

Really? Cause it looks like it uses the cluster name: https://github.com/google-github-actions/get-gke-credentials/blob/main/src/gkeClient.ts#L187

@bharathkkb
Copy link
Contributor

@abonander ah yes, you are right. I was thinking about the filename. I think we can add the context_name first and evaluate defaulting later.

Considering this is pre 1.0, we could have an upgrade guide showing how to get that behavior. /cc @averikitsch any thoughts?

with:
  cluster_name: ${{ env.GKE_CLUSTER }}
  location: ${{ env.GKE_ZONE }}
  credentials: ${{ secrets.GKE_SA_KEY }}
+  context_name: ${{ env.GKE_CLUSTER }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
2 participants