1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00

azure: Skip image upload if env var is set

Adding option to skip the image upload from the installer if
an environment variable is set since it takes a lot of time and
the marketplace images can be used to skip this step.
This commit is contained in:
rna-afk
2024-04-17 18:44:37 -04:00
parent 48241a0477
commit 1646bfbb4c
4 changed files with 133 additions and 95 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/url"
"os"
"sort"
"strconv"
"strings"
@@ -628,12 +629,46 @@ func ValidateForProvisioning(client API, ic *types.InstallConfig) error {
allErrs = append(allErrs, validateResourceGroup(client, field.NewPath("platform").Child("azure"), ic.Azure)...)
allErrs = append(allErrs, ValidateDiskEncryptionSet(client, ic)...)
allErrs = append(allErrs, ValidateSecurityProfileDiskEncryptionSet(client, ic)...)
allErrs = append(allErrs, validateSkipImageUpload(field.NewPath("image"), ic)...)
if ic.Azure.CloudName == aztypes.StackCloud {
allErrs = append(allErrs, checkAzureStackClusterOSImageSet(ic.Azure.ClusterOSImage, field.NewPath("platform").Child("azure"))...)
}
return allErrs.ToAggregate()
}
func validateSkipImageUpload(fieldPath *field.Path, ic *types.InstallConfig) field.ErrorList {
allErrs := field.ErrorList{}
defaultOSImage := aztypes.OSImage{}
if ic.Azure.DefaultMachinePlatform != nil {
defaultOSImage = aztypes.OSImage{
Plan: ic.Azure.DefaultMachinePlatform.OSImage.Plan,
Publisher: ic.Azure.DefaultMachinePlatform.OSImage.Publisher,
SKU: ic.Azure.DefaultMachinePlatform.OSImage.SKU,
Version: ic.Azure.DefaultMachinePlatform.OSImage.Version,
Offer: ic.Azure.DefaultMachinePlatform.OSImage.Offer,
}
}
controlPlaneOSImage := defaultOSImage
if ic.ControlPlane.Platform.Azure != nil {
controlPlaneOSImage = ic.ControlPlane.Platform.Azure.OSImage
}
allErrs = append(allErrs, validateOSImage(fieldPath.Child("controlplane"), controlPlaneOSImage)...)
computeOSImage := defaultOSImage
if len(ic.Compute) > 0 && ic.Compute[0].Platform.Azure != nil {
computeOSImage = ic.Compute[0].Platform.Azure.OSImage
}
allErrs = append(allErrs, validateOSImage(fieldPath.Child("compute"), computeOSImage)...)
return allErrs
}
func validateOSImage(fieldPath *field.Path, osImage aztypes.OSImage) field.ErrorList {
if _, ok := os.LookupEnv("OPENSHIFT_INSTALL_SKIP_IMAGE_UPLOAD"); ok {
if len(osImage.SKU) > 0 {
return nil
}
return field.ErrorList{field.Invalid(fieldPath, "image", "cannot skip image upload without marketplace image specified")}
}
return nil
}
func validateResourceGroup(client API, fieldPath *field.Path, platform *aztypes.Platform) field.ErrorList {
allErrs := field.ErrorList{}
if len(platform.ResourceGroupName) == 0 {

View File

@@ -58,7 +58,8 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
Offer: osImage.Offer,
SKU: osImage.SKU,
},
Version: osImage.Version,
Version: osImage.Version,
ThirdPartyImage: osImage.Plan != azure.ImageNoPurchasePlan,
},
}
case useImageGallery:

View File

@@ -173,7 +173,6 @@ func (c *system) Run(ctx context.Context) error {
&Azure,
[]string{
"-v=2",
"--diagnostics-address=0",
"--health-addr={{suggestHealthHostPort}}",
"--webhook-port={{.WebhookPort}}",
"--webhook-cert-dir={{.WebhookCertDir}}",

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"net/http"
"os"
"strings"
"time"
@@ -235,105 +236,107 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
logrus.Debugf("BlobContainer.ID=%s", *blobContainer.ID)
// Upload the image to the container
_, err = CreatePageBlob(ctx, &CreatePageBlobInput{
StorageURL: storageURL,
BlobURL: blobURL,
ImageURL: imageURL,
ImageLength: imageLength,
StorageAccountName: storageAccountName,
StorageAccountKeys: storageAccountKeys,
CloudConfiguration: cloudConfiguration,
})
if err != nil {
return err
}
if _, ok := os.LookupEnv("OPENSHIFT_INSTALL_SKIP_IMAGE_UPLOAD"); !ok {
_, err = CreatePageBlob(ctx, &CreatePageBlobInput{
StorageURL: storageURL,
BlobURL: blobURL,
ImageURL: imageURL,
ImageLength: imageLength,
StorageAccountName: storageAccountName,
StorageAccountKeys: storageAccountKeys,
CloudConfiguration: cloudConfiguration,
})
if err != nil {
return err
}
// Create image gallery
createImageGalleryOutput, err := CreateImageGallery(ctx, &CreateImageGalleryInput{
SubscriptionID: subscriptionID,
ResourceGroupName: resourceGroupName,
GalleryName: galleryName,
Region: platform.Region,
Tags: tags,
TokenCredential: tokenCredential,
CloudConfiguration: cloudConfiguration,
})
if err != nil {
return err
}
// Create image gallery
createImageGalleryOutput, err := CreateImageGallery(ctx, &CreateImageGalleryInput{
SubscriptionID: subscriptionID,
ResourceGroupName: resourceGroupName,
GalleryName: galleryName,
Region: platform.Region,
Tags: tags,
TokenCredential: tokenCredential,
CloudConfiguration: cloudConfiguration,
})
if err != nil {
return err
}
computeClientFactory := createImageGalleryOutput.ComputeClientFactory
computeClientFactory := createImageGalleryOutput.ComputeClientFactory
// Create gallery images
_, err = CreateGalleryImage(ctx, &CreateGalleryImageInput{
ResourceGroupName: resourceGroupName,
GalleryName: galleryName,
GalleryImageName: galleryImageName,
Region: platform.Region,
Tags: tags,
TokenCredential: tokenCredential,
CloudConfiguration: cloudConfiguration,
OSType: armcompute.OperatingSystemTypesLinux,
OSState: armcompute.OperatingSystemStateTypesGeneralized,
HyperVGeneration: armcompute.HyperVGenerationV1,
Publisher: "RedHat",
Offer: "rhcos",
SKU: "basic",
ComputeClientFactory: computeClientFactory,
})
if err != nil {
return err
}
// Create gallery images
_, err = CreateGalleryImage(ctx, &CreateGalleryImageInput{
ResourceGroupName: resourceGroupName,
GalleryName: galleryName,
GalleryImageName: galleryImageName,
Region: platform.Region,
Tags: tags,
TokenCredential: tokenCredential,
CloudConfiguration: cloudConfiguration,
OSType: armcompute.OperatingSystemTypesLinux,
OSState: armcompute.OperatingSystemStateTypesGeneralized,
HyperVGeneration: armcompute.HyperVGenerationV1,
Publisher: "RedHat",
Offer: "rhcos",
SKU: "basic",
ComputeClientFactory: computeClientFactory,
})
if err != nil {
return err
}
_, err = CreateGalleryImage(ctx, &CreateGalleryImageInput{
ResourceGroupName: resourceGroupName,
GalleryName: galleryName,
GalleryImageName: galleryGen2ImageName,
Region: platform.Region,
Tags: tags,
TokenCredential: tokenCredential,
CloudConfiguration: cloudConfiguration,
OSType: armcompute.OperatingSystemTypesLinux,
OSState: armcompute.OperatingSystemStateTypesGeneralized,
HyperVGeneration: armcompute.HyperVGenerationV1,
Publisher: "RedHat-gen2",
Offer: "rhcos-gen2",
SKU: "gen2",
ComputeClientFactory: computeClientFactory,
})
if err != nil {
return err
}
_, err = CreateGalleryImage(ctx, &CreateGalleryImageInput{
ResourceGroupName: resourceGroupName,
GalleryName: galleryName,
GalleryImageName: galleryGen2ImageName,
Region: platform.Region,
Tags: tags,
TokenCredential: tokenCredential,
CloudConfiguration: cloudConfiguration,
OSType: armcompute.OperatingSystemTypesLinux,
OSState: armcompute.OperatingSystemStateTypesGeneralized,
HyperVGeneration: armcompute.HyperVGenerationV1,
Publisher: "RedHat-gen2",
Offer: "rhcos-gen2",
SKU: "gen2",
ComputeClientFactory: computeClientFactory,
})
if err != nil {
return err
}
// Create gallery image versions
_, err = CreateGalleryImageVersion(ctx, &CreateGalleryImageVersionInput{
ResourceGroupName: resourceGroupName,
StorageAccountID: *storageAccount.ID,
GalleryName: galleryName,
GalleryImageName: galleryImageName,
GalleryImageVersionName: galleryImageVersionName,
Region: platform.Region,
BlobURL: blobURL,
RegionalReplicaCount: int32(1),
ComputeClientFactory: computeClientFactory,
})
if err != nil {
return err
}
// Create gallery image versions
_, err = CreateGalleryImageVersion(ctx, &CreateGalleryImageVersionInput{
ResourceGroupName: resourceGroupName,
StorageAccountID: *storageAccount.ID,
GalleryName: galleryName,
GalleryImageName: galleryImageName,
GalleryImageVersionName: galleryImageVersionName,
Region: platform.Region,
BlobURL: blobURL,
RegionalReplicaCount: int32(1),
ComputeClientFactory: computeClientFactory,
})
if err != nil {
return err
}
_, err = CreateGalleryImageVersion(ctx, &CreateGalleryImageVersionInput{
ResourceGroupName: resourceGroupName,
StorageAccountID: *storageAccount.ID,
GalleryName: galleryName,
GalleryImageName: galleryGen2ImageName,
GalleryImageVersionName: galleryGen2ImageVersionName,
Region: platform.Region,
BlobURL: blobURL,
RegionalReplicaCount: int32(1),
ComputeClientFactory: computeClientFactory,
})
if err != nil {
return err
_, err = CreateGalleryImageVersion(ctx, &CreateGalleryImageVersionInput{
ResourceGroupName: resourceGroupName,
StorageAccountID: *storageAccount.ID,
GalleryName: galleryName,
GalleryImageName: galleryGen2ImageName,
GalleryImageVersionName: galleryGen2ImageVersionName,
Region: platform.Region,
BlobURL: blobURL,
RegionalReplicaCount: int32(1),
ComputeClientFactory: computeClientFactory,
})
if err != nil {
return err
}
}
networkClientFactory, err := armnetwork.NewClientFactory(subscriptionID, session.TokenCreds,