From 305db9a0648abb19a7d55239d6e1b2504caea355 Mon Sep 17 00:00:00 2001 From: Bob Fournier Date: Thu, 26 Sep 2024 16:23:10 -0400 Subject: [PATCH] WIP AGENT-972, AGENT-973: Agent minimal ISO support for all platforms Add the ability to enable minimal ISO support for all platform types, not just External. Adds a new flag to the 'agent create image' command. Still WIP as dev-scripts testing needs to be done and integration tests added. --- cmd/openshift-install/agent.go | 7 +++++++ cmd/openshift-install/create.go | 5 +++++ pkg/asset/agent/image/agentimage.go | 18 +++++++++++++----- pkg/asset/agent/image/ignition.go | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/openshift-install/agent.go b/cmd/openshift-install/agent.go index f3f857f48b7..f0f25b87932 100644 --- a/cmd/openshift-install/agent.go +++ b/cmd/openshift-install/agent.go @@ -16,6 +16,10 @@ import ( "github.com/openshift/installer/pkg/asset/password" ) +var ( + agentImageMinimalISO = false +) + func newAgentCmd(ctx context.Context) *cobra.Command { agentCmd := &cobra.Command{ Use: "agent", @@ -129,6 +133,9 @@ func newAgentCreateCmd(ctx context.Context) *cobra.Command { for _, t := range agentTargets { t.command.Args = cobra.ExactArgs(0) t.command.Run = runTargetCmd(ctx, t.assets...) + if t.name == "Agent ISO Image" { + t.command.PersistentFlags().BoolVar(&agentImageMinimalISO, "minimal-iso", false, "generates a minimal ISO image, by default a full ISO will be generated.") + } cmd.AddCommand(t.command) } diff --git a/cmd/openshift-install/create.go b/cmd/openshift-install/create.go index a6df8837e28..baaac6b158d 100644 --- a/cmd/openshift-install/create.go +++ b/cmd/openshift-install/create.go @@ -39,6 +39,7 @@ import ( "github.com/openshift/installer/cmd/openshift-install/command" "github.com/openshift/installer/pkg/asset" "github.com/openshift/installer/pkg/asset/agent/agentconfig" + agentimage "github.com/openshift/installer/pkg/asset/agent/image" "github.com/openshift/installer/pkg/asset/cluster" "github.com/openshift/installer/pkg/asset/installconfig" "github.com/openshift/installer/pkg/asset/kubeconfig" @@ -317,6 +318,10 @@ func runTargetCmd(ctx context.Context, targets ...asset.WritableAsset) func(cmd cluster.InstallDir = command.RootOpts.Dir + if cmd.Name() == "image" && agentImageMinimalISO { + agentimage.MinimalISOConfigured = true + } + err := runner(command.RootOpts.Dir) if err != nil { if strings.Contains(err.Error(), asset.InstallConfigError) { diff --git a/pkg/asset/agent/image/agentimage.go b/pkg/asset/agent/image/agentimage.go index dea9237a2cd..2b17b8ff373 100644 --- a/pkg/asset/agent/image/agentimage.go +++ b/pkg/asset/agent/image/agentimage.go @@ -26,6 +26,10 @@ const ( iso9660Level1ExtLen = 3 ) +var ( + MinimalISOConfigured = false +) + // AgentImage is an asset that generates the bootable image used to install clusters. type AgentImage struct { cpuArch string @@ -38,11 +42,12 @@ type AgentImage struct { platform hiveext.PlatformType isoFilename string imageExpiresAt string + minimalISO bool } var _ asset.WritableAsset = (*AgentImage)(nil) -// Dependencies returns the assets on which the Bootstrap asset depends. +// Dependencies returns the assets on which the AgentImage asset depends. func (a *AgentImage) Dependencies() []asset.Asset { return []asset.Asset{ &workflow.AgentWorkflow{}, @@ -54,7 +59,7 @@ func (a *AgentImage) Dependencies() []asset.Asset { } } -// Generate generates the image file for to ISO asset. +// Generate generates the image file for an AgentImage asset. func (a *AgentImage) Generate(ctx context.Context, dependencies asset.Parents) error { agentWorkflow := &workflow.AgentWorkflow{} clusterInfo := &joiner.ClusterInfo{} @@ -92,7 +97,10 @@ func (a *AgentImage) Generate(ctx context.Context, dependencies asset.Parents) e } a.volumeID = volumeID - if a.platform == hiveext.ExternalPlatformType { + // External platform will always create a minimal ISO + a.minimalISO = MinimalISOConfigured || a.platform == hiveext.ExternalPlatformType + + if a.minimalISO { // when the bootArtifactsBaseURL is specified, construct the custom rootfs URL if a.bootArtifactsBaseURL != "" { a.rootFSURL = fmt.Sprintf("%s/%s", a.bootArtifactsBaseURL, fmt.Sprintf("agent.%s-rootfs.img", a.cpuArch)) @@ -226,9 +234,9 @@ func (a *AgentImage) PersistToFile(directory string) error { } var msg string - // For external platform when the bootArtifactsBaseURL is specified, + // For minimal ISO, when the bootArtifactsBaseURL is specified, // output the rootfs file alongside the minimal ISO - if a.platform == hiveext.ExternalPlatformType { + if a.minimalISO { if a.bootArtifactsBaseURL != "" { bootArtifactsFullPath := filepath.Join(directory, bootArtifactsPath) err := createDir(bootArtifactsFullPath) diff --git a/pkg/asset/agent/image/ignition.go b/pkg/asset/agent/image/ignition.go index 2d1cbd84f53..c9b5305ba4a 100644 --- a/pkg/asset/agent/image/ignition.go +++ b/pkg/asset/agent/image/ignition.go @@ -164,7 +164,7 @@ func (a *Ignition) Generate(_ context.Context, dependencies asset.Parents) error logrus.Infof("The rendezvous host IP (node0 IP) is %s", a.RendezvousIP) // Define cluster name and image type. clusterName = fmt.Sprintf("%s.%s", agentManifests.ClusterDeployment.Spec.ClusterName, agentManifests.ClusterDeployment.Spec.BaseDomain) - if agentManifests.AgentClusterInstall.Spec.PlatformType == hiveext.ExternalPlatformType { + if MinimalISOConfigured || (agentManifests.AgentClusterInstall.Spec.PlatformType == hiveext.ExternalPlatformType) { imageTypeISO = "minimal-iso" } // Fetch the required number of master and worker nodes.