Skip to content
Open
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
3 changes: 2 additions & 1 deletion pkg/asset/agent/image/agentimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (a *AgentImage) Generate(ctx context.Context, dependencies asset.Parents) e
logrus.Debugf("Using custom rootfs URL: %s", a.rootFSURL)
} else {
// Default to the URL from the RHCOS streams file
defaultRootFSURL, err := baseIso.getRootFSURL(ctx, a.cpuArch)
osImageStream := agentManifests.GetOSImageStream()
defaultRootFSURL, err := baseIso.getRootFSURL(ctx, a.cpuArch, osImageStream)
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/asset/agent/image/baseiso.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (i *BaseIso) Name() string {
}

// Fetch RootFS URL using the rhcos.json.
func (i *BaseIso) getRootFSURL(ctx context.Context, archName string) (string, error) {
metal, err := rhcos.GetMetalArtifact(ctx, archName)
func (i *BaseIso) getRootFSURL(ctx context.Context, archName string, osImageStream types.OSImageStream) (string, error) {
metal, err := rhcos.GetMetalArtifact(ctx, archName, osImageStream)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -69,8 +69,11 @@ func (i *BaseIso) Generate(ctx context.Context, dependencies asset.Parents) erro
clusterInfo := &joiner.ClusterInfo{}
dependencies.Get(agentManifests, registriesConf, agentWorkflow, clusterInfo)

// Extract osImageStream from AgentClusterInstall annotation
osImageStream := agentManifests.GetOSImageStream()

baseIsoFileName, err := rhcos.NewBaseISOFetcher(
i.getRelease(agentManifests, registriesConf.MirrorConfig)).GetBaseISOFilename(ctx, agentManifests.InfraEnv.Spec.CpuArchitecture)
i.getRelease(agentManifests, registriesConf.MirrorConfig), osImageStream).GetBaseISOFilename(ctx, agentManifests.InfraEnv.Spec.CpuArchitecture)

if err == nil {
logrus.Debugf("Using base ISO image %s", baseIsoFileName)
Expand Down
7 changes: 4 additions & 3 deletions pkg/asset/agent/image/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ func (a *Ignition) Generate(ctx context.Context, dependencies asset.Parents) err
infraEnvID := infraEnvAsset.ID
logrus.Debug("Generated random infra-env id ", infraEnvID)

osImage, err := getOSImagesInfo(ctx, archName, openshiftVersion)
osImageStream := agentManifests.GetOSImageStream()
osImage, err := getOSImagesInfo(ctx, archName, openshiftVersion, osImageStream)
if err != nil {
return err
}
Expand Down Expand Up @@ -745,13 +746,13 @@ func addExtraManifests(config *igntypes.Config, extraManifests *manifests.ExtraM
return nil
}

func getOSImagesInfo(ctx context.Context, cpuArch string, openshiftVersion string) (*models.OsImage, error) {
func getOSImagesInfo(ctx context.Context, cpuArch string, openshiftVersion string, osImageStream types.OSImageStream) (*models.OsImage, error) {
osImage := &models.OsImage{
CPUArchitecture: &cpuArch,
}
osImage.OpenshiftVersion = &openshiftVersion

artifacts, err := rhcos.GetMetalArtifact(ctx, cpuArch)
artifacts, err := rhcos.GetMetalArtifact(ctx, cpuArch, osImageStream)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/asset/agent/image/unconfigured_ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/openshift/installer/pkg/asset/agent/workflow"
"github.com/openshift/installer/pkg/asset/ignition"
"github.com/openshift/installer/pkg/asset/ignition/bootstrap"
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
agenttypes "github.com/openshift/installer/pkg/types/agent"
"github.com/openshift/installer/pkg/version"
Expand Down Expand Up @@ -155,7 +156,8 @@ func (a *UnconfiguredIgnition) Generate(ctx context.Context, dependencies asset.
if err != nil {
return err
}
osImage, err := getOSImagesInfo(ctx, archName, openshiftVersion)
// Use default OS image stream for unconfigured ignition workflow
osImage, err := getOSImagesInfo(ctx, archName, openshiftVersion, rhcos.DefaultOSImageStream)
if err != nil {
return err
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/asset/agent/manifests/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package manifests

import (
"context"
"encoding/json"
"fmt"
"reflect"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/validation/field"

Expand All @@ -16,6 +18,8 @@ import (
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/agent/workflow"
workflowreport "github.com/openshift/installer/pkg/asset/agent/workflow/report"
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
)

const (
Expand Down Expand Up @@ -118,6 +122,35 @@ func (m *AgentManifests) GetPullSecretData() string {
return m.PullSecret.StringData[".dockerconfigjson"]
}

// GetOSImageStream extracts the osImageStream from the AgentClusterInstall
// installConfigOverrides annotation, or returns the default if not present.
func (m *AgentManifests) GetOSImageStream() types.OSImageStream {
Comment thread
zaneb marked this conversation as resolved.
if m.AgentClusterInstall == nil {
return rhcos.DefaultOSImageStream
}

if m.AgentClusterInstall.Annotations == nil {
return rhcos.DefaultOSImageStream
}

overridesJSON, ok := m.AgentClusterInstall.Annotations[installConfigOverrides]
if !ok {
return rhcos.DefaultOSImageStream
}

var overrides agentClusterInstallInstallConfigOverrides
if err := json.Unmarshal([]byte(overridesJSON), &overrides); err != nil {
logrus.Debugf("Failed to parse installConfigOverrides: %v", err)
return rhcos.DefaultOSImageStream
}

if overrides.OSImageStream == "" {
return rhcos.DefaultOSImageStream
}

return overrides.OSImageStream
}

func (m *AgentManifests) finish() error {
if err := m.validateAgentManifests().ToAggregate(); err != nil {
return errors.Wrapf(err, "invalid agent configuration")
Expand Down
7 changes: 7 additions & 0 deletions pkg/asset/agent/manifests/agentclusterinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ type agentClusterInstallInstallConfigOverrides struct {
FeatureSet configv1.FeatureSet `json:"featureSet,omitempty"`
// Allow override of FeatureGates
FeatureGates []string `json:"featureGates,omitempty"`
// OSImageStream is the OS Image Stream to be used for all machines in the cluster
OSImageStream types.OSImageStream `json:"osImageStream,omitempty"`
}

var _ asset.WritableAsset = (*AgentClusterInstall)(nil)
Expand Down Expand Up @@ -397,6 +399,11 @@ func (a *AgentClusterInstall) Generate(_ context.Context, dependencies asset.Par
icOverrides.AdditionalTrustBundlePolicy = installConfig.Config.AdditionalTrustBundlePolicy
}

if installConfig.Config.OSImageStream != "" {
icOverridden = true
icOverrides.OSImageStream = installConfig.Config.OSImageStream
}

if icOverridden {
overrides, err := json.Marshal(icOverrides)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/asset/imagebased/image/baseiso.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/openshift/installer/pkg/asset"
assetrhcos "github.com/openshift/installer/pkg/asset/rhcos"
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/rhcos/cache"
"github.com/openshift/installer/pkg/types"
)
Expand Down Expand Up @@ -80,7 +81,8 @@ func (i *BaseIso) Load(f asset.FileFetcher) (bool, error) {

// Download the RHCOS base ISO via rhcos.json.
func (i *BaseIso) downloadBaseIso(ctx context.Context, archName string) (string, error) {
metal, err := assetrhcos.GetMetalArtifact(ctx, archName)
// Use default OS image stream for image-based installer
metal, err := assetrhcos.GetMetalArtifact(ctx, archName, rhcos.DefaultOSImageStream)
if err != nil {
return "", err
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/asset/installconfig/aws/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ func validatePlatform(ctx context.Context, meta *Metadata, fldPath *field.Path,
}

func validateAMI(ctx context.Context, meta *Metadata, config *types.InstallConfig) field.ErrorList {
osImageStream := config.OSImageStream
if osImageStream == "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprising to see this AWS change in a PR about ABI.

I think this should be set in https://github.com/openshift/installer/blob/main/pkg/types/defaults/installconfig.go rather than here.

That would eliminate a lot of places where this same logic is repeated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zaneb agree. In fact, the switchover PR has changed this interface to avoid doing this if play everywhere.
I'd prefer, if you agree, to continue with the change as it is as the switchover will probably take precedence and will completly remove this piece of code if the PR requires a rebase.

osImageStream = rhcos.DefaultOSImageStream
}

// accept AMI from the rhcos stream metadata
if rhcos.AMIRegions(config.ControlPlane.Architecture, config.OSImageStream).Has(config.Platform.AWS.Region) {
if rhcos.AMIRegions(config.ControlPlane.Architecture, osImageStream).Has(config.Platform.AWS.Region) {
return nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/asset/installconfig/nutanix/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func ValidateForProvisioning(ic *types.InstallConfig) error {

// validate PreloadedOSImageName if configured
if p.PreloadedOSImageName != "" {
err = validatePreloadedImage(ctx, nc, p, ic.OSImageStream)
osImageStream := ic.OSImageStream
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this could become a smart getter in installConfig asset

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if osImageStream == "" {
osImageStream = rhcos.DefaultOSImageStream
}
err = validatePreloadedImage(ctx, nc, p, osImageStream)
if err != nil {
errList = append(errList, field.Invalid(parentPath.Child("preloadedOSImageName"), p.PreloadedOSImageName, fmt.Sprintf("fail to validate the preloaded rhcos image: %v", err)))
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/asset/installconfig/vsphere/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ func ValidateForProvisioning(ic *types.InstallConfig) error {
}
defer cleanup()

err = getRhcosStream(validationCtx, ic.OSImageStream)
osImageStream := ic.OSImageStream
if osImageStream == "" {
osImageStream = rhcos.DefaultOSImageStream
}
err = getRhcosStream(validationCtx, osImageStream)
if err != nil {
return err
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/asset/rhcos/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ func osImage(ctx context.Context, ic *installconfig.InstallConfig, machinePool *
nodeArch := machinePool.Architecture
archName := arch.RpmArch(string(nodeArch))

st, err := rhcos.FetchCoreOSBuild(ctx, ic.Config.OSImageStream)
osImageStream := ic.Config.OSImageStream
if osImageStream == "" {
osImageStream = rhcos.DefaultOSImageStream
}

st, err := rhcos.FetchCoreOSBuild(ctx, osImageStream)
if err != nil {
return "", err
}
Expand All @@ -103,7 +108,7 @@ func osImage(ctx context.Context, ic *installconfig.InstallConfig, machinePool *
switch platform.Name() {
case aws.Name:
region := platform.AWS.Region
if !rhcos.AMIRegions(nodeArch, ic.Config.OSImageStream).Has(region) {
if !rhcos.AMIRegions(nodeArch, osImageStream).Has(region) {
const globalResourceRegion = "us-east-1"
logrus.Debugf("No AMI found in %s. Using AMI from %s.", region, globalResourceRegion)
region = globalResourceRegion
Expand Down
24 changes: 13 additions & 11 deletions pkg/asset/rhcos/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import (

// BaseIso generates the base ISO file for the image.
type BaseIso struct {
ocRelease ReleasePayload
ocRelease ReleasePayload
osImageStream types.OSImageStream
}

// NewBaseISOFetcher returns a struct that can be used to fetch a base ISO using
// the default method.
func NewBaseISOFetcher(ocRelease ReleasePayload) *BaseIso {
// the default method with the specified OS image stream.
func NewBaseISOFetcher(ocRelease ReleasePayload, osImageStream types.OSImageStream) *BaseIso {
return &BaseIso{
ocRelease: ocRelease,
ocRelease: ocRelease,
osImageStream: osImageStream,
}
}

Expand All @@ -52,12 +54,12 @@ func (i *BaseIso) GetBaseISOFilename(ctx context.Context, arch string) (baseIsoF
}

// GetMetalArtifact returns the CoreOS metal artifacts for a given arch
// using the embedded stream metadata.
func GetMetalArtifact(ctx context.Context, archName string) (stream.PlatformArtifacts, error) {
// using the embedded stream metadata with the specified stream.
func GetMetalArtifact(ctx context.Context, archName string, osImageStream types.OSImageStream) (stream.PlatformArtifacts, error) {
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()

st, err := rhcos.FetchCoreOSBuild(ctx, rhcos.DefaultOSImageStream)
st, err := rhcos.FetchCoreOSBuild(ctx, osImageStream)
if err != nil {
return stream.PlatformArtifacts{}, err
}
Expand All @@ -77,7 +79,7 @@ func GetMetalArtifact(ctx context.Context, archName string) (stream.PlatformArti

// Download the ISO using the URL in rhcos.json.
func (i *BaseIso) downloadIso(ctx context.Context, archName string) (string, error) {
metal, err := GetMetalArtifact(ctx, archName)
metal, err := GetMetalArtifact(ctx, archName, i.osImageStream)
if err != nil {
return "", err
}
Expand All @@ -101,14 +103,14 @@ func (i *BaseIso) checkReleasePayloadBaseISOVersion(ctx context.Context, r Relea
logrus.Debugf("Checking release payload base ISO version")

// Get current release payload CoreOS version
payloadRelease, err := r.GetBaseIsoVersion(archName)
payloadRelease, err := r.GetBaseIsoVersion(archName, i.osImageStream)
if err != nil {
logrus.Warnf("unable to determine base ISO version: %s", err.Error())
return
}

// Get pinned version from installer
metal, err := GetMetalArtifact(ctx, archName)
metal, err := GetMetalArtifact(ctx, archName, i.osImageStream)
if err != nil {
logrus.Warnf("unable to determine base ISO version: %s", err.Error())
return
Expand All @@ -133,7 +135,7 @@ func (i *BaseIso) retrieveBaseIso(ctx context.Context, archName string) (string,
if err := workflowreport.GetReport(ctx).SubStage(workflow.StageFetchBaseISOExtract); err != nil {
return "", err
}
baseIsoFileName, err := i.ocRelease.GetBaseIso(archName)
baseIsoFileName, err := i.ocRelease.GetBaseIso(archName, i.osImageStream)
if err == nil {
if err := workflowreport.GetReport(ctx).SubStage(workflow.StageFetchBaseISOVerify); err != nil {
return "", err
Expand Down
8 changes: 5 additions & 3 deletions pkg/asset/rhcos/iso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/openshift/installer/pkg/types"
)

func TestBaseIso(t *testing.T) {
Expand Down Expand Up @@ -69,7 +71,7 @@ func TestBaseIso(t *testing.T) {
isoBaseVersion: ocReleaseImage,
baseIsoFileName: ocBaseIsoFilename,
baseIsoError: tc.getIsoError,
})
}, "")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never pass "" to this now, right?

filename, err := fetcher.GetBaseISOFilename(context.Background(), "")

if tc.expectedError == "" {
Expand All @@ -88,14 +90,14 @@ type mockRelease struct {
baseIsoError error
}

func (m *mockRelease) GetBaseIso(architecture string) (string, error) {
func (m *mockRelease) GetBaseIso(architecture string, osImageStream types.OSImageStream) (string, error) {
if m.baseIsoError != nil {
return "", m.baseIsoError
}
return m.baseIsoFileName, nil
}

func (m *mockRelease) GetBaseIsoVersion(architecture string) (string, error) {
func (m *mockRelease) GetBaseIsoVersion(architecture string, osImageStream types.OSImageStream) (string, error) {
return m.isoBaseVersion, nil
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/asset/rhcos/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func release(ctx context.Context, config *types.InstallConfig) (string, error) {

archName := arch.RpmArch(string(config.ControlPlane.Architecture))

st, err := rhcos.FetchCoreOSBuild(ctx, config.OSImageStream)
osImageStream := config.OSImageStream
if osImageStream == "" {
osImageStream = rhcos.DefaultOSImageStream
}

st, err := rhcos.FetchCoreOSBuild(ctx, osImageStream)
if err != nil {
return "", err
}
Expand Down
Loading