Skip to content

Commit 6a8d7e6

Browse files
authored
Merge pull request #1469 from whites11/add-plan-support
Added support for specifying a `plan` for VMs and VMSSes when using a SIG image
2 parents 076a10d + 5dc58ab commit 6a8d7e6

13 files changed

+421
-17
lines changed

api/v1alpha3/azuremachinetemplate_conversion.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha3
1818

1919
import (
20+
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
2021
infrav1alpha4 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha4"
2122
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2223
"sigs.k8s.io/controller-runtime/pkg/conversion"
@@ -44,6 +45,12 @@ func (src *AzureMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { // nol
4445
}
4546
}
4647

48+
if restored.Spec.Template.Spec.Image.SharedGallery != nil {
49+
dst.Spec.Template.Spec.Image.SharedGallery.Offer = restored.Spec.Template.Spec.Image.SharedGallery.Offer
50+
dst.Spec.Template.Spec.Image.SharedGallery.Publisher = restored.Spec.Template.Spec.Image.SharedGallery.Publisher
51+
dst.Spec.Template.Spec.Image.SharedGallery.SKU = restored.Spec.Template.Spec.Image.SharedGallery.SKU
52+
}
53+
4754
return nil
4855
}
4956

@@ -73,3 +80,11 @@ func (dst *AzureMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
7380
src := srcRaw.(*infrav1alpha4.AzureMachineTemplateList)
7481
return Convert_v1alpha4_AzureMachineTemplateList_To_v1alpha3_AzureMachineTemplateList(src, dst, nil)
7582
}
83+
84+
func Convert_v1alpha4_AzureSharedGalleryImage_To_v1alpha3_AzureSharedGalleryImage(in *infrav1alpha4.AzureSharedGalleryImage, out *AzureSharedGalleryImage, s apimachineryconversion.Scope) error { // nolint
85+
if err := autoConvert_v1alpha4_AzureSharedGalleryImage_To_v1alpha3_AzureSharedGalleryImage(in, out, s); err != nil {
86+
return err
87+
}
88+
89+
return nil
90+
}

api/v1alpha3/zz_generated.conversion.go

Lines changed: 44 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha4/types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,23 @@ type AzureSharedGalleryImage struct {
322322
// time even if a new version becomes available.
323323
// +kubebuilder:validation:MinLength=1
324324
Version string `json:"version"`
325+
// Publisher is the name of the organization that created the image.
326+
// This value will be used to add a `Plan` in the API request when creating the VM/VMSS resource.
327+
// This is needed when the source image from which this SIG image was built requires the `Plan` to be used.
328+
// +optional
329+
Publisher *string `json:"publisher,omitempty"`
330+
// Offer specifies the name of a group of related images created by the publisher.
331+
// For example, UbuntuServer, WindowsServer
332+
// This value will be used to add a `Plan` in the API request when creating the VM/VMSS resource.
333+
// This is needed when the source image from which this SIG image was built requires the `Plan` to be used.
334+
// +optional
335+
Offer *string `json:"offer,omitempty"`
336+
// SKU specifies an instance of an offer, such as a major release of a distribution.
337+
// For example, 18.04-LTS, 2019-Datacenter
338+
// This value will be used to add a `Plan` in the API request when creating the VM/VMSS resource.
339+
// This is needed when the source image from which this SIG image was built requires the `Plan` to be used.
340+
// +optional
341+
SKU *string `json:"sku,omitempty"`
325342
}
326343

327344
// VMIdentity defines the identity of the virtual machine, if configured.

api/v1alpha4/zz_generated.deepcopy.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure/services/scalesets/scalesets.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet
385385
Capacity: to.Int64Ptr(vmssSpec.Capacity),
386386
},
387387
Zones: to.StringSlicePtr(vmssSpec.FailureDomains),
388+
Plan: s.generateImagePlan(),
388389
VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{
389390
UpgradePolicy: &compute.UpgradePolicy{
390391
Mode: compute.UpgradeModeManual,
@@ -631,6 +632,36 @@ func (s *Service) generateOSProfile(ctx context.Context, vmssSpec azure.ScaleSet
631632
return osProfile, nil
632633
}
633634

635+
func (s *Service) generateImagePlan() *compute.Plan {
636+
image, err := s.Scope.GetVMImage()
637+
if err != nil {
638+
s.Scope.Error(err, "failed to get vm image, disabling Plan")
639+
return nil
640+
}
641+
642+
if image.SharedGallery != nil && image.SharedGallery.Publisher != nil && image.SharedGallery.SKU != nil && image.SharedGallery.Offer != nil {
643+
return &compute.Plan{
644+
Publisher: image.SharedGallery.Publisher,
645+
Name: image.SharedGallery.SKU,
646+
Product: image.SharedGallery.Offer,
647+
}
648+
}
649+
650+
if image.Marketplace == nil || !image.Marketplace.ThirdPartyImage {
651+
return nil
652+
}
653+
654+
if image.Marketplace.Publisher == "" || image.Marketplace.SKU == "" || image.Marketplace.Offer == "" {
655+
return nil
656+
}
657+
658+
return &compute.Plan{
659+
Publisher: to.StringPtr(image.Marketplace.Publisher),
660+
Name: to.StringPtr(image.Marketplace.SKU),
661+
Product: to.StringPtr(image.Marketplace.Offer),
662+
}
663+
}
664+
634665
func getVMSSUpdateFromVMSS(vmss compute.VirtualMachineScaleSet) (compute.VirtualMachineScaleSetUpdate, error) {
635666
jsonData, err := vmss.MarshalJSON()
636667
if err != nil {

azure/services/scalesets/scalesets_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ func setupDefaultVMSSExpectations(s *mock_scalesets.MockScaleSetScopeMockRecorde
10571057
Version: "1.0",
10581058
},
10591059
}
1060-
s.GetVMImage().Return(image, nil)
1060+
s.GetVMImage().Return(image, nil).AnyTimes()
10611061
s.SaveVMImageToStatus(image)
10621062
}
10631063

@@ -1071,7 +1071,7 @@ func setupUpdateVMSSExpectations(s *mock_scalesets.MockScaleSetScopeMockRecorder
10711071
Version: "2.0",
10721072
},
10731073
}
1074-
s.GetVMImage().Return(image, nil)
1074+
s.GetVMImage().Return(image, nil).AnyTimes()
10751075
s.SaveVMImageToStatus(image)
10761076
}
10771077

azure/services/virtualmachines/virtualmachines.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,18 @@ func (s *Service) getExisting(ctx context.Context, name string) (*infrav1.VM, er
251251
func (s *Service) generateImagePlan() *compute.Plan {
252252
image, err := s.Scope.GetVMImage()
253253
if err != nil {
254+
s.Scope.Error(err, "failed to get vm image, disabling Plan")
254255
return nil
255256
}
256257

258+
if image.SharedGallery != nil && image.SharedGallery.Publisher != nil && image.SharedGallery.SKU != nil && image.SharedGallery.Offer != nil {
259+
return &compute.Plan{
260+
Publisher: image.SharedGallery.Publisher,
261+
Name: image.SharedGallery.SKU,
262+
Product: image.SharedGallery.Offer,
263+
}
264+
}
265+
257266
if image.Marketplace == nil || !image.Marketplace.ThirdPartyImage {
258267
return nil
259268
}

0 commit comments

Comments
 (0)