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
19 changes: 11 additions & 8 deletions pkg/asset/machines/azure/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/asset/machines/azure/machinesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/asset/machines/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func (m *Master) Dependencies() []asset.Asset {
&installconfig.PlatformCredsCheck{},
&installconfig.InstallConfig{},
new(rhcos.Image),
new(rhcos.Release),
&machine.Master{},
}
}
Expand All @@ -149,9 +148,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"

Expand Down Expand Up @@ -370,8 +368,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")
}
Expand Down