Skip to content

Commit be18395

Browse files
Merge pull request openshift#8283 from rna-afk/capz_skip_blob_upload
CORS-3434: azure: Skip image upload if env var is set
2 parents b8c8c69 + 1646bfb commit be18395

File tree

4 files changed

+134
-96
lines changed

4 files changed

+134
-96
lines changed

pkg/asset/installconfig/azure/validation.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net"
77
"net/url"
8+
"os"
89
"sort"
910
"strconv"
1011
"strings"
@@ -640,12 +641,46 @@ func ValidateForProvisioning(client API, ic *types.InstallConfig) error {
640641
allErrs = append(allErrs, validateResourceGroup(client, field.NewPath("platform").Child("azure"), ic.Azure)...)
641642
allErrs = append(allErrs, ValidateDiskEncryptionSet(client, ic)...)
642643
allErrs = append(allErrs, ValidateSecurityProfileDiskEncryptionSet(client, ic)...)
644+
allErrs = append(allErrs, validateSkipImageUpload(field.NewPath("image"), ic)...)
643645
if ic.Azure.CloudName == aztypes.StackCloud {
644646
allErrs = append(allErrs, checkAzureStackClusterOSImageSet(ic.Azure.ClusterOSImage, field.NewPath("platform").Child("azure"))...)
645647
}
646648
return allErrs.ToAggregate()
647649
}
648650

651+
func validateSkipImageUpload(fieldPath *field.Path, ic *types.InstallConfig) field.ErrorList {
652+
allErrs := field.ErrorList{}
653+
defaultOSImage := aztypes.OSImage{}
654+
if ic.Azure.DefaultMachinePlatform != nil {
655+
defaultOSImage = aztypes.OSImage{
656+
Plan: ic.Azure.DefaultMachinePlatform.OSImage.Plan,
657+
Publisher: ic.Azure.DefaultMachinePlatform.OSImage.Publisher,
658+
SKU: ic.Azure.DefaultMachinePlatform.OSImage.SKU,
659+
Version: ic.Azure.DefaultMachinePlatform.OSImage.Version,
660+
Offer: ic.Azure.DefaultMachinePlatform.OSImage.Offer,
661+
}
662+
}
663+
controlPlaneOSImage := defaultOSImage
664+
if ic.ControlPlane.Platform.Azure != nil {
665+
controlPlaneOSImage = ic.ControlPlane.Platform.Azure.OSImage
666+
}
667+
allErrs = append(allErrs, validateOSImage(fieldPath.Child("controlplane"), controlPlaneOSImage)...)
668+
computeOSImage := defaultOSImage
669+
if len(ic.Compute) > 0 && ic.Compute[0].Platform.Azure != nil {
670+
computeOSImage = ic.Compute[0].Platform.Azure.OSImage
671+
}
672+
allErrs = append(allErrs, validateOSImage(fieldPath.Child("compute"), computeOSImage)...)
673+
return allErrs
674+
}
675+
func validateOSImage(fieldPath *field.Path, osImage aztypes.OSImage) field.ErrorList {
676+
if _, ok := os.LookupEnv("OPENSHIFT_INSTALL_SKIP_IMAGE_UPLOAD"); ok {
677+
if len(osImage.SKU) > 0 {
678+
return nil
679+
}
680+
return field.ErrorList{field.Invalid(fieldPath, "image", "cannot skip image upload without marketplace image specified")}
681+
}
682+
return nil
683+
}
649684
func validateResourceGroup(client API, fieldPath *field.Path, platform *aztypes.Platform) field.ErrorList {
650685
allErrs := field.ErrorList{}
651686
if len(platform.ResourceGroupName) == 0 {

pkg/asset/machines/azure/azuremachines.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
5858
Offer: osImage.Offer,
5959
SKU: osImage.SKU,
6060
},
61-
Version: osImage.Version,
61+
Version: osImage.Version,
62+
ThirdPartyImage: osImage.Plan != azure.ImageNoPurchasePlan,
6263
},
6364
}
6465
case useImageGallery:

pkg/clusterapi/system.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ func (c *system) Run(ctx context.Context) error {
178178
&Azure,
179179
[]string{
180180
"-v=2",
181-
"--diagnostics-address=0",
182181
"--health-addr={{suggestHealthHostPort}}",
183182
"--webhook-port={{.WebhookPort}}",
184183
"--webhook-cert-dir={{.WebhookCertDir}}",

pkg/infrastructure/azure/azure.go

Lines changed: 97 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"math/rand"
77
"net/http"
8+
"os"
89
"strings"
910
"time"
1011

@@ -239,105 +240,107 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
239240
logrus.Debugf("BlobContainer.ID=%s", *blobContainer.ID)
240241

241242
// Upload the image to the container
242-
_, err = CreatePageBlob(ctx, &CreatePageBlobInput{
243-
StorageURL: storageURL,
244-
BlobURL: blobURL,
245-
ImageURL: imageURL,
246-
ImageLength: imageLength,
247-
StorageAccountName: storageAccountName,
248-
StorageAccountKeys: storageAccountKeys,
249-
CloudConfiguration: cloudConfiguration,
250-
})
251-
if err != nil {
252-
return err
253-
}
254-
255-
// Create image gallery
256-
createImageGalleryOutput, err := CreateImageGallery(ctx, &CreateImageGalleryInput{
257-
SubscriptionID: subscriptionID,
258-
ResourceGroupName: resourceGroupName,
259-
GalleryName: galleryName,
260-
Region: platform.Region,
261-
Tags: tags,
262-
TokenCredential: tokenCredential,
263-
CloudConfiguration: cloudConfiguration,
264-
})
265-
if err != nil {
266-
return err
267-
}
243+
if _, ok := os.LookupEnv("OPENSHIFT_INSTALL_SKIP_IMAGE_UPLOAD"); !ok {
244+
_, err = CreatePageBlob(ctx, &CreatePageBlobInput{
245+
StorageURL: storageURL,
246+
BlobURL: blobURL,
247+
ImageURL: imageURL,
248+
ImageLength: imageLength,
249+
StorageAccountName: storageAccountName,
250+
StorageAccountKeys: storageAccountKeys,
251+
CloudConfiguration: cloudConfiguration,
252+
})
253+
if err != nil {
254+
return err
255+
}
268256

269-
computeClientFactory := createImageGalleryOutput.ComputeClientFactory
257+
// Create image gallery
258+
createImageGalleryOutput, err := CreateImageGallery(ctx, &CreateImageGalleryInput{
259+
SubscriptionID: subscriptionID,
260+
ResourceGroupName: resourceGroupName,
261+
GalleryName: galleryName,
262+
Region: platform.Region,
263+
Tags: tags,
264+
TokenCredential: tokenCredential,
265+
CloudConfiguration: cloudConfiguration,
266+
})
267+
if err != nil {
268+
return err
269+
}
270270

271-
// Create gallery images
272-
_, err = CreateGalleryImage(ctx, &CreateGalleryImageInput{
273-
ResourceGroupName: resourceGroupName,
274-
GalleryName: galleryName,
275-
GalleryImageName: galleryImageName,
276-
Region: platform.Region,
277-
Tags: tags,
278-
TokenCredential: tokenCredential,
279-
CloudConfiguration: cloudConfiguration,
280-
OSType: armcompute.OperatingSystemTypesLinux,
281-
OSState: armcompute.OperatingSystemStateTypesGeneralized,
282-
HyperVGeneration: armcompute.HyperVGenerationV1,
283-
Publisher: "RedHat",
284-
Offer: "rhcos",
285-
SKU: "basic",
286-
ComputeClientFactory: computeClientFactory,
287-
})
288-
if err != nil {
289-
return err
290-
}
271+
computeClientFactory := createImageGalleryOutput.ComputeClientFactory
272+
273+
// Create gallery images
274+
_, err = CreateGalleryImage(ctx, &CreateGalleryImageInput{
275+
ResourceGroupName: resourceGroupName,
276+
GalleryName: galleryName,
277+
GalleryImageName: galleryImageName,
278+
Region: platform.Region,
279+
Tags: tags,
280+
TokenCredential: tokenCredential,
281+
CloudConfiguration: cloudConfiguration,
282+
OSType: armcompute.OperatingSystemTypesLinux,
283+
OSState: armcompute.OperatingSystemStateTypesGeneralized,
284+
HyperVGeneration: armcompute.HyperVGenerationV1,
285+
Publisher: "RedHat",
286+
Offer: "rhcos",
287+
SKU: "basic",
288+
ComputeClientFactory: computeClientFactory,
289+
})
290+
if err != nil {
291+
return err
292+
}
291293

292-
_, err = CreateGalleryImage(ctx, &CreateGalleryImageInput{
293-
ResourceGroupName: resourceGroupName,
294-
GalleryName: galleryName,
295-
GalleryImageName: galleryGen2ImageName,
296-
Region: platform.Region,
297-
Tags: tags,
298-
TokenCredential: tokenCredential,
299-
CloudConfiguration: cloudConfiguration,
300-
OSType: armcompute.OperatingSystemTypesLinux,
301-
OSState: armcompute.OperatingSystemStateTypesGeneralized,
302-
HyperVGeneration: armcompute.HyperVGenerationV1,
303-
Publisher: "RedHat-gen2",
304-
Offer: "rhcos-gen2",
305-
SKU: "gen2",
306-
ComputeClientFactory: computeClientFactory,
307-
})
308-
if err != nil {
309-
return err
310-
}
294+
_, err = CreateGalleryImage(ctx, &CreateGalleryImageInput{
295+
ResourceGroupName: resourceGroupName,
296+
GalleryName: galleryName,
297+
GalleryImageName: galleryGen2ImageName,
298+
Region: platform.Region,
299+
Tags: tags,
300+
TokenCredential: tokenCredential,
301+
CloudConfiguration: cloudConfiguration,
302+
OSType: armcompute.OperatingSystemTypesLinux,
303+
OSState: armcompute.OperatingSystemStateTypesGeneralized,
304+
HyperVGeneration: armcompute.HyperVGenerationV1,
305+
Publisher: "RedHat-gen2",
306+
Offer: "rhcos-gen2",
307+
SKU: "gen2",
308+
ComputeClientFactory: computeClientFactory,
309+
})
310+
if err != nil {
311+
return err
312+
}
311313

312-
// Create gallery image versions
313-
_, err = CreateGalleryImageVersion(ctx, &CreateGalleryImageVersionInput{
314-
ResourceGroupName: resourceGroupName,
315-
StorageAccountID: *storageAccount.ID,
316-
GalleryName: galleryName,
317-
GalleryImageName: galleryImageName,
318-
GalleryImageVersionName: galleryImageVersionName,
319-
Region: platform.Region,
320-
BlobURL: blobURL,
321-
RegionalReplicaCount: int32(1),
322-
ComputeClientFactory: computeClientFactory,
323-
})
324-
if err != nil {
325-
return err
326-
}
314+
// Create gallery image versions
315+
_, err = CreateGalleryImageVersion(ctx, &CreateGalleryImageVersionInput{
316+
ResourceGroupName: resourceGroupName,
317+
StorageAccountID: *storageAccount.ID,
318+
GalleryName: galleryName,
319+
GalleryImageName: galleryImageName,
320+
GalleryImageVersionName: galleryImageVersionName,
321+
Region: platform.Region,
322+
BlobURL: blobURL,
323+
RegionalReplicaCount: int32(1),
324+
ComputeClientFactory: computeClientFactory,
325+
})
326+
if err != nil {
327+
return err
328+
}
327329

328-
_, err = CreateGalleryImageVersion(ctx, &CreateGalleryImageVersionInput{
329-
ResourceGroupName: resourceGroupName,
330-
StorageAccountID: *storageAccount.ID,
331-
GalleryName: galleryName,
332-
GalleryImageName: galleryGen2ImageName,
333-
GalleryImageVersionName: galleryGen2ImageVersionName,
334-
Region: platform.Region,
335-
BlobURL: blobURL,
336-
RegionalReplicaCount: int32(1),
337-
ComputeClientFactory: computeClientFactory,
338-
})
339-
if err != nil {
340-
return err
330+
_, err = CreateGalleryImageVersion(ctx, &CreateGalleryImageVersionInput{
331+
ResourceGroupName: resourceGroupName,
332+
StorageAccountID: *storageAccount.ID,
333+
GalleryName: galleryName,
334+
GalleryImageName: galleryGen2ImageName,
335+
GalleryImageVersionName: galleryGen2ImageVersionName,
336+
Region: platform.Region,
337+
BlobURL: blobURL,
338+
RegionalReplicaCount: int32(1),
339+
ComputeClientFactory: computeClientFactory,
340+
})
341+
if err != nil {
342+
return err
343+
}
341344
}
342345

343346
networkClientFactory, err := armnetwork.NewClientFactory(subscriptionID, session.TokenCreds,

0 commit comments

Comments
 (0)