Skip to content

Commit

Permalink
azure: Skip image upload if env var is set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rna-afk committed May 1, 2024
1 parent 01d7e86 commit 9bccf7b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 95 deletions.
8 changes: 8 additions & 0 deletions pkg/asset/installconfig/azure/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/url"
"os"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -628,12 +629,19 @@ 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.ControlPlane.Platform)...)
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, platform types.MachinePoolPlatform) field.ErrorList {
if _, ok := os.LookupEnv("OPENSHIFT_INSTALL_SKIP_IMAGE_UPLOAD"); ok && platform.Azure != nil && len(platform.Azure.OSImage.SKU) > 0 {
return nil
}
return field.ErrorList{field.Invalid(field.NewPath("image"), "image", "cannot skip image upload without marketplace image specified")}
}
func validateResourceGroup(client API, fieldPath *field.Path, platform *aztypes.Platform) field.ErrorList {
allErrs := field.ErrorList{}
if len(platform.ResourceGroupName) == 0 {
Expand Down
1 change: 0 additions & 1 deletion pkg/clusterapi/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func (c *system) Run(ctx context.Context, installConfig *installconfig.InstallCo
&Azure,
[]string{
"-v=2",
"--diagnostics-address=0",
"--health-addr={{suggestHealthHostPort}}",
"--webhook-port={{.WebhookPort}}",
"--webhook-cert-dir={{.WebhookCertDir}}",
Expand Down
191 changes: 97 additions & 94 deletions pkg/infrastructure/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -227,105 +228,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
}

// 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
}
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
}

computeClientFactory := createImageGalleryOutput.ComputeClientFactory
// 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 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
}
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
}

_, 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, nil)
Expand Down

0 comments on commit 9bccf7b

Please sign in to comment.