Skip to content

Commit 963be78

Browse files
authored
update scripts for running local developer versions of bmo and capbm (#1067)
* rename scripts for managing baremetal-operator Signed-off-by: Doug Hellmann <[email protected]> * make bmo scripts use more distinct output filenames Signed-off-by: Doug Hellmann <[email protected]> * add script to run local version of capbm from source Signed-off-by: Doug Hellmann <[email protected]> * add script to switch back to mao-run version of capbm Signed-off-by: Doug Hellmann <[email protected]> * update instructions for running bmo and capbm from source Signed-off-by: Doug Hellmann <[email protected]>
1 parent a037780 commit 963be78

File tree

6 files changed

+130
-25
lines changed

6 files changed

+130
-25
lines changed

docs/custom-mao-and-capbm.md

+36-15
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,50 @@ Update the `kubeconfig` path to reflect your own environment.
107107
bin/machine-api-operator start --images-json=custom-images.json --kubeconfig=/home/${USER}/dev-scripts/ocp/$CLUSTER_NAME/auth/kubeconfig -v 4
108108
```
109109

110-
## Run a custom baremetal-operator
110+
## Run baremetal-operator from local source checkout
111111

112-
This step assumes that the machine-api-operator has been completely
113-
stopped, as described above, so that it does not re-deploy metal3 and
114-
break the manual configuration performed below.
112+
metal3 relies on ironic, a database, and other services that normally
113+
run inside the cluster. These can be launched with the script
114+
"metal3-dev/local-bmo.sh". The script stops the machine-api-operator,
115+
scales down the Deployment containing the services related to the
116+
baremetal-operator, and creates a new Deployment called
117+
"metal3-development" containing everything the baremetal-operator
118+
relies on. Finally, it uses the source in
119+
`$GOPATH/github.com/metal3-io/baremetal-operator` to build and run a
120+
version of the baremetal-operator from source, including updating the
121+
CRD for the BareMetalHost.
115122

116-
### 1) Remove the metal3 deployment
123+
```sh
124+
./metal3-dev/local-bmo.sh
125+
```
117126

118-
The machine-api-provider creates a "metal3" deployment, which needs to
119-
be deleted.
127+
To restore the version of the baremetal-operator deployed with the
128+
cluster, run
120129

121130
```sh
122-
oc delete deployment -n openshift-machine-api metal3
131+
./metal3-dev/mao-bmo.sh
123132
```
124133

125-
### 2) Launch the metal3 support services in the cluster
134+
## Run cluster-api-provider-baremetal from local source checkout
126135

127-
metal3 relies on ironic, a database, and other services that normally
128-
run inside the cluster. These can be launched with the script
129-
"metal3-dev/run.sh". The script creates a Deployment called
130-
"metal3-development" to differentiate it from the standard "metal3"
131-
deployment.
136+
The cluster API provider component is part of a Pod created by the
137+
machine-api-operator. The same Pod runs several other components which
138+
must be running for the cluster to function properly. The script
139+
140+
"metal3-dev/local-capbm.sh". The script stops the
141+
machine-api-operator, scales down the Deployment it created, and
142+
creates a new Deployment called "capbm-development" containing
143+
everything the old Deployment contained except for the
144+
cluster-api-provider-baremetal. Finally, it runs `make run` in
145+
`$GOPATH/github.com/openshift/cluster-api-provider-baremetal` to build
146+
and run a version of CAPBM from source.
147+
148+
```sh
149+
./metal3-dev/local-capbm.sh
150+
```
151+
152+
To restore the version of CAPBM deployed with the cluster, run
132153

133154
```sh
134-
./metal3-dev/run.sh
155+
./metal3-dev/mao-capbm.sh
135156
```

metal3-dev/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Metal3 Development
2+
3+
See [../docs/custom-mao-and-capbm.md](../docs/custom-mao-and-capbm.md)
4+
for instructions for using these scripts.

metal3-dev/run.sh metal3-dev/local-bmo.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,34 @@ if oc get pod -o name -n openshift-machine-api | grep -v metal3-development | gr
4141
fi
4242

4343
# Save a copy of the full deployment as input
44-
oc get deployment -n openshift-machine-api -o yaml metal3 > $OUTDIR/deployment-full.yaml
44+
oc get deployment -n openshift-machine-api -o yaml metal3 > $OUTDIR/bmo-deployment-full.yaml
4545

4646
# Extract the containers list, skipping the bmo
47-
cat $OUTDIR/deployment-full.yaml \
47+
cat $OUTDIR/bmo-deployment-full.yaml \
4848
| yq -Y '.spec.template.spec.containers | map(select( .command[0] != "/baremetal-operator"))' \
49-
> $OUTDIR/deployment-dev-containers.yaml
49+
> $OUTDIR/bmo-deployment-dev-containers.yaml
5050

5151
# Get a stripped down version of the deployment
52-
cat $OUTDIR/deployment-full.yaml \
52+
cat $OUTDIR/bmo-deployment-full.yaml \
5353
| yq -Y 'del(.spec.template.spec.containers) | del(.status) | del(.metadata.annotations) | del(.metadata.selfLink) | del(.metadata.uid) | del(.metadata.resourceVersion) | del(.metadata.creationTimestamp) | del(.metadata.generation)' \
54-
> $OUTDIR/deployment-dev-without-containers.yaml
54+
> $OUTDIR/bmo-deployment-dev-without-containers.yaml
5555

5656
# Combine the stripped down deployment with the container list
57-
containers=$(cat $OUTDIR/deployment-dev-containers.yaml | yq '.')
58-
cat $OUTDIR/deployment-dev-without-containers.yaml \
57+
containers=$(cat $OUTDIR/bmo-deployment-dev-containers.yaml | yq '.')
58+
cat $OUTDIR/bmo-deployment-dev-without-containers.yaml \
5959
| yq -Y --argjson containers "$containers" \
6060
'setpath(["spec", "template", "spec", "containers"]; $containers) | setpath(["metadata", "name"]; "metal3-development")' \
6161
| yq -Y 'setpath(["spec", "replicas"]; 1)' \
62-
> $OUTDIR/deployment-dev.yaml
62+
> $OUTDIR/bmo-deployment-dev.yaml
6363

6464
# Launch the deployment with the support services and ensure it is scaled up
65-
oc apply -f $OUTDIR/deployment-dev.yaml -n openshift-machine-api
65+
oc apply -f $OUTDIR/bmo-deployment-dev.yaml -n openshift-machine-api
6666

6767
# Set some variables the operator expects to have in order to work
6868
export OPERATOR_NAME=baremetal-operator
6969

7070
for var in IRONIC_ENDPOINT IRONIC_INSPECTOR_ENDPOINT DEPLOY_KERNEL_URL DEPLOY_RAMDISK_URL; do
71-
export "$var"=$(cat $OUTDIR/deployment-full.yaml | yq -r ".spec.template.spec.containers[0].env | map(select( .name == \""${var}"\"))[0].value")
71+
export "$var"=$(cat $OUTDIR/bmo-deployment-full.yaml | yq -r ".spec.template.spec.containers[0].env | map(select( .name == \""${var}"\"))[0].value")
7272
done
7373

7474
# Wait for the ironic service to be available

metal3-dev/local-capbm.sh

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash -xe
2+
3+
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
4+
5+
LOGDIR=${SCRIPTDIR}/logs
6+
source $SCRIPTDIR/logging.sh
7+
8+
source $SCRIPTDIR/common.sh
9+
source $SCRIPTDIR/utils.sh
10+
11+
if ! which yq 2>&1 >/dev/null ; then
12+
echo "Did not find yq" 1>&2
13+
echo "Install with: pip3 install --user yq" 1>&2
14+
exit 1
15+
fi
16+
17+
capbm_path=$GOPATH/src/github.com/openshift/cluster-api-provider-baremetal
18+
if [ ! -d $capbm_path ]; then
19+
echo "Did not find $capbm_path" 1>&2
20+
exit 1
21+
fi
22+
23+
# Stop the machine-api-operator so it does not try to fix the
24+
# deployment we are going to change.
25+
$SCRIPTDIR/stop-mao.sh
26+
27+
OUTDIR=${OCP_DIR}/metal3-dev
28+
mkdir -p $OUTDIR
29+
30+
# Scale the existing deployment down.
31+
oc scale deployment -n openshift-machine-api --replicas=0 machine-api-controllers
32+
if oc get pod -o name -n openshift-machine-api | grep -q machine-api-controllers; then
33+
pods=$(oc get pod -o name -n openshift-machine-api | grep machine-api-controllers)
34+
oc wait --for=delete -n openshift-machine-api $pods || true
35+
fi
36+
37+
# Save a copy of the full deployment as input
38+
oc get deployment -n openshift-machine-api -o yaml machine-api-controllers > $OUTDIR/capbm-deployment-full.yaml
39+
40+
# Extract the containers list, skipping the capbm
41+
cat $OUTDIR/capbm-deployment-full.yaml \
42+
| yq -Y '.spec.template.spec.containers | map(select( .command[0] != "/machine-controller-manager"))' \
43+
> $OUTDIR/capbm-deployment-dev-containers.yaml
44+
45+
# Get a stripped down version of the deployment
46+
cat $OUTDIR/capbm-deployment-full.yaml \
47+
| yq -Y 'del(.spec.template.spec.containers) | del(.status) | del(.metadata.annotations) | del(.metadata.selfLink) | del(.metadata.uid) | del(.metadata.resourceVersion) | del(.metadata.creationTimestamp) | del(.metadata.generation)' \
48+
> $OUTDIR/capbm-deployment-dev-without-containers.yaml
49+
50+
# Combine the stripped down deployment with the container list
51+
containers=$(cat $OUTDIR/capbm-deployment-dev-containers.yaml | yq '.')
52+
cat $OUTDIR/capbm-deployment-dev-without-containers.yaml \
53+
| yq -Y --argjson containers "$containers" \
54+
'setpath(["spec", "template", "spec", "containers"]; $containers) | setpath(["metadata", "name"]; "capbm-development")' \
55+
| yq -Y 'setpath(["spec", "replicas"]; 1)' \
56+
> $OUTDIR/capbm-deployment-dev.yaml
57+
58+
# Launch the deployment with the support services and ensure it is scaled up
59+
oc apply -f $OUTDIR/capbm-deployment-dev.yaml -n openshift-machine-api
60+
61+
# Run the local capbm
62+
cd $capbm_path
63+
64+
make build && ./bin/machine-controller-manager --logtostderr=true --v=3 --namespace=openshift-machine-api
File renamed without changes.

metal3-dev/mao-capbm.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash -xe
2+
3+
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
4+
5+
LOGDIR=${SCRIPTDIR}/logs
6+
source $SCRIPTDIR/logging.sh
7+
8+
# Scale down dev deployment
9+
oc scale deployment -n openshift-machine-api --replicas=0 capbm-development
10+
if oc get pod -o name -n openshift-machine-api | grep -q capbm-development; then
11+
pods=$(oc get pod -o name -n openshift-machine-api | grep capbm-development)
12+
oc wait --for=delete -n openshift-machine-api $pods || true
13+
fi
14+
15+
# Scale up regular deployment
16+
oc scale deployment -n openshift-machine-api --replicas=1 machine-api-controllers

0 commit comments

Comments
 (0)