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
37 changes: 37 additions & 0 deletions pkg/asset/manifests/mco.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/azure"
"github.com/openshift/installer/pkg/types/gcp"
"github.com/openshift/installer/pkg/types/vsphere"
)

func generateMCOManifest(installConfig *types.InstallConfig, template []*asset.File) []*asset.File {
Expand All @@ -35,8 +37,12 @@ func customBootImages(ic *types.InstallConfig) (customCPImg, customWImg bool) {
switch ic.Platform.Name() {
case aws.Name:
customCPImg, customWImg = awsBootImages(ic)
case azure.Name:
customCPImg, customWImg = azureBootImages(ic)
case gcp.Name:
customCPImg, customWImg = gcpBootImages(ic)
case vsphere.Name:
customCPImg, customWImg = vsphereBootImages(ic)
default:
// We do not need to consider other platforms, because default boot image management has not been enabled yet.
return
Expand Down Expand Up @@ -76,3 +82,34 @@ func gcpBootImages(ic *types.InstallConfig) (cpImg bool, wImg bool) {
}
return
}

func azureBootImages(ic *types.InstallConfig) (cpImg bool, wImg bool) {
var emptyOSImage azure.OSImage
if dmp := ic.Azure.DefaultMachinePlatform; dmp != nil && dmp.OSImage != emptyOSImage {
return true, true
}

if cp := ic.ControlPlane; cp != nil && cp.Platform.Azure != nil && cp.Platform.Azure.OSImage != emptyOSImage {
cpImg = true
}

for _, computeMP := range ic.Compute {
if azurePlatform := computeMP.Platform.Azure; azurePlatform != nil && azurePlatform.OSImage != emptyOSImage {
wImg = true
}
}
return
}

func vsphereBootImages(ic *types.InstallConfig) (cpImg bool, wImg bool) {
if ic.VSphere.ClusterOSImage != "" {
return true, true
}

for _, failureDomain := range ic.VSphere.FailureDomains {
if failureDomain.Topology.Template != "" {
return true, true
}
}
return
}
67 changes: 67 additions & 0 deletions pkg/asset/manifests/mco_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
azuretypes "github.com/openshift/installer/pkg/types/azure"
"github.com/openshift/installer/pkg/types/gcp"
"github.com/openshift/installer/pkg/types/vsphere"
)

func TestGenerateMCO(t *testing.T) {
Expand Down Expand Up @@ -50,6 +52,31 @@ func TestGenerateMCO(t *testing.T) {
installConfig: icBuild.build(icBuild.withGCPComputeAMI()),
expectedMCO: mcoBuild.build(mcoBuild.withComputeBootImageMgmtDisabled()),
},
{
name: "vanilla azure produces no mco cfg",
installConfig: icBuild.build(icBuild.forAzure()),
expectedMCO: nil,
},
{
name: "azure with a custom compute image disables mco management",
installConfig: icBuild.build(icBuild.withAzureComputeOSImage()),
expectedMCO: mcoBuild.build(mcoBuild.withComputeBootImageMgmtDisabled()),
},
{
name: "vanilla vsphere produces no mco cfg",
installConfig: icBuild.build(icBuild.forVSphere()),
expectedMCO: nil,
},
{
name: "vsphere with a custom cluster OS image disables mco management",
installConfig: icBuild.build(icBuild.withVSphereClusterOSImage()),
expectedMCO: mcoBuild.build(mcoBuild.withComputeBootImageMgmtDisabled()),
},
{
name: "vsphere with a failuredomain template disables mco management",
installConfig: icBuild.build(icBuild.withVSphereFailureDomainTemplate()),
expectedMCO: mcoBuild.build(mcoBuild.withComputeBootImageMgmtDisabled()),
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -169,3 +196,43 @@ func (b icBuildNamespace) withGCPComputeAMI() icOption {
}
}
}

func (b icBuildNamespace) withAzureComputeOSImage() icOption {
return func(ic *types.InstallConfig) {
b.forAzure()(ic)
ic.Compute = []types.MachinePool{
{
Platform: types.MachinePoolPlatform{
Azure: &azuretypes.MachinePool{
OSImage: azuretypes.OSImage{
Publisher: "RedHat",
Offer: "rhcos",
SKU: "rhcos",
Version: "latest",
},
},
},
},
}
}
}

func (b icBuildNamespace) withVSphereClusterOSImage() icOption {
return func(ic *types.InstallConfig) {
b.forVSphere()(ic)
ic.VSphere.ClusterOSImage = "https://example.com/rhcos.ova"
}
}

func (b icBuildNamespace) withVSphereFailureDomainTemplate() icOption {
return func(ic *types.InstallConfig) {
b.forVSphere()(ic)
ic.VSphere.FailureDomains = []vsphere.FailureDomain{
{
Topology: vsphere.Topology{
Template: "rhcos-template",
},
},
}
}
}