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

Write and symlink kubeconfig on change of target #86

Merged
merged 20 commits into from
Feb 16, 2022
Merged

Conversation

holgerkoser
Copy link
Member

@holgerkoser holgerkoser commented Feb 1, 2022

What this PR does / why we need it:
With this PR it is possible to change the target cluster of kubectl directly with the gardenctl target ... command without having to adjust the KUBECONFIG environment variable again and again. Whether the current target cluster of gardenctl and kubectl should be synchronized or not can be set using the configrations property link-kubeconfig or via environment variable GCTL_LINK_KUBECONFIG.

Behavior without symlink | linkKubeconfig: false

The target command only changes the current target cluster of gardenctl, but does not download the corresponding kubeconfig file. This happens only when the kubectl-env command is executed. If the user evals the generated script the KUBECONFIG environment variable points the downloaded kubeconfig file for the targeted cluster.
Link-Kubeconfig-2
The generated script looks something like this:

export KUBECONFIG=$TMPDIR/garden/<gctl-session-id>/kubeconfig.<hash>.yaml

Behavior with symlink | linkKubeconfig: true

The target command changes the current target cluster of gardenctl, downloads the corresponding kubeconfig file and creates a stable symlink to the current kubeconfig file in the session directory. If the target is changed the symlink points to the new target but the KUBECONFIG environment variable does not need to be changed. The kubectl-env command now does nothing except create the script to set the KUBECONFIG environment variable. This works even if nothing is targeted and could be done in the shell profile.
Link-Kubeconfig-1
The generated script only needs to be evaluated once per shell session and looks something like this:

export KUBECONFIG=$TMPDIR/garden/<gctl-session-id>/kubeconfig.yaml

Test

Test are not yet changed !!!

Which issue(s) this PR fixes:
Fixes #81

Special notes for your reviewer:

Release note:

@holgerkoser holgerkoser requested a review from a team as a code owner February 1, 2022 07:39
@gardener-robot gardener-robot added the needs/review Needs review label Feb 1, 2022
@holgerkoser holgerkoser marked this pull request as draft February 1, 2022 07:39
@gardener-robot gardener-robot added the size/s Size of pull request is small (see gardener-robot robot/bots/size.py) label Feb 1, 2022
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Feb 1, 2022
@holgerkoser holgerkoser changed the title Write and symlink kubeconfig on change of target !!!Do not merge!!! - Write and symlink kubeconfig on change of target Feb 1, 2022
@gardener-robot-ci-2 gardener-robot-ci-2 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Feb 1, 2022
@petersutter petersutter added the reviewed/do-not-merge Has no approval for merging as it may break things, be of poor quality or have (ext.) dependencies label Feb 1, 2022
@RaphaelVogel
Copy link
Member

nice, waiting to get this feature 👍

@gardener-robot gardener-robot added size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) and removed size/s Size of pull request is small (see gardener-robot robot/bots/size.py) labels Feb 14, 2022
@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Feb 14, 2022
@holgerkoser holgerkoser changed the title !!!Do not merge!!! - Write and symlink kubeconfig on change of target Write and symlink kubeconfig on change of target Feb 14, 2022
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Feb 14, 2022
@gardener-robot-ci-1 gardener-robot-ci-1 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Feb 14, 2022
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Feb 14, 2022
@gardener-robot gardener-robot added size/l Size of pull request is large (see gardener-robot robot/bots/size.py) needs/second-opinion Needs second review by someone else and removed size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) labels Feb 15, 2022
@gardener-robot-ci-2 gardener-robot-ci-2 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Feb 15, 2022
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Feb 15, 2022
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Feb 15, 2022
@gardener-robot-ci-2 gardener-robot-ci-2 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Feb 16, 2022
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Feb 16, 2022
@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Feb 16, 2022
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Feb 16, 2022
Copy link
Member

@petersutter petersutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging and removed needs/review Needs review needs/second-opinion Needs second review by someone else labels Feb 16, 2022
@holgerkoser holgerkoser merged commit 56f69fc into master Feb 16, 2022
@holgerkoser holgerkoser deleted the enh/symlink branch February 16, 2022 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) reviewed/lgtm Has approval for merging size/l Size of pull request is large (see gardener-robot robot/bots/size.py)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Link KUBECONFIG to the gardenctl target cluster
7 participants