From b93d32ca7f093b0fb4628214c8eded4827ab7f02 Mon Sep 17 00:00:00 2001 From: Richard Su Date: Thu, 5 Dec 2024 09:26:37 -0500 Subject: [PATCH] OCPBUGS-45317: node-joiner PXE artifacts should be prefixed "node" instead of "agent". The "agent" prefix is used for the day 1 agent ISO. The "node" prefix is used for day-2 artifacts, both ISO and PXE. --- cmd/node-joiner/testdata/add-nodes-pxe.txt | 14 ++++----- pkg/asset/agent/image/agentartifacts.go | 8 ++++-- pkg/asset/agent/image/agentimage.go | 2 +- pkg/asset/agent/image/agentpxefiles.go | 33 +++++++++++++++------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/cmd/node-joiner/testdata/add-nodes-pxe.txt b/cmd/node-joiner/testdata/add-nodes-pxe.txt index 98cb5f001e2..7680d97fd66 100644 --- a/cmd/node-joiner/testdata/add-nodes-pxe.txt +++ b/cmd/node-joiner/testdata/add-nodes-pxe.txt @@ -3,14 +3,14 @@ exec node-joiner add-nodes --pxe --kubeconfig=$WORK/kubeconfig --log-level=debug --dir=$WORK -exists $WORK/boot-artifacts/agent.x86_64-initrd.img -exists $WORK/boot-artifacts/agent.x86_64-rootfs.img -exists $WORK/boot-artifacts/agent.x86_64-vmlinuz -exists $WORK/boot-artifacts/agent.x86_64.ipxe +exists $WORK/boot-artifacts/node.x86_64-initrd.img +exists $WORK/boot-artifacts/node.x86_64-rootfs.img +exists $WORK/boot-artifacts/node.x86_64-vmlinuz +exists $WORK/boot-artifacts/node.x86_64.ipxe -grep 'initrd --name initrd http://user-specified-pxe-infra.com/agent.x86_64-initrd.img' $WORK/boot-artifacts/agent.x86_64.ipxe -grep 'kernel http://user-specified-pxe-infra.com/agent.x86_64-vmlinuz initrd=initrd coreos.live.rootfs_url=http://user-specified-pxe-infra.com/agent.x86_64-rootfs.img fips=1' $WORK/boot-artifacts/agent.x86_64.ipxe -! grep 'coreos.liveiso=' $WORK/boot-artifacts/agent.x86_64.ipxe +grep 'initrd --name initrd http://user-specified-pxe-infra.com/node.x86_64-initrd.img' $WORK/boot-artifacts/node.x86_64.ipxe +grep 'kernel http://user-specified-pxe-infra.com/node.x86_64-vmlinuz initrd=initrd coreos.live.rootfs_url=http://user-specified-pxe-infra.com/node.x86_64-rootfs.img fips=1' $WORK/boot-artifacts/node.x86_64.ipxe +! grep 'coreos.liveiso=' $WORK/boot-artifacts/node.x86_64.ipxe -- nodes-config.yaml -- bootArtifactsBaseURL: http://user-specified-pxe-infra.com diff --git a/pkg/asset/agent/image/agentartifacts.go b/pkg/asset/agent/image/agentartifacts.go index c08b29bd90d..f6208876264 100644 --- a/pkg/asset/agent/image/agentartifacts.go +++ b/pkg/asset/agent/image/agentartifacts.go @@ -26,6 +26,10 @@ const ( // bootArtifactsPath is the path where boot files are created. // e.g. initrd, kernel and rootfs. bootArtifactsPath = "boot-artifacts" + // agentFilePrefix is the prefix used for day 1 images. + agentFilePrefix = "agent" + // nodeFilePrefix is the prefix used for day 2 images. + nodeFilePrefix = "node" ) // AgentArtifacts is an asset that generates all the artifacts that could be used @@ -241,8 +245,8 @@ func createDir(bootArtifactsFullPath string) error { return nil } -func extractRootFS(bootArtifactsFullPath, agentISOPath, arch string) error { - agentRootfsimgFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("agent.%s-rootfs.img", arch)) +func extractRootFS(bootArtifactsFullPath, agentISOPath, filePrefix, arch string) error { + agentRootfsimgFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("%s.%s-rootfs.img", filePrefix, arch)) rootfsReader, err := os.Open(filepath.Join(agentISOPath, "images", "pxeboot", "rootfs.img")) if err != nil { return err diff --git a/pkg/asset/agent/image/agentimage.go b/pkg/asset/agent/image/agentimage.go index 3f6a043447a..e481492a474 100644 --- a/pkg/asset/agent/image/agentimage.go +++ b/pkg/asset/agent/image/agentimage.go @@ -242,7 +242,7 @@ func (a *AgentImage) PersistToFile(directory string) error { if err != nil { return err } - err = extractRootFS(bootArtifactsFullPath, a.tmpPath, a.cpuArch) + err = extractRootFS(bootArtifactsFullPath, a.tmpPath, agentFilePrefix, a.cpuArch) if err != nil { return err } diff --git a/pkg/asset/agent/image/agentpxefiles.go b/pkg/asset/agent/image/agentpxefiles.go index 610e3c359f9..7389f625215 100644 --- a/pkg/asset/agent/image/agentpxefiles.go +++ b/pkg/asset/agent/image/agentpxefiles.go @@ -16,6 +16,7 @@ import ( "github.com/openshift/assisted-image-service/pkg/isoeditor" "github.com/openshift/installer/pkg/asset" + "github.com/openshift/installer/pkg/asset/agent/workflow" "github.com/openshift/installer/pkg/types" ) @@ -26,6 +27,7 @@ type AgentPXEFiles struct { tmpPath string bootArtifactsBaseURL string kernelArgs string + filePrefix string } type coreOSKargs struct { @@ -38,13 +40,15 @@ var _ asset.WritableAsset = (*AgentPXEFiles)(nil) func (a *AgentPXEFiles) Dependencies() []asset.Asset { return []asset.Asset{ &AgentArtifacts{}, + &workflow.AgentWorkflow{}, } } // Generate generates the image files for PXE asset. func (a *AgentPXEFiles) Generate(_ context.Context, dependencies asset.Parents) error { agentArtifacts := &AgentArtifacts{} - dependencies.Get(agentArtifacts) + agentWorkflow := &workflow.AgentWorkflow{} + dependencies.Get(agentArtifacts, agentWorkflow) a.tmpPath = agentArtifacts.TmpPath @@ -64,6 +68,15 @@ func (a *AgentPXEFiles) Generate(_ context.Context, dependencies asset.Parents) return err } a.kernelArgs = kernelArgs + string(agentArtifacts.Kargs) + + switch agentWorkflow.Workflow { + case workflow.AgentWorkflowTypeInstall: + a.filePrefix = agentFilePrefix + case workflow.AgentWorkflowTypeAddNodes: + a.filePrefix = nodeFilePrefix + default: + return fmt.Errorf("AgentWorkflowType value not supported: %s", agentWorkflow.Workflow) + } return nil } @@ -84,12 +97,12 @@ func (a *AgentPXEFiles) PersistToFile(directory string) error { return err } - err = extractRootFS(bootArtifactsFullPath, a.tmpPath, a.cpuArch) + err = extractRootFS(bootArtifactsFullPath, a.tmpPath, a.filePrefix, a.cpuArch) if err != nil { return err } - agentInitrdFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("agent.%s-initrd.img", a.cpuArch)) + agentInitrdFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("%s.%s-initrd.img", a.filePrefix, a.cpuArch)) err = copyfile(agentInitrdFile, a.imageReader) if err != nil { return err @@ -108,7 +121,7 @@ func (a *AgentPXEFiles) PersistToFile(directory string) error { kernelFileType = "vmlinuz" } - agentVmlinuzFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("agent.%s-%s", a.cpuArch, kernelFileType)) + agentVmlinuzFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("%s.%s-%s", a.filePrefix, a.cpuArch, kernelFileType)) kernelReader, err := os.Open(filepath.Join(a.tmpPath, "images", "pxeboot", kernelFileType)) if err != nil { return err @@ -186,11 +199,11 @@ boot ` iPXEScript := fmt.Sprintf(iPXEScriptTemplate, a.bootArtifactsBaseURL, - fmt.Sprintf("agent.%s-initrd.img", a.cpuArch), a.bootArtifactsBaseURL, - fmt.Sprintf("agent.%s-vmlinuz", a.cpuArch), a.bootArtifactsBaseURL, - fmt.Sprintf("agent.%s-rootfs.img", a.cpuArch), a.kernelArgs) + fmt.Sprintf("%s.%s-initrd.img", a.filePrefix, a.cpuArch), a.bootArtifactsBaseURL, + fmt.Sprintf("%s.%s-vmlinuz", a.filePrefix, a.cpuArch), a.bootArtifactsBaseURL, + fmt.Sprintf("%s.%s-rootfs.img", a.filePrefix, a.cpuArch), a.kernelArgs) - iPXEFile := fmt.Sprintf("agent.%s.ipxe", a.cpuArch) + iPXEFile := fmt.Sprintf("%s.%s.ipxe", a.filePrefix, a.cpuArch) err := os.WriteFile(filepath.Join(pxeAssetsFullPath, iPXEFile), []byte(iPXEScript), 0600) if err != nil { @@ -238,13 +251,13 @@ func (a *AgentPXEFiles) handleAdditionals390xArtifacts(bootArtifactsFullPath str return err } - agentInitrdAddrFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("agent.%s-initrd.addrsize", a.cpuArch)) + agentInitrdAddrFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("%s.%s-initrd.addrsize", a.filePrefix, a.cpuArch)) err = copyfile(agentInitrdAddrFile, addrsizeFile) if err != nil { return err } - agentINSFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("agent.%s-generic.ins", a.cpuArch)) + agentINSFile := filepath.Join(bootArtifactsFullPath, fmt.Sprintf("%s.%s-generic.ins", a.filePrefix, a.cpuArch)) genericReader, err := os.Open(filepath.Join(a.tmpPath, "generic.ins")) if err != nil { return err