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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does using latest here work?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Prashanth684 I remember you had issues when using anything other than an actual version here

Copy link
Contributor

Choose a reason for hiding this comment

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

yes it did - looking back at this comment: #6304 (comment), it did not like latest when used as a version

Copy link
Contributor

Choose a reason for hiding this comment

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

See name here https://learn.microsoft.com/en-us/azure/templates/microsoft.compute/2021-10-01/galleries/images/versions?pivots=deployment-language-arm-template. This is the ARM template but iirc the same restrictions apply

Character limit: 32-bit integer

Valid characters:
Numbers and periods.
(Each segment is converted to an int32. So each segment has a max value of 2,147,483,647.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it did - looking back at this comment: #6304 (comment), it did not like latest when used as a version

It doesn't like latest when creating an image gallery (version), but it is ok when specifying the image to be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

that makes sense!

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
Copy link
Contributor

Choose a reason for hiding this comment

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

this "toggle" here seems to be hardcoded to say that if the platform is ASH use managed images, if not use image gallery? does this mean hive uses ASH? i don't understand how this toggle helps with backwards compatibility in this case.

Copy link
Contributor Author

@patrickdillon patrickdillon Dec 13, 2022

Choose a reason for hiding this comment

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

I am just learning about this myself... Within the installer, there is no backward compatibility and Azure Stack using the bool is more of a coincidence. Hive vendors the asset package and calls the function to create machinesets:

https://github.com/openshift/hive/blob/33e68f241d3c784c5362b48febea14020107dd39/pkg/controller/machinepool/azureactuator.go#L139-L146

So basically they will set the bool based on whether the version is 4.12+.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah..ok..i see..good to know..thanks

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 @@ -137,7 +137,6 @@ func (m *Master) Dependencies() []asset.Asset {
&installconfig.PlatformCredsCheck{},
&installconfig.InstallConfig{},
new(rhcos.Image),
new(rhcos.Release),
&machine.Master{},
}
}
Expand All @@ -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"

Expand Down Expand Up @@ -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")
}
Expand Down