Skip to content

Commit 63b2200

Browse files
committed
chore: make user and password optional
Signed-off-by: Prateek Chandra <[email protected]>
1 parent aef83be commit 63b2200

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

scripts/staging/kubectl-oci.sh

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# Manage kubectl plugin binaries as OCI artifacts.
33
# Supports both pushing and pulling operations.
44
# Usage:
5-
# Push: ./kubectl-oci.sh push --tag <tag> --namespace <namespace> --username <user> --password <token>
6-
# Pull: ./kubectl-oci.sh pull --tag <tag> --namespace <namespace> --username <user> --password <token>
5+
# Push: ./kubectl-oci.sh push --tag <tag> --namespace <namespace> [--username <user> --password <token>]
6+
# Pull: ./kubectl-oci.sh pull --tag <tag> --namespace <namespace> [--username <user> --password <token>]
77

88
set -euo pipefail
99

1010
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
1111
ROOT_DIR="$SCRIPT_DIR/../"
1212

13+
# shellcheck source=../utils/log.sh
1314
source "$ROOT_DIR/utils/log.sh"
1415

1516
ACTION=""
@@ -19,6 +20,7 @@ USERNAME=""
1920
PASSWORD=""
2021
REGISTRY="ghcr.io"
2122
PLUGIN="${PLUGIN:-"mayastor"}"
23+
NO_LOGIN=false
2224

2325
usage() {
2426
cat << EOF
@@ -32,12 +34,14 @@ Options:
3234
--tag <tag> Release tag (required)
3335
--registry <registry> The registry to push/pull from [default=$REGISTRY]
3436
--namespace <namespace> Namespace path (required)
35-
--username <username> Registry username (required)
36-
--password <password> Registry token/password (required)
37+
--username <username> Registry username (optional if already logged in)
38+
--password <password> Registry token/password (optional if already logged in)
39+
--no-login Skip login check (useful for CI/CD with pre-auth)
40+
-h, --help Show this help message
3741
3842
Examples:
3943
$0 push --tag v1.0.0 --namespace $PLUGIN/dev --username user --password token
40-
$0 pull --tag v1.0.0 --namespace $PLUGIN/dev --username user --password token
44+
$0 pull --tag v1.0.0 --namespace $PLUGIN/dev
4145
EOF
4246
}
4347

@@ -81,6 +85,10 @@ parse_args() {
8185
PASSWORD="$2"
8286
shift 2
8387
;;
88+
--no-login)
89+
NO_LOGIN=true
90+
shift
91+
;;
8492
-h|--help)
8593
usage
8694
exit 0
@@ -92,16 +100,31 @@ parse_args() {
92100
esac
93101
done
94102

95-
if [[ -z "$TAG" ]] || [[ -z "$NAMESPACE" ]] || [[ -z "$USERNAME" ]] || [[ -z "$PASSWORD" ]]; then
103+
if [[ -z "$TAG" ]] || [[ -z "$NAMESPACE" ]]; then
96104
usage
97-
log_fatal "Error: All options (--tag, --namespace, --username, --password) are required"
105+
log_fatal "Error: --tag and --namespace are required"
106+
fi
107+
108+
if [[ -z "${USERNAME:-}" || -z "${PASSWORD:-}" ]]; then
109+
echo "⚠️ No username/password provided — will attempt to use existing oras login session for ${REGISTRY}"
98110
fi
99111

100-
REPOSITORY=${REGISTRY}/${NAMESPACE}/kubectl-${PLUGIN}
112+
REPOSITORY="${REGISTRY}/${NAMESPACE}/kubectl-${PLUGIN}"
101113
}
102114

103-
# Login to registry
115+
# Login to registry (only if needed)
104116
login_registry() {
117+
echo "Checking login status for ${REGISTRY}..."
118+
119+
if oras login "${REGISTRY}" --get >/dev/null 2>&1; then
120+
echo "Already logged in to ${REGISTRY}"
121+
return 0
122+
fi
123+
124+
if [[ -z "${USERNAME:-}" || -z "${PASSWORD:-}" ]]; then
125+
log_fatal "Error: Not logged in to ${REGISTRY} and no credentials provided. Use --username and --password."
126+
fi
127+
105128
echo "Logging in to ${REGISTRY}..."
106129
echo "${PASSWORD}" | oras login "${REGISTRY}" --username "${USERNAME}" --password-stdin
107130
}
@@ -129,7 +152,7 @@ push_artifacts() {
129152

130153
rm -f "${combined_tar}"
131154

132-
echo "All kubectl binaries pushed successfully as a single bundle!"
155+
echo "All kubectl binaries pushed successfully as a single bundle!"
133156
echo "Bundle available at: ${REPOSITORY}:${TAG}"
134157
}
135158

@@ -155,12 +178,15 @@ pull_artifacts() {
155178
echo "Contents of artifacts directory after extraction:"
156179
ls -la artifacts/
157180

158-
echo "All kubectl binaries pulled successfully!"
181+
echo "All kubectl binaries pulled successfully!"
159182
}
160183

161184
main() {
162185
parse_args "$@"
163-
login_registry
186+
187+
if [[ "$NO_LOGIN" == false ]]; then
188+
login_registry
189+
fi
164190

165191
case "$ACTION" in
166192
push)

scripts/staging/validate.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ done
1818

1919
# --- Determine paths based on CHART_VALIDATE ---
2020
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
21+
source "${SCRIPT_DIR}/../utils/log.sh"
2122

2223
if [[ "${CHART_VALIDATE}" == "true" ]]; then
2324
ROOT_DIR="${SCRIPT_DIR}/../../../../../../"
2425
: "${PARENT_ROOT_DIR:=$ROOT_DIR}"
25-
26-
source "$ROOT_DIR/dependencies/control-plane/utils/dependencies/scripts/utils/log.sh"
2726
else
2827
ROOT_DIR="${SCRIPT_DIR}/../../../../"
2928
: "${PARENT_ROOT_DIR:=$ROOT_DIR}"
30-
31-
source "$ROOT_DIR/utils/dependencies/scripts/utils/log.sh"
3229
fi
3330

3431
# --- Run release.sh in a subshell ---

0 commit comments

Comments
 (0)