Skip to content

fix(deploy): stabilise Azure/GCP install — cert keys, node image, namespace order, migrations - #254

Open
sho6000 wants to merge 10 commits into
Sunbird-Spark:v1.1.3from
sho6000:v1.1.2-dep-fixes
Open

sho6000 wants to merge 10 commits into
Sunbird-Spark:v1.1.3from
sho6000:v1.1.2-dep-fixes

Conversation

@sho6000

@sho6000 sho6000 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Four independent fixes, all found and confirmed by reproducing real failures from the ey-installer GitHub Actions deployment history (18 failed runs reviewed):

  1. Certificate key path bug (install.sh for both Azure/GCP) — hardcoded relative path replaced with an absolute $ENV_DIR, fixing genrsa: Can't open "../opentofu/azure/eysandbox/certkey.pem"....
  2. Node base image EOL (upload-files/main.tf) — node:18.20.8-bullseye → bookworm; bullseye's apt repos 404.
  3. certificate_config() broke on DHI-hardened images — removed dead jq-install-in-container logic, moved public-key registration into a self-contained Helm hook Job in the registry chart.
  4. ai-pipeline namespace ordering bug — pre-create the namespace before workload-identity runs, fixing namespaces "ai-pipeline" not found.
  5. Broken wait command + duplicate backoffLimit in the YugabyteDB migration Job (ysql.yaml) — fixed stray quotes/missing sleep, removed the duplicate key.

Touches: OpenTofu modules (Azure + GCP), Helm charts (learnbb)
Providers affected: Azure, GCP

Why

Multiple real deployments against ey-installer's self-hosted CI runner failed on these exact errors — fixing them here so they don't recur anywhere else using this installer.

How this was verified

  • Static checks only — bash -n on shell changes, structural YAML parse on the Helm changes
  • Not yet deployed to a live cluster

@sho6000 sho6000 changed the title V1.1.2 dep fixes fix(bugs): deployment fix from ey-demo Nov 17, 2026
@sho6000
sho6000 changed the base branch from main to v1.1.2 November 17, 2026 11:50
@divyagovindaiah

divyagovindaiah commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Review

✅ Certificate key path fix (ENV_DIR): looks good

Checked against both deployment paths. In both, install.sh is started from the env folder, so ENV_DIR is correct:

Flow How install.sh is started ENV_DIR
Private repo (GitHub Actions) cd $ENV_FOLDER && bash install.sh ... (ENV_FOLDER=sunbird-spark-installer/opentofu/azure/<env>) env folder ✅
Repo cloned on the VM cd opentofu/azure/<env> && ./install.sh ... env folder ✅

certkey.pem, certpubkey.pem and the keys in global-values.yaml are written to the same place as before. The old ../opentofu/azure/$environment/ path only resolved correctly after install_component had moved into helmcharts/. The private repo workflow's "Commit certificate keys after learnbb" step, which runs cd $ENV_FOLDER && bash install.sh certificate_keys and then copies $ENV_FOLDER/*.pem, keeps working, and this fixes its Can't open ../opentofu/azure/<env>/certkey.pem error.

Minor: install_component still checks [[ -f "certkey.pem" ]] relative to helmcharts/, where the file never exists, so certificate_keys is always called. It's harmless because certificate_keys skips itself when the keys are already present, but for consistency it should be "$ENV_DIR/certkey.pem".

❌ Changes requested

1. Removing certificate_config breaks the private repo workflow.
sunbird-spark-platform.yaml (step 8 certificate_config) still runs bash install.sh certificate_config, and so does private-repo-setup/README.md. With the function and its case entry commented out, the call falls through to invoke_functions, which fails with "command not found". Please keep a stub, for example:

function certificate_config() {
    echo "certificate_config: public key registration now runs as the registry Helm hook (publickey-config-job) — nothing to do"
}

2. publickey-config-job.yaml: .Values.publickeyConfig.image will probably fail to render.
publickeyConfig isn't defined in the registry chart's values.yaml. Helm errors with nil pointer evaluating interface {}.image when the parent key is missing, so the learnbb install would fail. Please add publickeyConfig.image to the values, or use (.Values.publickeyConfig | default dict).image. Please also pin the image tag instead of curlimages/curl:latest, and add it to images.yaml.

3. The public key reaches registry in a different format than before.
CERTIFICATE_PUBLIC_KEY is stored in global-values.yaml as "-----BEGIN PUBLIC KEY-----\nMIIB...\n-----END PUBLIC KEY-----\n", so Helm reads it with real newlines. In value: "{{ .Values.global.CERTIFICATE_PUBLIC_KEY }}" the rendered string spans several lines, and when Kubernetes parses the YAML it turns those line breaks into spaces. Checked with a parser:

Registry receives
Old certificate_config -----BEGIN PUBLIC KEY-----⏎MIIB...⏎-----END PUBLIC KEY-----
This PR -----BEGIN PUBLIC KEY----- MIIB... -----END PUBLIC KEY-----

Fix: use the \\n-escaped copy of the same key, in single quotes, so the env var keeps the literal \n and the JSON payload matches the old one exactly:

env:
  - name: CERTIFICATE_PUBLIC_KEY
    value: '{{ .Values.global.CERTIFICATESIGN_PUBLIC_KEY }}'

4. The hook can report success without registering the key.
The Job runs right after install with no wait for registry-service. If registry isn't ready, the search returns empty, the POST fails, and curl without -f still exits 0, so the Job succeeds and nothing is registered. Please add a wait-until-ready loop and use curl -f, so a failure is visible.

5. ysql.yaml backoffLimit.
The Job has backoffLimit: 0 under spec and backoffLimit: 30 at the end. Removing the 30 leaves the migration Job with 0 retries. If 30 was what applied before, that's a behaviour change. Should we keep 30 and drop the 0 instead?

Since items 2–4 only show up on a real learnbb install, please do one test deploy before merging. If the path fix is needed quickly, it's safe to split it into its own PR.

@divyagovindaiah divyagovindaiah changed the title fix(bugs): deployment fix from ey-demo fix(deploy): stabilise Azure/GCP install — cert keys, node image, namespace order, migrations Nov 20, 2026

@divyagovindaiah divyagovindaiah left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review (after 8b47fa33 "cert_sign_config added")

Thanks for bringing certificate_config back and dropping the hook Job. That resolves the earlier points about the private repo workflow, the README, ./install.sh certificate_config on the VM, publickeyConfig.image, the PEM newline format (the payload is the same awk extraction as before, so the format matches), and the silent-success hook. Running curl/jq on the host through a port-forward is a good approach.

❌ Blocker: the RETURN trap kills install.sh with exit 143

trap 'kill $pf_pid 2>/dev/null; wait $pf_pid 2>/dev/null' RETURN

When the function returns, kill sends SIGTERM to the port-forward, and wait $pf_pid then returns 143 (128 + SIGTERM). Because the script runs with set -euo pipefail, that non-zero status in the trap exits the whole script with 143, even when the key was registered successfully.

Reproduced on bash 5.2.21 (Ubuntu 24.04) with a minimal script using the same set -euo pipefail and the same trap line: output stopped right after the function returned, exit=143.

Impact:

  • Full install (./install.sh with no args): stops after certificate_config. dns_mapping, generate_postman_env and run_post_install never run.
  • Private repo workflow step 8 (bash install.sh certificate_config) always fails.

Fix (verified with the same test: the script continues, exit=0). It also clears the trap so it doesn't fire on later function returns:

trap 'kill $pf_pid 2>/dev/null; wait $pf_pid 2>/dev/null || true; trap - RETURN' RETURN

Smaller points on certificate_config

  1. Fixed local port 8081. If something on the runner already uses 8081 (another port-forward, a local service), either the port-forward dies, which is handled, or the readiness check gets an answer from the other process and the calls go to the wrong place. Let kubectl choose a free port: kubectl port-forward svc/registry-service :8081 and read the port from its output, or use a less common fixed port.
  2. Empty key check. If CERTIFICATE_PUBLIC_KEY is missing from global-values.yaml, CERTPUBKEY is empty and an empty key is registered, after which the search check skips it forever. Add [[ -n "$CERTPUBKEY" ]] || { echo "CERTIFICATE_PUBLIC_KEY not found in global-values.yaml"; return 1; }.
  3. Use "$ENV_DIR/global-values.yaml" in the awk, to match the certificate_keys change in this PR.
  4. /tmp/certcfg-pf-$$.log is never removed. Add rm -f "$pf_log" to the trap.

Still open from the first review

  1. GCP not updated. opentofu/gcp/template/install.sh still has the old kubectl exec deploy/knowledge-mw + apt-get install jq version, so GCP has the same DHI-image failure this PR fixes for Azure. Please port the new function there too.
  2. ysql.yaml backoffLimit. The PR removes backoffLimit: 30 and keeps backoffLimit: 0, so the migration Job gets no retries. Was that intended? Keeping 30 and dropping 0 seems safer.

✅ Unchanged and fine

  • ENV_DIR certificate key paths: correct for both the private repo workflow and running on the VM.
  • node:18.20.8-bookworm.
  • The ysql.yaml wait command fix (sleep 10, stray quotes removed).

Requesting changes for the trap blocker. The rest are small. After the fix, one full ./install.sh run (or at least install_component learnbb followed by certificate_config and dns_mapping) on a test environment would confirm it end to end.

@sho6000

sho6000 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author
  • set ysql.yaml to backoffLimit: 30
  • ai_pipeline set to false to avoid any interruption if api not set

@divyagovindaiah divyagovindaiah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review (after a38d7760 "updated cert_config, ysql to 30 retries")

Correction to my earlier comments: disabling ai_pipeline_enabled in the template was requested, so please ignore that point. I've removed it from the earlier reviews.

✅ Resolved in this commit

  • ysql.yaml: backoffLimit: 30, and only one backoffLimit remains. 👍
  • Port-forward readiness: checking for Forwarding from in the port-forward log confirms our port-forward is the one listening, so a different process on 8081 can no longer be mistaken for registry. If 8081 is busy, kubectl exits with "address already in use" and the kill -0 check catches it. Good enough to keep the fixed port.

❌ Still blocking: the RETURN trap exits install.sh with 143

This line is unchanged:

trap 'kill $pf_pid 2>/dev/null; wait $pf_pid 2>/dev/null' RETURN

When certificate_config returns, wait reports the killed port-forward as 143, and with set -euo pipefail that ends the whole script with exit 143, even after a successful registration. Reproduced on bash 5.2.21 (Ubuntu 24.04).

  • Full ./install.sh: stops after certificate_config. dns_mapping, generate_postman_env and run_post_install never run.
  • Private repo workflow step bash install.sh certificate_config: always fails.

One-line fix (verified: the script continues, exit 0):

trap 'kill $pf_pid 2>/dev/null; wait $pf_pid 2>/dev/null || true; rm -f "$pf_log"; trap - RETURN' RETURN

This also cleans up the temp log and clears the trap so it doesn't run again on later function returns.

Still open (non-blocking)

  1. Empty key guard. If CERTIFICATE_PUBLIC_KEY isn't in global-values.yaml, an empty key gets registered and the search check skips it from then on:
    [[ -n "$CERTPUBKEY" ]] || { echo "CERTIFICATE_PUBLIC_KEY not found in global-values.yaml"; return 1; }
  2. Use "$ENV_DIR/global-values.yaml" in the awk, to match the certificate_keys change.
  3. GCP: opentofu/gcp/template/install.sh still has the old kubectl exec deploy/knowledge-mw version. Please port the new function so GCP doesn't hit the same DHI-image failure.

Once the trap line is fixed, I'm happy to approve. Items 1–3 can go in this PR or a quick follow-up.

@sho6000

sho6000 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author
    1. Empty key guard — [[ -n "$CERTPUBKEY" ]] || { echo "..."; return 1; } added right after reading the key, before it can ever be POSTed empty.
    1. $ENV_DIR in the awk call — fixed in both files, consistent with the certificate_keys() path fix.
    1. GCP ported — opentofu/gcp/template/install.sh's old kubectl exec deploy/knowledge-mw version replaced with the same port-forward-based function (including the trap fix, readiness check, and both guards) — GCP's call sites (pipeline + case dispatch) were already in place and didn't need changes.

@divyagovindaiah

Copy link
Copy Markdown
Collaborator

Re-review (after 7a747612 "gcp + azure changes updated")

# Item Status
1 RETURN trap exiting install.sh with 143 ✅ Fixed: wait ... || true and trap - RETURN added (Azure and GCP)
2 Temp port-forward log not cleaned up ✅ Fixed: rm -f "$pf_log" in the trap
3 Empty key registered when CERTIFICATE_PUBLIC_KEY missing ✅ Fixed: guard added before the POST
4 awk reading global-values.yaml relative to cwd ✅ Fixed: now "$ENV_DIR/global-values.yaml"
5 GCP still using kubectl exec deploy/knowledge-mw ✅ Fixed: GCP now has the same port-forward certificate_config, wired into the default flow and the case entry
6 ysql.yaml migration Job retries ✅ Fixed: backoffLimit: 30 (single key)
7 Port-forward readiness check ✅ Fixed (previous commit): waits for Forwarding from in the port-forward log

Both install.sh files pass bash -n.

@divyagovindaiah

divyagovindaiah commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

One more fix needed

The problem

This PR changes the wait command inside the YugabyteDB migration Job (helmcharts/learnbb/templates/provision/ysql.yaml).

On an environment where learnbb is already installed, that Job already exists in the cluster. Kubernetes does not allow the command of an existing Job to be changed, so ./install.sh install_component learnbb will fail with:

Job.batch "learnbb-yugabytesql-migration-job" is invalid: spec.template: field is immutable

Fresh installs are fine. Only upgrades of existing environments fail.

What to change

In both opentofu/azure/template/install.sh and opentofu/gcp/template/install.sh, in install_component, inside the existing if [[ $component = "learnbb" ]] block (right after the keycloak-kids-keys delete), add:

kubectl delete job learnbb-yugabytesql-migration-job -n sunbird --ignore-not-found

So the block becomes:

if [[ $component = "learnbb" ]]; then
    if kubectl get job keycloak-kids-keys -n sunbird >/dev/null 2>&1; then
        echo "Deleting existing job keycloak-kids-keys..."
        kubectl delete job keycloak-kids-keys -n sunbird
    fi
    kubectl delete job learnbb-yugabytesql-migration-job -n sunbird --ignore-not-found
    ...

Helm then creates the Job again with the new command. Running the migration again is safe (the SQL files are applied with || true).

Optional (nice to have)

  • In certificate_config, add an error message if the PublicKey search call fails, so the script doesn't stop silently:
    CERTKEY=$(curl -sf ... | jq -r '.[] | .value') || { echo "registry-service PublicKey search failed"; return 1; }
  • The new comment in create_tf_resources starts mid-sentence ("ai_pipeline_enabled is true. Pre-create it here…"). Please complete it.

@sho6000

sho6000 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author
  • Delete the immutable Job before re-install — kubectl delete job learnbb-yugabytesql-migration-job -n sunbird --ignore-not-found added right in the learnbb block, fixing the upgrade-breaks bug.
  • Explicit failure message on the PublicKey/search call — now reports "registry-service PublicKey search failed" and returns 1 instead of silently falling through.
  • Mid-sentence comment fixed in Azure's create_tf_resources — restored the missing lead-in explaining why the namespace is excluded from Terraform's own list.
  • (Already done in the previous round) empty-key guard and $ENV_DIR in the awk call.

@divyagovindaiah
divyagovindaiah changed the base branch from v1.1.2 to v1.1.3 November 20, 2026 11:51
@divyagovindaiah

Copy link
Copy Markdown
Collaborator

Re-review (after 45eec217 "fixes added")

# Item Status
1 Delete learnbb-yugabytesql-migration-job before installing learnbb (Job template is immutable) ✅ Fixed in Azure and GCP install.sh
2 Error message when the registry PublicKey search fails ✅ Fixed in Azure and GCP
3 ai-pipeline comment in create_tf_resources starting mid-sentence ✅ Fixed

Both install.sh files pass bash -n. Nit: the blank line added above the new kubectl delete job line has trailing spaces.

@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants