Skip to content

Commit 7088f9c

Browse files
committed
chore: improve wrapper scripts for flexibility
Signed-off-by: Chris Butler <chris.butler@redhat.com>
1 parent 9c6f715 commit 7088f9c

File tree

2 files changed

+84
-11
lines changed

2 files changed

+84
-11
lines changed

rhdp/rhdp-cluster-define.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,22 @@
1313
from typing_extensions import Annotated
1414

1515

16-
def get_default_cluster_configs() -> List[Dict]:
17-
"""Get default cluster configurations"""
16+
def get_default_cluster_configs(prefix: str = "") -> List[Dict]:
17+
"""Get default cluster configurations
18+
19+
Args:
20+
prefix: Optional prefix to add to cluster name and directory
21+
"""
22+
if prefix:
23+
return [
24+
{
25+
"name": f"coco-{prefix}",
26+
"directory": f"openshift-install-{prefix}",
27+
"cluster_network_cidr": "10.128.0.0/14",
28+
"machine_network_cidr": "10.0.0.0/16",
29+
"service_network_cidr": "172.30.0.0/16",
30+
}
31+
]
1832
return [
1933
{
2034
"name": "coco",
@@ -135,23 +149,35 @@ def run(
135149
multicluster: Annotated[
136150
bool, typer.Option("--multicluster", help="Deploy hub and spoke clusters")
137151
] = False,
152+
prefix: Annotated[
153+
str, typer.Option("--prefix", help="Prefix for cluster name and directory")
154+
] = "",
138155
):
139156
"""
140157
Region flag requires an azure region key which can be (authoritatively)
141158
requested with: "az account list-locations -o table".
142159
143160
Use --multicluster flag to deploy both hub (coco-hub) and spoke (coco-spoke)
144161
clusters.
162+
163+
Use --prefix to add a prefix to cluster name and install directory, enabling
164+
multiple cluster deployments (e.g., --prefix cluster1 creates coco-cluster1
165+
in openshift-install-cluster1).
145166
"""
146167
validate_dir()
147168

148169
# Choose cluster configurations based on multicluster flag
149170
if multicluster:
171+
if prefix:
172+
rprint("WARNING: --prefix is ignored when using --multicluster")
150173
cluster_configs = get_multicluster_configs()
151174
rprint("Setting up multicluster deployment (hub and spoke)")
152175
else:
153-
cluster_configs = get_default_cluster_configs()
154-
rprint("Setting up single cluster deployment")
176+
cluster_configs = get_default_cluster_configs(prefix)
177+
if prefix:
178+
rprint(f"Setting up single cluster deployment with prefix: {prefix}")
179+
else:
180+
rprint("Setting up single cluster deployment")
155181

156182
cleanup(pathlib.Path.cwd(), cluster_configs)
157183
setup_install(

rhdp/wrapper.sh

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,56 @@ get_python_cmd() {
1414
fi
1515
}
1616

17-
if [ "$#" -ne 1 ]; then
18-
echo "Error: Exactly one argument is required."
19-
echo "Usage: $0 {azure-region-code}"
17+
# Parse arguments
18+
AZUREREGION=""
19+
PREFIX=""
20+
21+
while [[ $# -gt 0 ]]; do
22+
case $1 in
23+
--prefix)
24+
PREFIX="$2"
25+
shift 2
26+
;;
27+
--prefix=*)
28+
PREFIX="${1#*=}"
29+
shift
30+
;;
31+
-*)
32+
echo "Error: Unknown option $1"
33+
echo "Usage: $0 [--prefix <prefix>] {azure-region-code}"
34+
echo "Example: $0 eastasia"
35+
echo "Example: $0 --prefix cluster1 eastasia"
36+
exit 1
37+
;;
38+
*)
39+
if [ -z "$AZUREREGION" ]; then
40+
AZUREREGION="$1"
41+
else
42+
echo "Error: Too many positional arguments."
43+
echo "Usage: $0 [--prefix <prefix>] {azure-region-code}"
44+
exit 1
45+
fi
46+
shift
47+
;;
48+
esac
49+
done
50+
51+
if [ -z "$AZUREREGION" ]; then
52+
echo "Error: Azure region is required."
53+
echo "Usage: $0 [--prefix <prefix>] {azure-region-code}"
2054
echo "Example: $0 eastasia"
55+
echo "Example: $0 --prefix cluster1 eastasia"
2156
exit 1
2257
fi
23-
AZUREREGION=$1
58+
59+
# Set install directory based on prefix
60+
if [ -n "$PREFIX" ]; then
61+
INSTALL_DIR="openshift-install-${PREFIX}"
62+
echo "Using prefix: $PREFIX"
63+
echo "Install directory: $INSTALL_DIR"
64+
else
65+
INSTALL_DIR="openshift-install"
66+
fi
2467

2568
echo "---------------------"
2669
echo "Validating configuration"
@@ -113,15 +156,19 @@ echo "---------------------"
113156
echo "defining cluster"
114157
echo "---------------------"
115158
PYTHON_CMD=$(get_python_cmd)
116-
$PYTHON_CMD rhdp/rhdp-cluster-define.py ${AZUREREGION}
159+
if [ -n "$PREFIX" ]; then
160+
$PYTHON_CMD rhdp/rhdp-cluster-define.py --prefix "${PREFIX}" ${AZUREREGION}
161+
else
162+
$PYTHON_CMD rhdp/rhdp-cluster-define.py ${AZUREREGION}
163+
fi
117164
echo "---------------------"
118165
echo "cluster defined"
119166
echo "---------------------"
120167
sleep 10
121168
echo "---------------------"
122169
echo "openshift-install"
123170
echo "---------------------"
124-
openshift-install create cluster --dir=./openshift-install
171+
openshift-install create cluster --dir=./${INSTALL_DIR}
125172
echo "openshift-install done"
126173
echo "---------------------"
127174
echo "setting up secrets"
@@ -133,7 +180,7 @@ sleep 60
133180
echo "---------------------"
134181
echo "pattern install"
135182
echo "---------------------"
136-
export KUBECONFIG="$(pwd)/openshift-install/auth/kubeconfig"
183+
export KUBECONFIG="$(pwd)/${INSTALL_DIR}/auth/kubeconfig"
137184

138185

139186
./pattern.sh make install

0 commit comments

Comments
 (0)