Skip to content

feat(deployer): authenticate to GKE via WIF and generate scoped kubeconfig#342

Merged
Syphon83 merged 9 commits into
masterfrom
wif-gke-kubeconfig
May 12, 2026
Merged

feat(deployer): authenticate to GKE via WIF and generate scoped kubeconfig#342
Syphon83 merged 9 commits into
masterfrom
wif-gke-kubeconfig

Conversation

@Syphon83

@Syphon83 Syphon83 commented May 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds GKE kubeconfig generation support to the deployer by introducing a new
portable GitLab CI template templates/functions/gke-kubeconfig.yml
(.gke-kubeconfig) that generates a namespace-scoped kubeconfig for GKE
clusters. It works with any gcloud authentication method (WIF, service account
key, etc.) and acts as an alternative to the GitLab Agent approach.

What changes

  • New template templates/functions/gke-kubeconfig.yml — self-contained,
    remotely includable, no Docker image dependency. Defines check_gcloud_auth(),
    check_gke_env() and generate_gke_kubeconfig() inline in before_script.
    Activated when K8S_CLUSTER_NAME is set.
  • check_gcloud_auth() — verifies gcloud is available and has an active
    authenticated account before attempting cluster access. Fails with a clear
    message if not authenticated.
  • Execution order.gke-kubeconfig runs as the last step in
    .global-setup, after setup-gitlab-agent, so the gcloud context always
    overrides the agent context when both are configured (safety net for users who
    forget DISABLE_GITLAB_AGENT=1).
  • templates/.gitlab-ci-template.yml — new include: entry for
    gke-kubeconfig.yml + !reference added as last step in .global-setup before_script.
  • scripts/src/functions.bash — removed legacy kubectl config set-cluster/set-credentials/set-context/use-context commands referencing the
    old gitlab-deploy context.
  • DNS endpoint supportK8S_USE_DNS_ENDPOINT=1 conditionally passes
    --dns-endpoint to gcloud container clusters get-credentials for private
    GKE clusters.
  • Namespace scoping — kubeconfig context is scoped to $KUBE_NAMESPACE via
    kubectl config set-context --current --namespace.

Variables consumed

All injected by the platform generator (board#4348):

Variable Description
K8S_CLUSTER_NAME GKE cluster name — activates the template when set
K8S_LOCATION GKE cluster location
GCP_PROJECT_ID GCP project ID
KUBE_NAMESPACE Target namespace
K8S_USE_DNS_ENDPOINT "1" to pass --dns-endpoint for private clusters

Backward compatibility

Pipelines without K8S_CLUSTER_NAME are completely unaffected — the template
emits a skip message and exits cleanly. The template is auth-method agnostic:
it works with WIF (gcp-wif.yml), a service account key, or any other gcloud
authentication configured before it runs.

Refs: sparkfabrik-innovation-team/board#4351
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
@Syphon83 Syphon83 requested a review from Monska85 May 6, 2026 09:38
@paolomainardi

Copy link
Copy Markdown
Member

/describe

Refs: sparkfabrik-innovation-team/board#4351
Assisted-by: opencode/github-copilot/claude-sonnet-4.6

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new Kubernetes authentication path for GitLab CI pipelines targeting GKE: when Workload Identity Federation (WIF) is enabled, the deployer can authenticate via gcloud and generate a namespace-defaulted kubeconfig, while preserving the legacy static-token path.

Changes:

  • Extend create_kubeconfig() / ensure_deploy_variables() to support a WIF+GKE execution branch driven by ENABLE_GCP_WIF=1 and K8S_CLUSTER_NAME.
  • Wire WIF+GKE kubeconfig generation into the shared GitLab CI before_script after GitLab Agent setup.
  • Document the new authentication mode and variables (README + changelog) and add OpenSpec workflow artifacts/commands.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
templates/.gitlab-ci-template.yml Adds a gated create_kubeconfig call in before_script for WIF+GKE pipelines.
scripts/src/functions.bash Implements WIF+GKE kubeconfig creation via gcloud get-credentials and adjusts variable validation logic.
README.md Documents legacy token auth vs WIF+GKE variables/behavior and ordering with GitLab Agent.
CHANGELOG.md Adds unreleased entries describing the new WIF+GKE kubeconfig and validation behavior.
openspec/config.yaml Adds OpenSpec configuration scaffold for spec-driven workflow.
openspec/changes/wif-gke-kubeconfig/.openspec.yaml Adds OpenSpec change metadata.
openspec/changes/wif-gke-kubeconfig/proposal.md Captures the “why/what” for WIF+GKE kubeconfig support.
openspec/changes/wif-gke-kubeconfig/design.md Captures design decisions, execution order, and risks/trade-offs.
openspec/changes/wif-gke-kubeconfig/tasks.md Tracks implementation tasks and validation checklist for the change.
openspec/changes/wif-gke-kubeconfig/specs/wif-gke-kubeconfig/spec.md Adds delta spec describing WIF+GKE kubeconfig requirements.
openspec/changes/wif-gke-kubeconfig/specs/kubeconfig-creation/spec.md Adds delta spec describing multi-path kubeconfig creation + validation requirements.
.opencode/skills/openspec-propose/SKILL.md Adds OpenSpec “propose” skill definition for OpenCode workflow.
.opencode/skills/openspec-explore/SKILL.md Adds OpenSpec “explore” skill definition for OpenCode workflow.
.opencode/skills/openspec-archive-change/SKILL.md Adds OpenSpec “archive change” skill definition for OpenCode workflow.
.opencode/skills/openspec-apply-change/SKILL.md Adds OpenSpec “apply change” skill definition for OpenCode workflow.
.opencode/command/opsx-propose.md Adds /opsx-propose command documentation for OpenCode workflow.
.opencode/command/opsx-explore.md Adds /opsx-explore command documentation for OpenCode workflow.
.opencode/command/opsx-archive.md Adds /opsx-archive command documentation for OpenCode workflow.
.opencode/command/opsx-apply.md Adds /opsx-apply command documentation for OpenCode workflow.
.github/skills/openspec-propose/SKILL.md Adds OpenSpec “propose” skill definition for GitHub workflow.
.github/skills/openspec-explore/SKILL.md Adds OpenSpec “explore” skill definition for GitHub workflow.
.github/skills/openspec-archive-change/SKILL.md Adds OpenSpec “archive change” skill definition for GitHub workflow.
.github/skills/openspec-apply-change/SKILL.md Adds OpenSpec “apply change” skill definition for GitHub workflow.
.github/prompts/opsx-propose.prompt.md Adds /opsx:propose prompt content for GitHub workflow.
.github/prompts/opsx-explore.prompt.md Adds /opsx:explore prompt content for GitHub workflow.
.github/prompts/opsx-archive.prompt.md Adds /opsx:archive prompt content for GitHub workflow.
.github/prompts/opsx-apply.prompt.md Adds /opsx:apply prompt content for GitHub workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/src/functions.bash Outdated
Comment thread templates/.gitlab-ci-template.yml Outdated
Comment thread scripts/src/functions.bash Outdated
Comment thread README.md Outdated
@paolomainardi

Copy link
Copy Markdown
Member

@copilot can you add a description of what the PR does ? update the PR description

Copilot AI commented May 6, 2026

Copy link
Copy Markdown

@copilot can you add a description of what the PR does ? update the PR description

I've updated the PR description with a full summary of the changes: what problem is being solved, what files changed and why, how activation works, the variables table, and backward compatibility notes.

Copilot AI requested a review from paolomainardi May 6, 2026 11:01
Comment thread scripts/src/functions.bash Outdated
Comment thread scripts/src/functions.bash Outdated
Comment thread scripts/src/functions.bash Outdated
Comment thread scripts/src/functions.bash Outdated
Comment thread CHANGELOG.md
@Monska85

Monska85 commented May 6, 2026

Copy link
Copy Markdown
Contributor

I would also use the approach used for the WIF bash functions: all the needed functions are defined in the YAML templates. This allow the portability of these functions simply using the templates and decoupling the bash functions from the spark-k8s-deployer docker image. A bash shell is the only requirement.

@Stevesibilia you can help with this task.

Syphon83 added 3 commits May 8, 2026 16:03
Refs: sparkfabrik-innovation-team/board#4351
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
…ate design

Refs: sparkfabrik-innovation-team/board#4351
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
Refs: sparkfabrik-innovation-team/board#4351
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
@Syphon83 Syphon83 force-pushed the wif-gke-kubeconfig branch from d4319cc to 9023559 Compare May 8, 2026 14:07
@Syphon83 Syphon83 requested a review from Monska85 May 8, 2026 14:16
@Syphon83

Syphon83 commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

I would also use the approach used for the WIF bash functions: all the needed functions are defined in the YAML templates. This allow the portability of these functions simply using the templates and decoupling the bash functions from the spark-k8s-deployer docker image. A bash shell is the only requirement.

@Stevesibilia you can help with this task.

I reverted the changes done in the bash scripts and created a new template called gke-kubeconfig.
Template should tun after gitlab agent setup in order to override it just in case.
I removed the old configuration involving gitlab-deploy.

Comment thread templates/functions/gke-kubeconfig.yml Outdated
Refs: sparkfabrik-innovation-team/board#4351
Assisted-by: opencode/github-copilot/claude-sonnet-4.6

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Comment thread scripts/src/functions.bash
Comment thread scripts/src/functions.bash
Comment thread templates/functions/gke-kubeconfig.yml Outdated
Comment thread templates/functions/gke-kubeconfig.yml
Comment thread templates/functions/gke-kubeconfig.yml
Refs: sparkfabrik-innovation-team/board#4351
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
@Syphon83 Syphon83 requested review from Monska85 and Copilot May 8, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Comment thread scripts/src/functions.bash
Comment thread scripts/src/functions.bash Outdated
Comment thread templates/functions/gke-kubeconfig.yml
Comment thread templates/functions/gke-kubeconfig.yml Outdated
Refs: #342
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
Syphon83 added a commit that referenced this pull request May 11, 2026
… name

Refs: #342
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
Comment thread scripts/src/functions.bash Outdated
Syphon83 added a commit that referenced this pull request May 11, 2026
… name

Refs: #342
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
@Syphon83 Syphon83 force-pushed the wif-gke-kubeconfig branch from 0ee8515 to c79c1ef Compare May 11, 2026 16:30
Comment thread scripts/src/functions.bash Outdated
… name

Refs: #342
Assisted-by: opencode/github-copilot/claude-sonnet-4.6
@Syphon83 Syphon83 force-pushed the wif-gke-kubeconfig branch from c79c1ef to 8d25443 Compare May 11, 2026 16:42
@Syphon83 Syphon83 merged commit b453636 into master May 12, 2026
2 checks passed
@Syphon83 Syphon83 deleted the wif-gke-kubeconfig branch May 12, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants