Skip to content
Merged
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 == nil || *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
8 changes: 8 additions & 0 deletions pkg/asset/agent/manifests/agentclusterinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/openshift/installer/pkg/asset/agent/agentconfig"
"github.com/openshift/installer/pkg/asset/agent/workflow"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/baremetal"
"github.com/openshift/installer/pkg/types/defaults"
Expand Down Expand Up @@ -131,6 +132,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 +400,11 @@ func (a *AgentClusterInstall) Generate(_ context.Context, dependencies asset.Par
icOverrides.AdditionalTrustBundlePolicy = installConfig.Config.AdditionalTrustBundlePolicy
}

if installConfig.Config.OSImageStream != rhcos.DefaultOSImageStream && installConfig.Config.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.

nit: I don't think it can ever be "" because we set it by default now.

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
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,
})
}, types.OSImageStreamRHCOS9)
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
Loading