Skip to content

Commit 47897ef

Browse files
committed
Use a job instead of oc debug for 'make crc_storage'
1 parent 3ab4f51 commit 47897ef

File tree

4 files changed

+188
-4
lines changed

4 files changed

+188
-4
lines changed

scripts/create-pv.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,26 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616
set -ex
17+
18+
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19+
. "${SCRIPTPATH}/storage_common.sh"
20+
1721
PV_NUM=${PV_NUM:-12}
22+
TIMEOUT=${TIMEOUT:-300s}
1823

1924
released=$(oc get pv -o json | jq -r '.items[] | select(.status.phase | test("Released")).metadata.name')
2025

2126
for name in $released; do
2227
oc patch pv -p '{"spec":{"claimRef": null}}' $name
2328
done
2429

25-
NODE_NAMES=$(oc get node -o name -l node-role.kubernetes.io/worker)
30+
NODE_NAMES=$(oc get node -o template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' -l node-role.kubernetes.io/worker)
2631
if [ -z "$NODE_NAMES" ]; then
2732
echo "Unable to determine node name with 'oc' command."
2833
exit 1
2934
fi
3035
for node in $NODE_NAMES; do
31-
oc debug $node -T -- chroot /host /usr/bin/bash -c "for i in `seq -w -s ' ' $PV_NUM`; do echo \"creating dir /mnt/openstack/pv\$i on $node\"; mkdir -p /mnt/openstack/pv\$i; done"
36+
. "${SCRIPTPATH}/storage_apply.sh" "${node}" "create"
3237
done
38+
39+
oc wait job -n "${NAMESPACE}" -l install-yamls.crc.storage --for condition=Complete --timeout "${TIMEOUT}"

scripts/delete-pv.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616
set -ex
17+
18+
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19+
. "${SCRIPTPATH}/storage_common.sh"
20+
1721
PV_NUM=${PV_NUM:-12}
22+
TIMEOUT=${TIMEOUT:-300s}
1823

19-
NODE_NAMES=$(oc get node -o name -l node-role.kubernetes.io/worker)
24+
NODE_NAMES=$(oc get node -o template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' -l node-role.kubernetes.io/worker)
2025
if [ -z "$NODE_NAMES" ]; then
2126
echo "Unable to determine node name with 'oc' command."
2227
exit 1
2328
fi
2429
for node in $NODE_NAMES; do
25-
oc debug $node -T -- chroot /host /usr/bin/bash -c "for i in `seq -w -s ' ' $PV_NUM`; do echo \"deleting dir /mnt/openstack/pv\$i on $node\"; rm -rf /mnt/openstack/pv\$i; done"
30+
. "${SCRIPTPATH}/storage_apply.sh" "${node}" "delete"
2631
done
32+
33+
oc wait job -n "${NAMESPACE}" -l install-yamls.crc.storage --for condition=Complete --timeout "${TIMEOUT}"

scripts/storage_apply.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2025 Red Hat Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
set -ex
17+
18+
NODE=${1:-"crc"}
19+
OPERATION=${2:-"create"}
20+
21+
oc delete -n "${NAMESPACE}" job "crc-storage-${NODE}" --ignore-not-found
22+
23+
cat << EOF | oc apply -f -
24+
apiVersion: batch/v1
25+
kind: Job
26+
metadata:
27+
name: crc-storage-${NODE}
28+
namespace: ${NAMESPACE}
29+
labels:
30+
install-yamls.crc.storage: ""
31+
spec:
32+
template:
33+
spec:
34+
containers:
35+
- name: storage
36+
image: bash:latest
37+
env:
38+
- name: PV_NUM
39+
value: "${PV_NUM}"
40+
command: ["bash"]
41+
args: ["/usr/local/bin/crc-storage.sh"]
42+
securityContext:
43+
privileged: true
44+
allowPrivilegeEscalation: true
45+
runAsUser: 0
46+
seccompProfile:
47+
type: RuntimeDefault
48+
volumeMounts:
49+
- mountPath: /usr/local/bin/crc-storage.sh
50+
name: crc-storage
51+
readOnly: true
52+
subPath: ${OPERATION}-storage.sh
53+
- name: node-mnt
54+
mountPath: /mnt/nodeMnt
55+
nodeSelector:
56+
kubernetes.io/hostname: ${NODE}
57+
node-role.kubernetes.io/worker: ""
58+
restartPolicy: Never
59+
securityContext:
60+
runAsUser: 0
61+
serviceAccount: crc-storage
62+
volumes:
63+
- configMap:
64+
defaultMode: 493
65+
items:
66+
- key: ${OPERATION}-storage.sh
67+
path: ${OPERATION}-storage.sh
68+
name: crc-storage
69+
name: crc-storage
70+
- name: node-mnt
71+
hostPath:
72+
path: /mnt
73+
type: Directory
74+
backoffLimit: 10
75+
EOF

scripts/storage_common.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2025 Red Hat Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
set -ex
17+
OPERATION=${1:-"create"}
18+
19+
cat << EOF | oc apply -f -
20+
apiVersion: v1
21+
data:
22+
create-storage.sh: |
23+
#!/bin/bash
24+
25+
for i in \`seq -w -s ' ' \${PV_NUM}\`; do
26+
echo "creating dir /mnt/openstack/pv\$i on host"
27+
mkdir -p /mnt/nodeMnt/openstack/pv\$i
28+
done
29+
delete-storage.sh: |
30+
#!/bin/bash
31+
32+
for i in \`seq -w -s ' ' \${PV_NUM}\`; do
33+
echo "deleting dir /mnt/openstack/pv\$i on host"
34+
rm -rf /mnt/nodeMnt/openstack/pv\$i
35+
done
36+
kind: ConfigMap
37+
metadata:
38+
name: crc-storage
39+
namespace: ${NAMESPACE}
40+
EOF
41+
42+
cat << EOF | oc apply -f -
43+
apiVersion: v1
44+
kind: ServiceAccount
45+
metadata:
46+
name: crc-storage
47+
namespace: ${NAMESPACE}
48+
EOF
49+
50+
cat << EOF | oc apply -f -
51+
apiVersion: rbac.authorization.k8s.io/v1
52+
kind: Role
53+
metadata:
54+
name: crc-storage-role
55+
namespace: ${NAMESPACE}
56+
rules:
57+
- apiGroups:
58+
- security.openshift.io
59+
resourceNames:
60+
- anyuid
61+
- privileged
62+
resources:
63+
- securitycontextconstraints
64+
verbs:
65+
- use
66+
- apiGroups:
67+
- ""
68+
resources:
69+
- pods
70+
- jobs
71+
verbs:
72+
- create
73+
- get
74+
- list
75+
- watch
76+
- update
77+
- patch
78+
- delete
79+
EOF
80+
81+
cat << EOF | oc apply -f -
82+
apiVersion: rbac.authorization.k8s.io/v1
83+
kind: RoleBinding
84+
metadata:
85+
name: crc-storage-rolebinding
86+
namespace: ${NAMESPACE}
87+
roleRef:
88+
apiGroup: rbac.authorization.k8s.io
89+
kind: Role
90+
name: crc-storage-role
91+
subjects:
92+
- kind: ServiceAccount
93+
name: crc-storage
94+
namespace: ${NAMESPACE}
95+
EOF

0 commit comments

Comments
 (0)