Skip to content

Commit 76f33c9

Browse files
committed
feat(build): Improve dev workflow with auto-detect and next-steps output
- generate-resources.sh auto-detects cluster stack version from .release/ directory (priority: .release/ > OCI registry > default v1) - build.sh prints actionable 'next steps' after publish with exact CSO helm install and generate-resources commands - Add 'just dev' recipe that chains build+publish+generate in one command Assisted-by: Claude Code Signed-off-by: Jan Schoone <jan.schoone@uhurutec.com>
1 parent 60674dd commit 76f33c9

3 files changed

Lines changed: 87 additions & 9 deletions

File tree

hack/build.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ EOF
394394
if [[ "$PUBLISH" == "true" ]]; then
395395
publish_version "$release_dir" "$provider" "$stack_name" "$k8s_dash" "$release_version"
396396
fi
397+
398+
# Track for "next steps" output
399+
BUILT_K8S_SHORTS+=("$k8s_short")
400+
BUILT_CS_VERSIONS+=("$release_version")
401+
BUILT_PROVIDERS+=("$provider")
402+
BUILT_STACK_NAMES+=("$stack_name")
397403
}
398404

399405
# ============================================
@@ -451,9 +457,45 @@ echo "Stack base: $BASE_DIR"
451457
echo "Version dirs: $(echo "$VERSION_DIRS" | tr '\n' ' ')"
452458
echo ""
453459

460+
# Track built versions for "next steps" output
461+
declare -a BUILT_K8S_SHORTS=()
462+
declare -a BUILT_CS_VERSIONS=()
463+
declare -a BUILT_PROVIDERS=()
464+
declare -a BUILT_STACK_NAMES=()
465+
454466
for version_dir in $VERSION_DIRS; do
455467
build_version_dir "$version_dir"
456468
done
457469

458470
echo ""
459471
echo "Done."
472+
473+
# ============================================
474+
# Next steps (after publish)
475+
# ============================================
476+
477+
if [[ "$PUBLISH" == "true" && ${#BUILT_K8S_SHORTS[@]} -gt 0 ]]; then
478+
echo ""
479+
echo "================================================================"
480+
echo "Next steps"
481+
echo "================================================================"
482+
echo ""
483+
echo "1. Install the Cluster Stack Operator (CSO) with matching OCI config:"
484+
echo ""
485+
echo " helm install cso <path-to-cso-chart> \\"
486+
echo " --namespace cso-system --create-namespace \\"
487+
echo " --set controllerManager.manager.source=oci \\"
488+
echo " --set clusterStackVariables.ociRegistry=\"${OCI_REGISTRY}\" \\"
489+
echo " --set clusterStackVariables.ociRepository=\"${OCI_REPOSITORY}\""
490+
echo ""
491+
echo "2. Apply the ClusterStack resource(s):"
492+
echo ""
493+
for ((i=0; i<${#BUILT_K8S_SHORTS[@]}; i++)); do
494+
local_provider="${BUILT_PROVIDERS[$i]}"
495+
local_stack="${BUILT_STACK_NAMES[$i]}"
496+
local_k8s="${BUILT_K8S_SHORTS[$i]}"
497+
local_version="${BUILT_CS_VERSIONS[$i]}"
498+
echo " CLUSTER_STACK=${local_stack} ./hack/generate-resources.sh --version ${local_k8s} --cs-version ${local_version} | kubectl apply -f -"
499+
done
500+
echo ""
501+
fi

hack/generate-resources.sh

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
#
1111
# Options:
1212
# --version <X.Y> K8s minor version (required)
13-
# --cs-version <vN> Cluster stack version (default: auto-detect from OCI, or v1)
13+
# --cs-version <vN> Cluster stack version (default: auto-detect, see below)
1414
# --namespace <ns> Namespace (default: cluster)
1515
# --cluster-name <name> Workload cluster name (default: cs-cluster)
1616
# --cluster-only Only generate the Cluster resource
1717
# --clusterstack-only Only generate the ClusterStack resource
1818
#
19-
# Auto-detection of --cs-version queries the OCI registry for existing tags.
20-
# Requires OCI_REGISTRY and OCI_REPOSITORY environment variables and oras CLI.
21-
# Falls back to v1 if auto-detection is not possible.
19+
# Auto-detection of --cs-version (in priority order):
20+
# 1. Local .release/ directory — reads metadata.yaml from the latest matching build
21+
# 2. OCI registry — queries tags via oras (requires OCI_REGISTRY + OCI_REPOSITORY)
22+
# 3. Falls back to v1
2223
#
2324
# Output goes to stdout. Pipe to kubectl apply -f - or redirect to a file.
2425
#
@@ -98,21 +99,36 @@ K8S_VERSION_RAW=$(yq -r '.kubernetesVersion' "$STACK_YAML")
9899
# Use full version from stack.yaml if it has patch, otherwise use the minor
99100
K8S_FULL="$K8S_VERSION_RAW"
100101

101-
# Auto-detect CS version from OCI registry (if not specified)
102+
# Auto-detect CS version (if not specified)
103+
# Priority: 1. local .release/ build output 2. OCI registry 3. fall back to v1
102104
if [[ -z "$CS_VERSION" ]]; then
103-
CS_VERSION="v1"
104-
if [[ -n "${OCI_REGISTRY:-}" && -n "${OCI_REPOSITORY:-}" ]] && command -v oras >/dev/null 2>&1; then
105-
TAG_PREFIX="${PROVIDER}-${CLUSTER_STACK}-${K8S_DASH}"
105+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
106+
RELEASE_DIR="${OUTPUT_DIR:-$REPO_ROOT/.release}"
107+
TAG_PREFIX="${PROVIDER}-${CLUSTER_STACK}-${K8S_DASH}"
108+
109+
# 1. Check .release/ for a matching build (newest first by mtime)
110+
LATEST_BUILD=""
111+
if [[ -d "$RELEASE_DIR" ]]; then
112+
LATEST_BUILD=$(ls -dt "$RELEASE_DIR/${TAG_PREFIX}"-*/metadata.yaml 2>/dev/null | head -1 || true)
113+
fi
114+
115+
if [[ -n "$LATEST_BUILD" ]]; then
116+
CS_VERSION=$(yq -r '.versions.clusterStack' "$LATEST_BUILD")
117+
echo "# Auto-detected CS version: ${CS_VERSION} (from $(dirname "$LATEST_BUILD"))" >&2
118+
# 2. Try OCI registry
119+
elif [[ -n "${OCI_REGISTRY:-}" && -n "${OCI_REPOSITORY:-}" ]] && command -v oras >/dev/null 2>&1; then
106120
LATEST=$(oras repo tags "${OCI_REGISTRY}/${OCI_REPOSITORY}" 2>/dev/null | \
107121
grep -oP "^${TAG_PREFIX}-v\K[0-9]+" | sort -n | tail -1 || echo "")
108122
if [[ -n "$LATEST" ]]; then
109123
CS_VERSION="v${LATEST}"
110124
echo "# Auto-detected CS version: ${CS_VERSION} (from ${OCI_REGISTRY}/${OCI_REPOSITORY})" >&2
111125
else
126+
CS_VERSION="v1"
112127
echo "# No published versions found, using default: ${CS_VERSION}" >&2
113128
fi
114129
else
115-
echo "# OCI auto-detect unavailable (set OCI_REGISTRY/OCI_REPOSITORY + oras), using default: ${CS_VERSION}" >&2
130+
CS_VERSION="v1"
131+
echo "# No .release/ build or OCI registry available, using default: ${CS_VERSION}" >&2
116132
fi
117133
fi
118134

justfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ build *FLAGS:
3333
publish *FLAGS:
3434
{{ if RUN_IN_CONTAINER == "true" { "just _container-exec publish " + FLAGS } else { "./hack/build.sh --publish " + FLAGS } }}
3535

36+
# Build, publish, and generate the ClusterStack resource (e.g., just dev --version 1.35)
37+
dev *FLAGS:
38+
#!/usr/bin/env bash
39+
set -euo pipefail
40+
./hack/build.sh --publish {{FLAGS}}
41+
# Extract --version from flags for generate-resources
42+
version=""
43+
prev=""
44+
for arg in {{FLAGS}}; do
45+
if [[ "$prev" == "--version" ]]; then version="$arg"; fi
46+
prev="$arg"
47+
done
48+
if [[ -n "$version" ]]; then
49+
echo ""
50+
echo "================================================================"
51+
echo "ClusterStack resource (pipe to kubectl apply -f -)"
52+
echo "================================================================"
53+
./hack/generate-resources.sh --version "$version" --clusterstack-only
54+
fi
55+
3656
# Clean build artifacts
3757
clean:
3858
rm -rf .release

0 commit comments

Comments
 (0)