From 3d4734fdff2c701c7d749cca4b0fc80138fe5a9c 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. --- .../agentconfigtemplate/agent-config-template.txt | 1 + pkg/asset/agent/agentconfig/agent_config.go | 1 + pkg/asset/agent/image/agentartifacts.go | 11 +++++++++++ pkg/asset/agent/image/agentimage.go | 12 +++++++----- pkg/asset/agent/image/ignition.go | 5 +++-- pkg/types/agent/agent_config_type.go | 3 +++ 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/cmd/openshift-install/testdata/agent/agentconfigtemplate/agent-config-template.txt b/cmd/openshift-install/testdata/agent/agentconfigtemplate/agent-config-template.txt index da8db838699..ce7e9598015 100644 --- a/cmd/openshift-install/testdata/agent/agentconfigtemplate/agent-config-template.txt +++ b/cmd/openshift-install/testdata/agent/agentconfigtemplate/agent-config-template.txt @@ -22,6 +22,7 @@ metadata: # All fields are optional rendezvousIP: your-node0-ip bootArtifactsBaseURL: http://user-specified-infra.com +minimalISO: false additionalNTPSources: - 0.rhel.pool.ntp.org - 1.rhel.pool.ntp.org diff --git a/pkg/asset/agent/agentconfig/agent_config.go b/pkg/asset/agent/agentconfig/agent_config.go index 9cf4e1e5475..1c634d3ea3c 100644 --- a/pkg/asset/agent/agentconfig/agent_config.go +++ b/pkg/asset/agent/agentconfig/agent_config.go @@ -57,6 +57,7 @@ metadata: # All fields are optional rendezvousIP: your-node0-ip bootArtifactsBaseURL: http://user-specified-infra.com +minimalISO: false additionalNTPSources: - 0.rhel.pool.ntp.org - 1.rhel.pool.ntp.org diff --git a/pkg/asset/agent/image/agentartifacts.go b/pkg/asset/agent/image/agentartifacts.go index b1003f0ff6e..bdc77b221e3 100644 --- a/pkg/asset/agent/image/agentartifacts.go +++ b/pkg/asset/agent/image/agentartifacts.go @@ -8,7 +8,10 @@ import ( "path/filepath" "strings" + "github.com/sirupsen/logrus" + "github.com/openshift/assisted-image-service/pkg/isoeditor" + hiveext "github.com/openshift/assisted-service/api/hiveextension/v1beta1" "github.com/openshift/installer/pkg/asset" "github.com/openshift/installer/pkg/asset/agent" config "github.com/openshift/installer/pkg/asset/agent/agentconfig" @@ -33,6 +36,7 @@ type AgentArtifacts struct { Kargs string ISOPath string BootArtifactsBaseURL string + MinimalISO bool } // Dependencies returns the assets on which the AgentArtifacts asset depends. @@ -73,6 +77,13 @@ func (a *AgentArtifacts) Generate(_ context.Context, dependencies asset.Parents) if agentconfig.Config != nil { a.BootArtifactsBaseURL = strings.Trim(agentconfig.Config.BootArtifactsBaseURL, "/") + // External platform will always create a minimal ISO + a.MinimalISO = agentconfig.Config.MinimalISO || agentManifests.AgentClusterInstall.Spec.PlatformType == hiveext.ExternalPlatformType + if agentconfig.Config.MinimalISO { + logrus.Infof("Minimal ISO will be created based on configuration") + } else if agentManifests.AgentClusterInstall.Spec.PlatformType == hiveext.ExternalPlatformType { + logrus.Infof("Minimal ISO will be created for External platform") + } } var agentTuiFiles []string diff --git a/pkg/asset/agent/image/agentimage.go b/pkg/asset/agent/image/agentimage.go index dea9237a2cd..74e5dde6b5e 100644 --- a/pkg/asset/agent/image/agentimage.go +++ b/pkg/asset/agent/image/agentimage.go @@ -38,11 +38,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 +55,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{} @@ -85,6 +86,7 @@ func (a *AgentImage) Generate(ctx context.Context, dependencies asset.Parents) e a.tmpPath = agentArtifacts.TmpPath a.isoPath = agentArtifacts.ISOPath a.bootArtifactsBaseURL = agentArtifacts.BootArtifactsBaseURL + a.minimalISO = agentArtifacts.MinimalISO volumeID, err := isoeditor.VolumeIdentifier(a.isoPath) if err != nil { @@ -92,7 +94,7 @@ func (a *AgentImage) Generate(ctx context.Context, dependencies asset.Parents) e } a.volumeID = volumeID - if 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 +228,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..e3314f22354 100644 --- a/pkg/asset/agent/image/ignition.go +++ b/pkg/asset/agent/image/ignition.go @@ -162,9 +162,10 @@ func (a *Ignition) Generate(_ context.Context, dependencies asset.Parents) error } a.RendezvousIP = nodeZeroIP logrus.Infof("The rendezvous host IP (node0 IP) is %s", a.RendezvousIP) - // Define cluster name and image type. + // Define cluster name clusterName = fmt.Sprintf("%s.%s", agentManifests.ClusterDeployment.Spec.ClusterName, agentManifests.ClusterDeployment.Spec.BaseDomain) - if agentManifests.AgentClusterInstall.Spec.PlatformType == hiveext.ExternalPlatformType { + if (agentConfigAsset.Config != nil && agentConfigAsset.Config.MinimalISO) || + (agentManifests.AgentClusterInstall.Spec.PlatformType == hiveext.ExternalPlatformType) { imageTypeISO = "minimal-iso" } // Fetch the required number of master and worker nodes. diff --git a/pkg/types/agent/agent_config_type.go b/pkg/types/agent/agent_config_type.go index 83ec3ec1537..81e96115c78 100644 --- a/pkg/types/agent/agent_config_type.go +++ b/pkg/types/agent/agent_config_type.go @@ -27,6 +27,9 @@ type Config struct { RendezvousIP string `json:"rendezvousIP,omitempty"` BootArtifactsBaseURL string `json:"bootArtifactsBaseURL,omitempty"` Hosts []Host `json:"hosts,omitempty"` + // When MinimalISO is set to true, a minimal ISO that does not contain the rootfs will be generated. + // By default a full ISO will be created, unless the platform is External, which generates a minimal ISO. + MinimalISO bool `json:"minimalISO,omitempty"` } // Host defines per host configurations