diff --git a/pkg/asset/machines/azure/machines.go b/pkg/asset/machines/azure/machines.go index f934a5aef2c..b95ae6e114c 100644 --- a/pkg/asset/machines/azure/machines.go +++ b/pkg/asset/machines/azure/machines.go @@ -23,7 +23,7 @@ const ( ) // Machines returns a list of machines for a machinepool. -func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string, capabilities map[string]string, rhcosVersion string) ([]machineapi.Machine, error) { +func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string, capabilities map[string]string, useImageGallery bool) ([]machineapi.Machine, error) { if configPlatform := config.Platform.Name(); configPlatform != azure.Name { return nil, fmt.Errorf("non-Azure configuration: %q", configPlatform) } @@ -50,7 +50,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine if len(azs) > 0 { azIndex = int(idx) % len(azs) } - provider, err := provider(platform, mpool, osImage, userDataSecret, clusterID, role, &azIndex, capabilities, rhcosVersion) + provider, err := provider(platform, mpool, osImage, userDataSecret, clusterID, role, &azIndex, capabilities, useImageGallery) if err != nil { return nil, errors.Wrap(err, "failed to create provider") } @@ -82,7 +82,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine return machines, nil } -func provider(platform *azure.Platform, mpool *azure.MachinePool, osImage string, userDataSecret string, clusterID string, role string, azIdx *int, capabilities map[string]string, rhcosVersion string) (*machineapi.AzureMachineProviderSpec, error) { +func provider(platform *azure.Platform, mpool *azure.MachinePool, osImage string, userDataSecret string, clusterID string, role string, azIdx *int, capabilities map[string]string, useImageGallery bool) (*machineapi.AzureMachineProviderSpec, error) { var az *string if len(mpool.Zones) > 0 && azIdx != nil { az = &mpool.Zones[*azIdx] @@ -110,14 +110,20 @@ func provider(platform *azure.Platform, mpool *azure.MachinePool, osImage string image.Offer = mpool.OSImage.Offer image.SKU = mpool.OSImage.SKU image.Version = mpool.OSImage.Version - } else { + } else if useImageGallery { // image gallery names cannot have dashes galleryName := strings.Replace(clusterID, "-", "_", -1) id := clusterID if hyperVGen == "V2" { id += "-gen2" } - imageID := fmt.Sprintf("/resourceGroups/%s/providers/Microsoft.Compute/galleries/gallery_%s/images/%s/versions/%s", rg, galleryName, id, rhcosVersion) + imageID := fmt.Sprintf("/resourceGroups/%s/providers/Microsoft.Compute/galleries/gallery_%s/images/%s/versions/latest", rg, galleryName, id) + image.ResourceID = imageID + } else { + imageID := fmt.Sprintf("/resourceGroups/%s/providers/Microsoft.Compute/images/%s", rg, clusterID) + if hyperVGen == "V2" && platform.CloudName != azure.StackCloud { + imageID += "-gen2" + } image.ResourceID = imageID } @@ -188,9 +194,6 @@ func provider(platform *azure.Platform, mpool *azure.MachinePool, osImage string if platform.CloudName == azure.StackCloud { spec.AvailabilitySet = fmt.Sprintf("%s-cluster", clusterID) - - // Public Azure has moved to use image galleries, but ASH is still using managed images. - spec.Image.ResourceID = fmt.Sprintf("/resourceGroups/%s/providers/Microsoft.Compute/images/%s", rg, clusterID) } return spec, nil diff --git a/pkg/asset/machines/azure/machinesets.go b/pkg/asset/machines/azure/machinesets.go index 686b07d4ae4..9182d2399f2 100644 --- a/pkg/asset/machines/azure/machinesets.go +++ b/pkg/asset/machines/azure/machinesets.go @@ -41,7 +41,8 @@ func MachineSets(clusterID string, config *types.InstallConfig, pool *types.Mach if int64(idx) < total%numOfAZs { replicas++ } - provider, err := provider(platform, mpool, osImage, userDataSecret, clusterID, role, &idx, capabilities, rhcosVersion) + useImageGallery := platform.CloudName != azure.StackCloud + provider, err := provider(platform, mpool, osImage, userDataSecret, clusterID, role, &idx, capabilities, useImageGallery) if err != nil { return nil, errors.Wrap(err, "failed to create provider") } diff --git a/pkg/asset/machines/master.go b/pkg/asset/machines/master.go index c88d960e17a..555831d9b5e 100644 --- a/pkg/asset/machines/master.go +++ b/pkg/asset/machines/master.go @@ -137,7 +137,6 @@ func (m *Master) Dependencies() []asset.Asset { &installconfig.PlatformCredsCheck{}, &installconfig.InstallConfig{}, new(rhcos.Image), - new(rhcos.Release), &machine.Master{}, } } @@ -148,9 +147,8 @@ func (m *Master) Generate(dependencies asset.Parents) error { clusterID := &installconfig.ClusterID{} installConfig := &installconfig.InstallConfig{} rhcosImage := new(rhcos.Image) - rhcosRelease := new(rhcos.Release) mign := &machine.Master{} - dependencies.Get(clusterID, installConfig, rhcosImage, rhcosRelease, mign) + dependencies.Get(clusterID, installConfig, rhcosImage, mign) masterUserDataSecretName := "master-user-data" @@ -369,8 +367,9 @@ func (m *Master) Generate(dependencies asset.Parents) error { if err != nil { return err } + useImageGallery := installConfig.Azure.CloudName != azuretypes.StackCloud - machines, err = azure.Machines(clusterID.InfraID, ic, &pool, string(*rhcosImage), "master", masterUserDataSecretName, capabilities, rhcosRelease.GetAzureReleaseVersion()) + machines, err = azure.Machines(clusterID.InfraID, ic, &pool, string(*rhcosImage), "master", masterUserDataSecretName, capabilities, useImageGallery) if err != nil { return errors.Wrap(err, "failed to create master machine objects") }