Skip to content

Commit 5a3e543

Browse files
committed
removed usage of pull-secret.
command now generates directly an exit code file. random namespace generation. config file name customizable.
1 parent 3615943 commit 5a3e543

File tree

3 files changed

+53
-34
lines changed

3 files changed

+53
-34
lines changed

docs/user/agent/add-nodes.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
## Pre-requisites
44
1. The `oc` tool must be available in the execution environment (the "user host").
55
2. The user host has a valid network connection to the target OpenShift cluster to be expanded.
6-
3. The user host has a valid pull-secret.
76

87
## Setup
98
1. Download the [node-joiner.sh](./node-joiner.sh) script in a working directory in
@@ -66,16 +65,24 @@ hosts:
6665
macAddress: 00:02:46:e3:9e:9c
6766
6867
## ISO generation
69-
Run the [node-joiner.sh](./node-joiner.sh) by specifying the location of the current pull secret:
68+
Run the [node-joiner.sh](./node-joiner.sh):
7069
```bash
71-
$ ./node-joiner.sh ~/config/pull-secret
70+
$ ./node-joiner.sh
7271
```
73-
The script will generate a temporary namespace `openshift-node-joiner` in the target cluster,
72+
The script will generate a temporary namespace prefixed with `openshift-node-joiner` in the target cluster,
7473
where a pod will be launched to execute the effective node-joiner workload.
7574
In case of success, the `agent-addnodes.x86_64.iso` ISO image will be downloaded in the assets folder.
7675

76+
### Configuration file name
77+
By default the script looks for a configuration file named `nodes-config.yaml`. It's possible to specify a
78+
different config file name, as the first parameter of the script:
79+
80+
```bash
81+
$ ./node-joiner.sh config.yaml
82+
```
83+
7784
## Nodes joining
78-
Use the iso image to boot all the nodes listed in the `nodes-config.yaml` file, and wait for the related
85+
Use the iso image to boot all the nodes listed in the configuration file, and wait for the related
7986
certificate signing requests (CSRs) to appear. When adding a new node to the cluster, two pending CSRs will
8087
be generated, and they must be manually approved by the user.
8188
Use the following command to monitor the pending certificates:

docs/user/agent/node-joiner.sh

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
#!/bin/bash
22

3-
if [ $# -lt 1 ]; then
4-
echo "./node-joiner.sh <pull secret path>"
5-
echo "Usage example:"
6-
echo "$ ./node-joiner.sh ~/config/my-pull-secret"
3+
set -eu
74

8-
exit 1
5+
# Config file
6+
nodesConfigFile=${1:-"nodes-config.yaml"}
7+
if [ ! -f $nodesConfigFile ]; then
8+
echo "Cannot find the config file $nodesConfigFile"
9+
exit 1
910
fi
10-
pullSecret=$1
11+
12+
# Generate a random namespace name
13+
namespace="openshift-node-joiner-$(cat /dev/urandom | tr -dc 'a-z' | head -c 10)"
1114

1215
# Extract the installer image pullspec and release version.
13-
releaseImage=$(oc get clusterversion version -o=jsonpath='{.status.history[?(@.state == "Completed")].image}')
14-
nodeJoinerPullspec=$(oc adm release info -a "$pullSecret" --image-for=installer "$releaseImage")
16+
nodeJoinerPullspec=$(oc get is installer -n openshift -o=jsonpath='{.spec.tags[0].from.name}')
1517

1618
# Create the namespace to run the node-joiner, along with the required roles and bindings.
1719
staticResources=$(cat <<EOF
1820
apiVersion: v1
1921
kind: Namespace
2022
metadata:
21-
name: openshift-node-joiner
23+
name: ${namespace}
2224
---
2325
apiVersion: v1
2426
kind: ServiceAccount
2527
metadata:
2628
name: node-joiner
27-
namespace: openshift-node-joiner
29+
namespace: ${namespace}
2830
---
2931
apiVersion: rbac.authorization.k8s.io/v1
3032
kind: ClusterRole
@@ -55,7 +57,7 @@ metadata:
5557
subjects:
5658
- kind: ServiceAccount
5759
name: node-joiner
58-
namespace: openshift-node-joiner
60+
namespace: ${namespace}
5961
roleRef:
6062
kind: ClusterRole
6163
name: node-joiner
@@ -65,15 +67,15 @@ EOF
6567
echo "$staticResources" | oc apply -f -
6668

6769
# Generate a configMap to store the user configuration
68-
oc create configmap nodes-config --from-file=nodes-config.yaml -n openshift-node-joiner -o yaml --dry-run=client | oc apply -f -
70+
oc create configmap nodes-config --from-file=nodes-config.yaml=${nodesConfigFile} -n ${namespace} -o yaml --dry-run=client | oc apply -f -
6971

7072
# Runt the node-joiner pod to generate the ISO
7173
nodeJoinerPod=$(cat <<EOF
7274
apiVersion: v1
7375
kind: Pod
7476
metadata:
7577
name: node-joiner
76-
namespace: openshift-node-joiner
78+
namespace: ${namespace}
7779
annotations:
7880
openshift.io/scc: anyuid
7981
labels:
@@ -93,39 +95,36 @@ spec:
9395
mountPath: /config
9496
- name: assets
9597
mountPath: /assets
96-
command: ["/bin/sh", "-c", "cp /config/nodes-config.yaml /assets; HOME=/assets node-joiner add-nodes --dir=/assets --log-level=debug; echo \$? > /assets/completed; sleep 600"]
98+
command: ["/bin/sh", "-c", "cp /config/nodes-config.yaml /assets; HOME=/assets node-joiner add-nodes --dir=/assets --log-level=debug; sleep 600"]
9799
volumes:
98100
- name: nodes-config
99101
configMap:
100102
name: nodes-config
101-
namespace: openshift-node-joiner
103+
namespace: ${namespace}
102104
- name: assets
103105
emptyDir:
104106
sizeLimit: "4Gi"
105107
EOF
106108
)
107109
echo "$nodeJoinerPod" | oc apply -f -
108110

109-
# Wait until the node-joiner was completed.
110111
while true; do
111-
if oc exec node-joiner -n openshift-node-joiner -- test -e /assets/completed >/dev/null 2>&1; then
112+
if oc exec node-joiner -n ${namespace} -- test -e /assets/exit_code >/dev/null 2>&1; then
112113
break
113114
else
114115
echo "Waiting for node-joiner pod to complete..."
115116
sleep 10s
116117
fi
117118
done
118119

119-
# In case of success, let's extract the ISO, otherwise the logs are shown for troubleshooting the error.
120-
completed=$(oc exec node-joiner -n openshift-node-joiner -- cat /assets/completed)
121-
if [ "$completed" = 0 ]; then
120+
res=$(oc exec node-joiner -n ${namespace} -- cat /assets/exit_code)
121+
if [ "$res" = 0 ]; then
122122
echo "node-joiner successfully completed, extracting ISO image..."
123-
oc cp -n openshift-node-joiner node-joiner:/assets/agent-addnodes.x86_64.iso agent-addnodes.x86_64.iso
123+
oc cp -n ${namespace} node-joiner:/assets/agent-addnodes.x86_64.iso agent-addnodes.x86_64.iso
124124
else
125-
oc logs node-joiner -n openshift-node-joiner
125+
oc logs node-joiner -n ${namespace}
126126
echo "node-joiner failed"
127127
fi
128128

129-
# Remove all the resources previously created.
130129
echo "Cleaning up"
131-
oc delete namespace openshift-node-joiner --grace-period=0 >/dev/null 2>&1 &
130+
oc delete namespace "${namespace}" --grace-period=0 >/dev/null 2>&1 &

pkg/nodejoiner/addnodes.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package nodejoiner
22

33
import (
4-
"context"
4+
"os"
5+
"path/filepath"
56

67
"github.com/openshift/installer/pkg/asset"
78
"github.com/openshift/installer/pkg/asset/agent/image"
@@ -10,6 +11,10 @@ import (
1011
"github.com/openshift/installer/pkg/asset/store"
1112
)
1213

14+
const (
15+
addNodesResultFile = "exit_code"
16+
)
17+
1318
// NewAddNodesCommand creates a new command for add nodes.
1419
func NewAddNodesCommand(directory string, kubeConfig string) error {
1520
// Store the current parameters into the assets folder, so
@@ -22,12 +27,20 @@ func NewAddNodesCommand(directory string, kubeConfig string) error {
2227
return err
2328
}
2429

25-
ctx := context.Background()
26-
2730
fetcher := store.NewAssetsFetcher(directory)
28-
return fetcher.FetchAndPersist(ctx, []asset.WritableAsset{
31+
err = fetcher.FetchAndPersist([]asset.WritableAsset{
2932
&workflow.AgentWorkflowAddNodes{},
3033
&image.AgentImage{},
31-
// To be completed
3234
})
35+
36+
// Save the exit code result
37+
exitCode := "0"
38+
if err != nil {
39+
exitCode = "1"
40+
}
41+
if err2 := os.WriteFile(filepath.Join(directory, addNodesResultFile), []byte(exitCode), 0644); err2 != nil {
42+
return err2
43+
}
44+
45+
return err
3346
}

0 commit comments

Comments
 (0)