-
Notifications
You must be signed in to change notification settings - Fork 129
[v2.11] add prime mode logic to the provisioning-tests script #1839
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
Open
jferrazbr
wants to merge
3
commits into
dev-v2.11
Choose a base branch
from
add-prime-mode-support-to-v2.11-provisioning-tests
base: dev-v2.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/usr/bin/awk -f | ||
| # Usage: channels-pick-minchan-for-version.awk <channels-file> <exact-version> | ||
| # Prints the minChannelServerVersion for that release (if present), returns 2 | ||
| # if receives insufficient arguments, else nothing. | ||
|
|
||
| function trim(s){ sub(/^[ \t\r\n]+/,"",s); sub(/[ \t\r\n]+$/,"",s); return s } | ||
|
|
||
| BEGIN { | ||
| if (ARGC < 3) exit 2 | ||
| target = ARGV[2] | ||
| ARGV[2] = "" # prevent awk from treating target as a file | ||
| inBlock = 0 | ||
| curVer = "" | ||
| } | ||
|
|
||
| # Start of a release block: "- version: <ver>" | ||
| /^[[:space:]]*-[[:space:]]*version:[[:space:]]*/ { | ||
| inBlock = 1 | ||
| line = $0 | ||
| sub(/^[[:space:]]*-[[:space:]]*version:[[:space:]]*/, "", line) | ||
| curVer = trim(line) | ||
| next | ||
| } | ||
jferrazbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Capture minChannelServerVersion only if we are in the target block | ||
| inBlock && curVer == target && /^[[:space:]]*minChannelServerVersion:[[:space:]]*/ { | ||
| line = $0 | ||
| sub(/^[[:space:]]*minChannelServerVersion:[[:space:]]*/, "", line) | ||
| print trim(line) | ||
| exit 0 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/usr/bin/env bash | ||
| # scripts/prime-route | ||
| # Sets PRIME_MODE, PRIME_REGISTRY_ENVIRONMENT, and (optionally) PRIME_REG_HOST/CATTLE_AGENT_IMAGE. | ||
| # Detection is independent of whether endpoints are available. | ||
| # Inputs: | ||
| # CHANNELS_FILE, SOME_K8S_VERSION, LAST_COMMUNITY_RANCHER | ||
| # REGISTRY_ENDPOINT, STAGE_REGISTRY_ENDPOINT | ||
| # PRIME_AGENT_IMAGE | ||
| set -e | ||
|
|
||
| # only set defaults if not provided by the workflow | ||
| if [ -z "${LAST_COMMUNITY_RANCHER:-}" ]; then | ||
| LAST_COMMUNITY_RANCHER="v2.11.0-alpha1" | ||
| fi | ||
|
|
||
| if [ -z "${PRIME_AGENT_IMAGE:-}" ]; then | ||
jferrazbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PRIME_AGENT_IMAGE="rancher/rancher-agent:v2.11.6" | ||
| fi | ||
|
|
||
|
|
||
| # Compute minChannelServerVersion for the selected K8s version (may be empty) | ||
| MINCHAN="$(scripts/channels-pick-minchan-for-version.awk "${CHANNELS_FILE}" "${SOME_K8S_VERSION}" || true)" | ||
|
|
||
| # Defaults | ||
| PRIME_MODE=0 | ||
| unset PRIME_REGISTRY_ENVIRONMENT | ||
| unset PRIME_REG_HOST | ||
|
|
||
| # Decide Prime mode purely by version comparison: MINCHAN > LAST_COMMUNITY_RANCHER | ||
| if [[ -n "${MINCHAN}" ]] && scripts/semver_g.awk "${MINCHAN}" "${LAST_COMMUNITY_RANCHER}"; then | ||
| PRIME_MODE=1 | ||
jferrazbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # --- BEGIN sensitive section (suppress xtrace to avoid printing hosts) --- | ||
| _TRACE_WAS_ON=0 | ||
jferrazbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [[ $- == *x* ]]; then | ||
| _TRACE_WAS_ON=1 | ||
| set +x | ||
| fi | ||
|
|
||
| # Choose staging vs production by "-rc" in SOME_K8S_VERSION (prerelease => staging) | ||
| if [[ "${SOME_K8S_VERSION,,}" == *-rc* ]]; then | ||
| PRIME_REGISTRY_ENVIRONMENT="staging" | ||
| PRIME_REG_HOST="${STAGE_REGISTRY_ENDPOINT:-}" | ||
| else | ||
| PRIME_REGISTRY_ENVIRONMENT="production" | ||
| PRIME_REG_HOST="${REGISTRY_ENDPOINT:-}" | ||
| fi | ||
|
|
||
| # Only export PRIME_REG_HOST if it is set | ||
| if [[ -n "${PRIME_REG_HOST}" ]]; then | ||
| export PRIME_REG_HOST | ||
| fi | ||
|
|
||
| # If Prime is on and PRIME_AGENT_IMAGE is set, override CATTLE_AGENT_IMAGE | ||
| if [[ -n "${PRIME_AGENT_IMAGE:-}" ]]; then | ||
| export CATTLE_AGENT_IMAGE="${PRIME_AGENT_IMAGE}" | ||
| fi | ||
|
|
||
| # Restore xtrace if it was enabled | ||
| if [[ "${_TRACE_WAS_ON}" == "1" ]]; then | ||
| set -x | ||
| fi | ||
| # --- END sensitive section --- | ||
| fi | ||
|
|
||
| # Export non-sensitive flags (safe to print) | ||
| export PRIME_MODE PRIME_REGISTRY_ENVIRONMENT | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/usr/bin/awk -f | ||
| # Exit codes: 0 if A>B by major.minor.patch (ignoring pre-release suffix), 1 if A<=B, 2 if insufficient arguments. | ||
| # Usage: scripts/semver_g.awk <A> <B> | ||
| function norm(s, n,i,arr) { | ||
| gsub(/^v/,"",s); sub(/-.*/,"",s) | ||
| n = split(s, arr, ".") | ||
| for (i=1; i<=3; i++) if (i>n) arr[i]=0 | ||
| return sprintf("%d.%d.%d", arr[1], arr[2], arr[3]) | ||
| } | ||
| BEGIN { | ||
| if (ARGC < 3) exit 2 | ||
| as = norm(ARGV[1]); bs = norm(ARGV[2]) | ||
| split(as,a,"."); split(bs,b,".") | ||
| if (a[1]>b[1] || (a[1]==b[1] && (a[2]>b[2] || (a[2]==b[2] && a[3]>b[3])))) exit 0 | ||
| exit 1 | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.