Skip to content

Commit 54d9c8e

Browse files
Merge pull request #8093 from andfasano/agent-day2-ignition-services
AGENT-858: Agent day2 ignition services
2 parents 0d88d59 + cac843c commit 54d9c8e

21 files changed

+669
-119
lines changed

cmd/node-joiner/main.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package main
22

33
import (
4+
"fmt"
5+
"io"
6+
"os"
7+
48
"github.com/sirupsen/logrus"
59
"github.com/spf13/cobra"
10+
terminal "golang.org/x/term"
611

12+
"github.com/openshift/installer/cmd/openshift-install/command"
713
"github.com/openshift/installer/pkg/nodejoiner"
814
)
915

@@ -33,14 +39,47 @@ func main() {
3339
}
3440

3541
rootCmd := &cobra.Command{
36-
Use: "node-joiner",
42+
Use: "node-joiner",
43+
PersistentPreRun: runRootCmd,
3744
}
3845
rootCmd.PersistentFlags().String("kubeconfig", "", "Path to the kubeconfig file.")
3946
rootCmd.PersistentFlags().String("dir", ".", "assets directory")
47+
rootCmd.PersistentFlags().String("log-level", "info", "log level (e.g. \"debug | info | warn | error\")")
4048

4149
rootCmd.AddCommand(nodesAddCmd)
4250
rootCmd.AddCommand(nodesMonitorCmd)
4351
if err := rootCmd.Execute(); err != nil {
4452
logrus.Fatal(err)
4553
}
4654
}
55+
56+
func runRootCmd(cmd *cobra.Command, args []string) {
57+
logrus.SetOutput(io.Discard)
58+
logrus.SetLevel(logrus.TraceLevel)
59+
60+
logLevel, err := cmd.Flags().GetString("log-level")
61+
if err != nil {
62+
logrus.Fatal(err)
63+
}
64+
65+
level, err := logrus.ParseLevel(logLevel)
66+
if err != nil {
67+
level = logrus.InfoLevel
68+
}
69+
70+
logrus.AddHook(command.NewFileHookWithNewlineTruncate(os.Stderr, level, &logrus.TextFormatter{
71+
// Setting ForceColors is necessary because logrus.TextFormatter determines
72+
// whether or not to enable colors by looking at the output of the logger.
73+
// In this case, the output is io.Discard, which is not a terminal.
74+
// Overriding it here allows the same check to be done, but against the
75+
// hook's output instead of the logger's output.
76+
ForceColors: terminal.IsTerminal(int(os.Stderr.Fd())),
77+
DisableTimestamp: true,
78+
DisableLevelTruncation: true,
79+
DisableQuote: true,
80+
}))
81+
82+
if err != nil {
83+
logrus.Fatal(fmt.Errorf("invalid log-level: %w", err))
84+
}
85+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# shellcheck disable=SC1091
5+
source issue_status.sh
6+
7+
BASE_URL="${SERVICE_BASE_URL}api/assisted-install/v2"
8+
9+
cluster_id=""
10+
while [[ "${cluster_id}" = "" ]]
11+
do
12+
# Get cluster id
13+
cluster_id=$(curl -s -S "${BASE_URL}/clusters" | jq -r .[].id)
14+
if [[ "${cluster_id}" = "" ]]; then
15+
sleep 2
16+
fi
17+
done
18+
19+
printf '\nInfra env id is %s\n' "${INFRA_ENV_ID}" 1>&2
20+
21+
status_issue="90_add-node"
22+
23+
# Wait for the current host to be ready
24+
host_ready=false
25+
while [[ $host_ready == false ]]
26+
do
27+
host_status=$(curl -s -S "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts" | jq -r ".[].status")
28+
if [[ "${host_status}" != "known" ]]; then
29+
printf '\\e{yellow}Waiting for the host to be ready' | set_issue "${status_issue}"
30+
sleep 10
31+
else
32+
host_ready=true
33+
fi
34+
done
35+
36+
HOST_ID=$(curl -s "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts" | jq -r '.[].id')
37+
printf '\nHost %s is ready for installation\n' "${HOST_ID}" 1>&2
38+
clear_issue "${status_issue}"
39+
40+
# Add the current host to the cluster
41+
res=$(curl -X POST -s -S -w "%{http_code}\\n" -o /dev/null "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts/${HOST_ID}/actions/install")
42+
if [[ $res = "202" ]]; then
43+
printf '\nHost installation started\n' 1>&2
44+
else
45+
printf '\nHost installation failed\n' 1>&2
46+
exit 1
47+
fi
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Unit]
2+
Description=Adds the current node to an already existing cluster
3+
Wants=network-online.target
4+
Requires=apply-host-config.service
5+
PartOf=assisted-service-pod.service
6+
After=network-online.target apply-host-config.service
7+
ConditionPathExists=/etc/assisted/node0
8+
9+
[Service]
10+
EnvironmentFile=/usr/local/share/assisted-service/assisted-service.env
11+
EnvironmentFile=/usr/local/share/start-cluster/start-cluster.env
12+
EnvironmentFile=/etc/assisted/rendezvous-host.env
13+
ExecStartPre=/usr/local/bin/wait-for-assisted-service.sh
14+
ExecStart=/usr/local/bin/add-node.sh
15+
16+
KillMode=none
17+
Type=oneshot
18+
RemainAfterExit=true
19+
20+
[Install]
21+
WantedBy=multi-user.target
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[Unit]
2+
Description=Imports an already existing cluster
3+
Wants=network-online.target assisted-service.service
4+
PartOf=assisted-service-pod.service
5+
After=network-online.target assisted-service.service
6+
ConditionPathExists=/etc/assisted/node0
7+
8+
[Service]
9+
Environment=PODMAN_SYSTEMD_UNIT=%n
10+
Environment=OPENSHIFT_INSTALL_RELEASE_IMAGE_MIRROR={{.ReleaseImageMirror}}
11+
EnvironmentFile=/etc/assisted/rendezvous-host.env
12+
EnvironmentFile=/usr/local/share/assisted-service/agent-images.env
13+
EnvironmentFile=/usr/local/share/assisted-service/assisted-service.env
14+
EnvironmentFile=/etc/assisted/add-nodes.env
15+
ExecStartPre=/bin/rm -f %t/%n.ctr-id
16+
ExecStartPre=/usr/local/bin/wait-for-assisted-service.sh
17+
ExecStart=podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --rm --pod-id-file=%t/assisted-service-pod.pod-id --replace --name=agent-import-cluster -v /etc/assisted/manifests:/manifests -v /etc/assisted/extra-manifests:/extra-manifests -v /etc/pki/ca-trust:/etc/pki/ca-trust:z {{ if .HaveMirrorConfig }}-v /etc/containers:/etc/containers{{ end }} --env SERVICE_BASE_URL --env OPENSHIFT_INSTALL_RELEASE_IMAGE_MIRROR --env CLUSTER_ID --env CLUSTER_NAME --env CLUSTER_API_VIP_DNS_NAME $SERVICE_IMAGE /usr/local/bin/agent-installer-client importCluster
18+
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
19+
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
20+
21+
KillMode=none
22+
Type=oneshot
23+
Restart=on-failure
24+
RestartSec=30
25+
RemainAfterExit=true
26+
27+
[Install]
28+
WantedBy=multi-user.target

data/data/agent/systemd/units/agent-register-infraenv.service.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Description=Service that registers the infraenv
33
Wants=network-online.target assisted-service.service
44
PartOf=assisted-service-pod.service
5-
After=network-online.target assisted-service.service agent-register-cluster.service
5+
After=network-online.target assisted-service.service {{ if eq .WorkflowType "install" }}agent-register-cluster.service{{ end }}{{ if eq .WorkflowType "addnodes" }}agent-import-cluster.service{{ end }}
66
ConditionPathExists=/etc/assisted/node0
77

88
[Service]

data/data/agent/systemd/units/apply-host-config.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ EnvironmentFile=/usr/local/share/assisted-service/assisted-service.env
1414
ExecStartPre=/bin/rm -f %t/%n.ctr-id
1515
ExecStartPre=/bin/mkdir -p %t/agent-installer /etc/assisted/hostconfig
1616
ExecStartPre=/usr/local/bin/wait-for-assisted-service.sh
17-
ExecStart=podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --restart=on-failure:10 --pod-id-file=%t/assisted-service-pod.pod-id --replace --name=apply-host-config -v /etc/assisted/hostconfig:/etc/assisted/hostconfig -v %t/agent-installer:/var/run/agent-installer:z --env SERVICE_BASE_URL --env INFRA_ENV_ID $SERVICE_IMAGE /usr/local/bin/agent-installer-client configure
17+
ExecStart=podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --restart=on-failure:10 --pod-id-file=%t/assisted-service-pod.pod-id --replace --name=apply-host-config -v /etc/assisted/hostconfig:/etc/assisted/hostconfig -v %t/agent-installer:/var/run/agent-installer:z --env SERVICE_BASE_URL --env INFRA_ENV_ID --env WORKFLOW_TYPE $SERVICE_IMAGE /usr/local/bin/agent-installer-client configure
1818
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
1919
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
2020

hack/build-node-joiner.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
# shellcheck disable=SC2068
6+
version() { IFS="."; printf "%03d%03d%03d\\n" $@; unset IFS;}
7+
8+
minimum_go_version=1.21
9+
current_go_version=$(go version | cut -d " " -f 3)
10+
11+
if [ "$(version "${current_go_version#go}")" -lt "$(version "$minimum_go_version")" ]; then
12+
echo "Go version should be greater or equal to $minimum_go_version"
13+
exit 1
14+
fi
15+
16+
export CGO_ENABLED=0
17+
MODE="${MODE:-release}"
18+
19+
GIT_COMMIT="${SOURCE_GIT_COMMIT:-$(git rev-parse --verify 'HEAD^{commit}')}"
20+
GIT_TAG="${BUILD_VERSION:-$(git describe --always --abbrev=40 --dirty)}"
21+
DEFAULT_ARCH="${DEFAULT_ARCH:-amd64}"
22+
GOFLAGS="${GOFLAGS:--mod=vendor}"
23+
GCFLAGS=""
24+
LDFLAGS="${LDFLAGS} -X github.com/openshift/installer/pkg/version.Raw=${GIT_TAG} -X github.com/openshift/installer/pkg/version.Commit=${GIT_COMMIT} -X github.com/openshift/installer/pkg/version.defaultArch=${DEFAULT_ARCH}"
25+
TAGS="${TAGS:-}"
26+
OUTPUT="${OUTPUT:-bin/node-joiner}"
27+
28+
case "${MODE}" in
29+
release)
30+
LDFLAGS="${LDFLAGS} -s -w"
31+
TAGS="${TAGS} release"
32+
;;
33+
dev)
34+
GCFLAGS="${GCFLAGS} all=-N -l"
35+
;;
36+
*)
37+
echo "unrecognized mode: ${MODE}" >&2
38+
exit 1
39+
esac
40+
41+
if test "${SKIP_GENERATION}" != y
42+
then
43+
# this step has to be run natively, even when cross-compiling
44+
GOOS='' GOARCH='' go generate ./data
45+
fi
46+
47+
echo "building node-joiner"
48+
49+
# shellcheck disable=SC2086
50+
go build ${GOFLAGS} -gcflags "${GCFLAGS}" -ldflags "${LDFLAGS}" -tags "${TAGS}" -o "${OUTPUT}" ./cmd/node-joiner

pkg/asset/agent/image/agentartifacts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (a *AgentArtifacts) Generate(dependencies asset.Parents) error {
9292
func (a *AgentArtifacts) fetchAgentTuiFiles(releaseImage string, pullSecret string, mirrorConfig []mirror.RegistriesConfig) ([]string, error) {
9393
release := NewRelease(
9494
Config{MaxTries: OcDefaultTries, RetryDelay: OcDefaultRetryDelay},
95-
releaseImage, pullSecret, mirrorConfig)
95+
releaseImage, pullSecret, mirrorConfig, nil)
9696

9797
agentTuiFilenames := []string{"/usr/bin/agent-tui", "/usr/lib64/libnmstate.so.*"}
9898
files := []string{}

pkg/asset/agent/image/agentimage.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020
)
2121

2222
const (
23-
agentISOFilename = "agent.%s.iso"
24-
iso9660Level1ExtLen = 3
23+
agentISOFilename = "agent.%s.iso"
24+
agentAddNodesISOFilename = "agent-addnodes.%s.iso"
25+
iso9660Level1ExtLen = 3
2526
)
2627

2728
// AgentImage is an asset that generates the bootable image used to install clusters.
@@ -34,6 +35,7 @@ type AgentImage struct {
3435
rootFSURL string
3536
bootArtifactsBaseURL string
3637
platform hiveext.PlatformType
38+
isoFilename string
3739
}
3840

3941
var _ asset.WritableAsset = (*AgentImage)(nil)
@@ -61,9 +63,11 @@ func (a *AgentImage) Generate(dependencies asset.Parents) error {
6163
switch agentWorkflow.Workflow {
6264
case workflow.AgentWorkflowTypeInstall:
6365
a.platform = agentManifests.AgentClusterInstall.Spec.PlatformType
66+
a.isoFilename = agentISOFilename
6467

6568
case workflow.AgentWorkflowTypeAddNodes:
6669
a.platform = clusterInfo.PlatformType
70+
a.isoFilename = agentAddNodesISOFilename
6771

6872
default:
6973
return fmt.Errorf("AgentWorkflowType value not supported: %s", agentWorkflow.Workflow)
@@ -239,7 +243,7 @@ func (a *AgentImage) PersistToFile(directory string) error {
239243
return errors.New("cannot generate ISO image due to configuration errors")
240244
}
241245

242-
agentIsoFile := filepath.Join(directory, fmt.Sprintf(agentISOFilename, a.cpuArch))
246+
agentIsoFile := filepath.Join(directory, fmt.Sprintf(a.isoFilename, a.cpuArch))
243247

244248
// Remove symlink if it exists
245249
os.Remove(agentIsoFile)

0 commit comments

Comments
 (0)