Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cmd/openshift-install/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,19 @@ var (
},
}

agentTargets = []target{agentConfigTarget, agentManifestsTarget, agentImageTarget, agentPXEFilesTarget, agentConfigImageTarget, agentUnconfiguredIgnitionTarget}
agentImageAddNodesTarget = target{
name: "Agent ISO Image for adding nodes",
command: &cobra.Command{
Use: "nodes-image",
Short: "Generates a bootable image containing all the information needed to added one or more nodes to an already existing cluster",
Args: cobra.ExactArgs(0),
},
assets: []asset.WritableAsset{
&image.AgentImage{},
},
}

agentTargets = []target{agentConfigTarget, agentManifestsTarget, agentImageTarget, agentPXEFilesTarget, agentConfigImageTarget, agentUnconfiguredIgnitionTarget, agentImageAddNodesTarget}
)

func newAgentCreateCmd() *cobra.Command {
Expand Down
2 changes: 2 additions & 0 deletions data/data/agent/files/usr/local/bin/get-container-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ set -euo pipefail
# The agent image will be also retrieved when its script is run
cat <<EOF >/usr/local/share/assisted-service/agent-images.env
SERVICE_IMAGE=$(image_for agent-installer-api-server)
# TODO: remove when assisted-service changes to import cluster merges
SERVICE_IMAGE=quay.io/rwsu1/assisted-service:latest
CONTROLLER_IMAGE=$(image_for agent-installer-csr-approver)
INSTALLER_IMAGE=$(image_for agent-installer-orchestrator)
AGENT_DOCKER_IMAGE=$(image_for agent-installer-node-agent)
Expand Down
11 changes: 11 additions & 0 deletions data/data/agent/files/usr/local/bin/import-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

echo "Waiting for assisted-service to be ready"
until curl --output /dev/null --silent --fail "${SERVICE_BASE_URL}/api/assisted-install/v2/infra-envs"; do
printf '.'
sleep 5
done

echo "Importing cluster from ${API_VIP_DNSNAME}"
curl -d '{"name":"abi", "api_vip_dnsname":"'"${API_VIP_DNSNAME}"'", "openshift_cluster_id":"764eb48f-8ffb-4126-b7ed-0ca746365654"}' -H "Content-Type: application/json" -X POST "${SERVICE_BASE_URL}/api/assisted-install/v2/clusters/import"
58 changes: 35 additions & 23 deletions data/data/agent/files/usr/local/bin/start-cluster-installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,45 @@ num_known_hosts() {

while [[ "${total_required_nodes}" != $(num_known_hosts) ]]
do

# For some reason the initial role patching doesn't seem to work properly, to be reviewed
echo "Patching host..."
export HOST_ID=$(curl -s ${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts | jq -r '.[].id')
curl -X PATCH -d '{"host_role":"worker"}' -H "Content-Type: application/json" ${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts/${HOST_ID}

echo "Waiting for hosts to become ready for cluster installation..." 1>&2
sleep 10
done

echo "All ${total_required_nodes} hosts are ready." 1>&2
clear_issue "${status_issue}"

while [[ "${cluster_status}" != "installed" ]]
do
sleep 5
cluster_status=$(curl -s -S "${BASE_URL}/clusters" | jq -r .[].status)
echo "Cluster status: ${cluster_status}" 1>&2
# Start the cluster install, if it transitions back to Ready due to a failure,
# then it will be restarted
case "${cluster_status}" in
"ready")
echo "Starting cluster installation..." 1>&2
curl -s -S -X POST "${BASE_URL}/clusters/${cluster_id}/actions/install" \
-H 'accept: application/json' \
-d ''
echo "Cluster installation started" 1>&2
;&
"installed" | "preparing-for-installation" | "installing")
printf '\\e{lightgreen}Cluster installation in progress\\e{reset}' | set_issue "${status_issue}"
;;
*)
printf '\\e{lightred}Installation cannot proceed:\\e{reset} Cluster status: %s' "${cluster_status}" | set_issue "${status_issue}"
;;
esac
done
# Install the host
# echo "Installing host..."
# curl -X POST ${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts/${HOST_ID}/actions/install
# TODO: temporary to test cluster import without initiating install
echo "RWSU skip Installing host..."

# while [[ "${cluster_status}" != "installed" ]]
# do
# sleep 5
# cluster_status=$(curl -s -S "${BASE_URL}/clusters" | jq -r .[].status)
# echo "Cluster status: ${cluster_status}" 1>&2
# # Start the cluster install, if it transitions back to Ready due to a failure,
# # then it will be restarted
# case "${cluster_status}" in
# "ready")
# echo "Starting cluster installation..." 1>&2
# curl -s -S -X POST "${BASE_URL}/clusters/${cluster_id}/actions/install" \
# -H 'accept: application/json' \
# -d ''
# echo "Cluster installation started" 1>&2
# ;&
# "installed" | "preparing-for-installation" | "installing")
# printf '\\e{lightgreen}Cluster installation in progress\\e{reset}' | set_issue "${status_issue}"
# ;;
# *)
# printf '\\e{lightred}Installation cannot proceed:\\e{reset} Cluster status: %s' "${cluster_status}" | set_issue "${status_issue}"
# ;;
# esac
# done
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ASSISTED_SERVICE_HOST=localhost:8090
ASSISTED_SERVICE_SCHEME={{.ServiceProtocol}}
OS_IMAGES=[{"openshift_version":"{{.OSImage.OpenshiftVersion}}","cpu_architecture":"{{.OSImage.CPUArchitecture}}","url":"{{.OSImage.URL}}","version":"{{.OSImage.Version}}"}]
# TODO: temporary to test on specific version
OS_IMAGES=[{"openshift_version":"{{.OSImage.OpenshiftVersion}}","cpu_architecture":"{{.OSImage.CPUArchitecture}}","url":"{{.OSImage.URL}}","version":"{{.OSImage.Version}}"},{"openshift_version":"4.15.0-rc.2","cpu_architecture":"x86_64","url":"https://rhcos.mirror.openshift.com/art/storage/prod/streams/4.14-9.2/builds/414.92.202307070025-0/x86_64/rhcos-414.92.202307070025-0-live.x86_64.iso","version":"414.92.202307070025-0"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CLUSTER_ID=d8fc9f93-1b33-4b2a-943f-54afca271cb2
CLUSTER_NAME=abi
CLUSTER_API_VIP_DNS_NAME=api.ostest.test.metalkube.org
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REQUIRED_MASTER_NODES={{.ControlPlaneAgents}}
REQUIRED_WORKER_NODES={{.WorkerAgents}}
REQUIRED_WORKER_NODES=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Unit]
Description=Service that imports the cluster
Wants=network-online.target assisted-service.service
PartOf=assisted-service-pod.service
After=network-online.target assisted-service.service
ConditionPathExists=/etc/assisted/node0

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Environment=OPENSHIFT_INSTALL_RELEASE_IMAGE_MIRROR={{.ReleaseImageMirror}}
EnvironmentFile=/etc/assisted/rendezvous-host.env
EnvironmentFile=/usr/local/share/assisted-service/agent-images.env
EnvironmentFile=/usr/local/share/import-cluster/import-cluster.env
ExecStartPre=/usr/local/bin/wait-for-assisted-service.sh
ExecStartPre=/bin/rm -f %t/%n.ctr-id
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 CLUSTER_ID --env CLUSTER_NAME --env CLUSTER_API_VIP_DNS_NAME $SERVICE_IMAGE /usr/local/bin/agent-installer-client importCluster
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id

KillMode=none
Type=oneshot
Restart=on-failure
RestartSec=30
RemainAfterExit=true

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Description=Service that registers the infraenv
Wants=network-online.target assisted-service.service
PartOf=assisted-service-pod.service
After=network-online.target assisted-service.service agent-register-cluster.service
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 }}
ConditionPathExists=/etc/assisted/node0

[Service]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ Environment=PODMAN_SYSTEMD_UNIT=%n
EnvironmentFile=/etc/assisted/rendezvous-host.env
EnvironmentFile=/usr/local/share/assisted-service/agent-images.env
EnvironmentFile=/usr/local/share/assisted-service/assisted-service.env
Environment=WORKFLOW_TYPE={{.WorkflowType}}
ExecStartPre=/bin/rm -f %t/%n.ctr-id
ExecStartPre=/bin/mkdir -p %t/agent-installer /etc/assisted/hostconfig
ExecStartPre=/usr/local/bin/wait-for-assisted-service.sh
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
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
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id

Expand Down
15 changes: 12 additions & 3 deletions pkg/asset/agent/image/agentimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type AgentImage struct {
rootFSURL string
bootArtifactsBaseURL string
platform hiveext.PlatformType
kubeconfig *manifests.KubeConfigFile
}

var _ asset.WritableAsset = (*AgentImage)(nil)
Expand All @@ -42,6 +43,7 @@ func (a *AgentImage) Dependencies() []asset.Asset {
&AgentArtifacts{},
&manifests.AgentManifests{},
&BaseIso{},
&manifests.KubeConfigFile{},
}
}

Expand All @@ -50,21 +52,24 @@ func (a *AgentImage) Generate(dependencies asset.Parents) error {
agentArtifacts := &AgentArtifacts{}
agentManifests := &manifests.AgentManifests{}
baseIso := &BaseIso{}
dependencies.Get(agentArtifacts, agentManifests, baseIso)
kubeconfig := &manifests.KubeConfigFile{}
dependencies.Get(agentArtifacts, agentManifests, baseIso, kubeconfig)

a.cpuArch = agentArtifacts.CPUArch
a.rendezvousIP = agentArtifacts.RendezvousIP
a.tmpPath = agentArtifacts.TmpPath
a.isoPath = agentArtifacts.ISOPath
a.bootArtifactsBaseURL = agentArtifacts.BootArtifactsBaseURL
a.kubeconfig = kubeconfig

volumeID, err := isoeditor.VolumeIdentifier(a.isoPath)
if err != nil {
return err
}
a.volumeID = volumeID

a.platform = agentManifests.AgentClusterInstall.Spec.PlatformType
// a.platform = agentManifests.AgentClusterInstall.Spec.PlatformType
a.platform = "BareMetal"
if a.platform == hiveext.ExternalPlatformType {
// when the bootArtifactsBaseURL is specified, construct the custom rootfs URL
if a.bootArtifactsBaseURL != "" {
Expand Down Expand Up @@ -214,7 +219,11 @@ func (a *AgentImage) PersistToFile(directory string) error {
return errors.New("cannot generate ISO image due to configuration errors")
}

agentIsoFile := filepath.Join(directory, fmt.Sprintf(agentISOFilename, a.cpuArch))
name := fmt.Sprintf(agentISOFilename, a.cpuArch)
if a.kubeconfig != nil {
name = "workers-" + name
}
agentIsoFile := filepath.Join(directory, name)

// Remove symlink if it exists
os.Remove(agentIsoFile)
Expand Down
Loading