-
Notifications
You must be signed in to change notification settings - Fork 1.5k
AGENT-906: Script to run monitor-add-nodes in cluster #8294
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -eu | ||
|
|
||
| if [ $# -eq 0 ]; then | ||
| echo "At least one IP address must be provided" | ||
| exit 1 | ||
| fi | ||
|
|
||
| ipAddresses=$@ | ||
|
|
||
| # Setup a cleanup function to ensure to remove the temporary | ||
| # file when the script will be completed. | ||
| cleanup() { | ||
| if [ -f "$pullSecretFile" ]; then | ||
| echo "Removing temporary file $pullSecretFile" | ||
| rm "$pullSecretFile" | ||
| fi | ||
| } | ||
| trap cleanup EXIT TERM | ||
|
|
||
| # Retrieve the pullsecret and store it in a temporary file. | ||
| pullSecretFile=$(mktemp -p "/tmp" -t "nodejoiner-XXXXXXXXXX") | ||
| oc get secret -n openshift-config pull-secret -o jsonpath='{.data.\.dockerconfigjson}' | base64 -d > "$pullSecretFile" | ||
|
|
||
| # Extract the baremetal-installer image pullspec from the current cluster. | ||
| nodeJoinerPullspec=$(oc adm release info --image-for=baremetal-installer --registry-config="$pullSecretFile") | ||
|
|
||
| # Use the same random temp file suffix for the namespace. | ||
| namespace=$(echo "openshift-node-joiner-${pullSecretFile#/tmp/nodejoiner-}" | tr '[:upper:]' '[:lower:]') | ||
|
|
||
| # Create the namespace to run the node-joiner-monitor, along with the required roles and bindings. | ||
| staticResources=$(cat <<EOF | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| name: ${namespace} | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: node-joiner-monitor | ||
| namespace: ${namespace} | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: node-joiner-monitor | ||
| rules: | ||
| - apiGroups: | ||
| - certificates.k8s.io | ||
| resources: | ||
| - certificatesigningrequests | ||
| verbs: | ||
| - get | ||
| - list | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - pods | ||
| - nodes | ||
| verbs: | ||
| - get | ||
| - list | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: node-joiner-monitor | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: node-joiner-monitor | ||
| namespace: ${namespace} | ||
| roleRef: | ||
| kind: ClusterRole | ||
| name: node-joiner-monitor | ||
| apiGroup: rbac.authorization.k8s.io | ||
| EOF | ||
| ) | ||
| echo "$staticResources" | oc apply -f - | ||
|
|
||
| # Run the node-joiner-monitor to monitor node joining cluster | ||
| nodeJoinerPod=$(cat <<EOF | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: node-joiner-monitor | ||
| namespace: ${namespace} | ||
| annotations: | ||
| openshift.io/scc: anyuid | ||
| labels: | ||
| app: node-joiner-monitor | ||
| spec: | ||
| restartPolicy: Never | ||
| serviceAccountName: node-joiner-monitor | ||
| securityContext: | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| containers: | ||
| - name: node-joiner-monitor | ||
| imagePullPolicy: IfNotPresent | ||
| image: $nodeJoinerPullspec | ||
| command: ["/bin/sh", "-c", "node-joiner monitor-add-nodes $ipAddresses --log-level=info; sleep 5"] | ||
| EOF | ||
| ) | ||
| echo "$nodeJoinerPod" | oc apply -f - | ||
|
|
||
| oc project "${namespace}" | ||
|
|
||
| oc wait --for=condition=Ready=true --timeout=300s pod/node-joiner-monitor | ||
|
|
||
| oc logs -f -n "${namespace}" node-joiner-monitor | ||
|
||
|
|
||
| echo "Cleaning up" | ||
| oc delete namespace "${namespace}" --grace-period=0 >/dev/null 2>&1 & | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed that below there's a small pre-existing typo,
Userinstead ofuse