Skip to content

Fix/gke kubeconfig posix deploy variables#343

Merged
Syphon83 merged 2 commits into
masterfrom
fix/gke-kubeconfig-posix-deploy-variables
May 12, 2026
Merged

Fix/gke kubeconfig posix deploy variables#343
Syphon83 merged 2 commits into
masterfrom
fix/gke-kubeconfig-posix-deploy-variables

Conversation

@Syphon83

@Syphon83 Syphon83 commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes two bugs introduced by the gke-kubeconfig template added in #342.

Fix shell syntax error in non-bash images (gke-kubeconfig)

The generate_gke_kubeconfig() function used bash-specific array syntax
(local cmd=(...), cmd+=(...), "${cmd[@]}") which caused a shell parse
error when the function block was evaluated in images running /bin/sh
(e.g. the secret_detection scanner image registry.gitlab.com/security-products/secrets:7).
Because the global before_script in .gitlab-ci-template.yml injects
.gke-kubeconfig into every job, any job running in a non-bash image
would fail at parse time with:
syntax error: unexpected "(" (expecting "}")
The fix replaces the array-based command construction with a plain
POSIX-compatible variable flag approach.

Fix silent no-op in ensure_deploy_variables

ensure_deploy_variables() had a conditional guard that skipped all
validation when every required variable was unset. This meant calling the
function with no variables configured was a silent no-op, allowing
create_kubeconfig() to proceed with empty KUBE_URL and KUBE_TOKEN
and silently produce a broken kubeconfig.
The fix removes the outer if guard so the function unconditionally
validates all five required variables (KUBE_NAMESPACE, KUBE_URL,
KUBE_TOKEN, CI_ENVIRONMENT_SLUG, CI_ENVIRONMENT_URL) whenever it
is called.

Testing

  • The secret_detection job (and any other job running in a non-bash
    image) no longer fails with a shell syntax error due to the inherited
    before_script.
  • Calling ensure_deploy_variables with missing variables now always
    exits with an explicit error message instead of silently passing.

Syphon83 added 2 commits May 12, 2026 15:39
Assisted-by: opencode/github-copilot/claude-opus-4.6
Assisted-by: opencode/github-copilot/claude-opus-4.6
Copilot AI review requested due to automatic review settings May 12, 2026 15:27

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 adjusts the deployer’s GKE kubeconfig generation and legacy deploy-variable validation to behave more consistently across shell environments and CI variable setups.

Changes:

  • Refactors .gke-kubeconfig’s gcloud container clusters get-credentials invocation to avoid using a Bash array and conditionally add --dns-endpoint.
  • Makes ensure_deploy_variables() always validate the legacy variable set instead of validating only when at least one legacy variable is already present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
templates/functions/gke-kubeconfig.yml Reworks conditional --dns-endpoint handling without a command array.
scripts/src/functions.bash Makes legacy deploy-variable validation unconditional.

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

Comment thread templates/functions/gke-kubeconfig.yml

@Monska85 Monska85 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.

LGTM 👍

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 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines 66 to 70
generate_gke_kubeconfig() {
local gcloud_cmd=(
gcloud container clusters get-credentials "${K8S_CLUSTER_NAME}"
--location "${K8S_LOCATION}"
--project "${GCP_PROJECT_ID}"
)

local dns_flag=""
if [ "${K8S_USE_DNS_ENDPOINT:-0}" = "1" ]; then
gcloud_cmd+=(--dns-endpoint)
dns_flag="--dns-endpoint"
fi
@Syphon83 Syphon83 merged commit bb97550 into master May 12, 2026
10 checks passed
@Syphon83 Syphon83 deleted the fix/gke-kubeconfig-posix-deploy-variables branch May 12, 2026 15:36
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.

3 participants