Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use CAPZ community gallery for default VM images #5167

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion azure/converters/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func GetOrchestrationMode(modeType infrav1.OrchestrationModeType) armcompute.Orc
return armcompute.OrchestrationModeUniform
}

// IDImageRefToImage converts an ID to a infrav1.Image with ComputerGallery set or ID, depending on the structure of the ID.
// IDImageRefToImage converts an ID to a infrav1.Image with ComputeGallery set or ID, depending on the structure of the ID.
func IDImageRefToImage(id string) infrav1.Image {
// compute gallery image
if ok, params := getParams(RegExpStrComputeGalleryID, id); ok {
Expand Down
6 changes: 6 additions & 0 deletions azure/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ const (
DefaultImagePublisherID = "cncf-upstream"
// LatestVersion is the image version latest.
LatestVersion = "latest"
// DefaultPublicGalleryName is the default Azure Compute Gallery.
DefaultPublicGalleryName = "capzed-489de9a5-a0a0-4e79-a806-ad5479ec43a5"
// DefaultLinuxGalleryImageName is the default Azure Linux Gallery Image Name.
DefaultLinuxGalleryImageName = "capi-ubun2-2404"
// DefaultWindowsGalleryImageName is the default Azure Windows Gallery Image Name.
DefaultWindowsGalleryImageName = "capi-win-2022-containerd"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func (m *MachineScope) GetVMImage(ctx context.Context) (*infrav1.Image, error) {
}

log.Info("No image specified for machine, using default Linux Image", "machine", m.AzureMachine.GetName())
return svc.GetDefaultUbuntuImage(ctx, m.Location(), ptr.Deref(m.Machine.Spec.Version, ""))
return svc.GetDefaultLinuxImage(ctx, m.Location(), ptr.Deref(m.Machine.Spec.Version, ""))
}

// SetSubnetName defaults the AzureMachine subnet name to the name of one the subnets with the machine role when there is only one of them.
Expand Down
109 changes: 9 additions & 100 deletions azure/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/azure/services/resourceskus"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/roleassignments"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualmachineimages"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualmachineimages/mock_virtualmachineimages"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/vmextensions"
)

Expand Down Expand Up @@ -1538,7 +1537,7 @@ func TestMachineScope_GetVMImage(t *testing.T) {
clusterMock.EXPECT().SubscriptionID().AnyTimes()
clusterMock.EXPECT().CloudEnvironment().AnyTimes()
clusterMock.EXPECT().Token().Return(&azidentity.DefaultAzureCredential{}).AnyTimes()
svc := virtualmachineimages.Service{Client: mock_virtualmachineimages.NewMockClient(mockCtrl)}
svc := virtualmachineimages.Service{}

tests := []struct {
name string
Expand All @@ -1547,7 +1546,7 @@ func TestMachineScope_GetVMImage(t *testing.T) {
expectedErr string
}{
{
name: "returns AzureMachine image is found if present in the AzureMachine spec",
name: "returns AzureMachine image if present in the AzureMachine spec",
machineScope: MachineScope{
AzureMachine: &infrav1.AzureMachine{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1566,7 +1565,7 @@ func TestMachineScope_GetVMImage(t *testing.T) {
expectedErr: "",
},
{
name: "if no image is specified and os specified is windows with version below 1.22, returns windows dockershim image",
name: "if no image is specified and os specified is windows, returns windows containerd image",
machineScope: MachineScope{
Machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1589,42 +1588,13 @@ func TestMachineScope_GetVMImage(t *testing.T) {
ClusterScoper: clusterMock,
},
want: func() *infrav1.Image {
image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.20.1", "dockershim", "")
image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.20.1", "containerd", "")
return image
}(),
expectedErr: "",
},
{
name: "if no image is specified and os specified is windows with version is 1.22+ with no annotation, returns windows containerd image",
machineScope: MachineScope{
Machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
},
Spec: clusterv1.MachineSpec{
Version: ptr.To("1.22.1"),
},
},
AzureMachine: &infrav1.AzureMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
},
Spec: infrav1.AzureMachineSpec{
OSDisk: infrav1.OSDisk{
OSType: azure.WindowsOS,
},
},
},
ClusterScoper: clusterMock,
},
want: func() *infrav1.Image {
image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.22.1", "containerd", "")
return image
}(),
expectedErr: "",
},
{
name: "if no image is specified and os specified is windows with version is 1.22+ with annotation dockershim, returns windows dockershim image",
name: "if no image is specified and os specified is windows with annotation dockershim, returns error",
machineScope: MachineScope{
Machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1653,71 +1623,10 @@ func TestMachineScope_GetVMImage(t *testing.T) {
image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.22.1", "dockershim", "")
return image
}(),
expectedErr: "",
},
{
name: "if no image is specified and os specified is windows with version is less and 1.22 with annotation dockershim, returns windows dockershim image",
machineScope: MachineScope{
Machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
},
Spec: clusterv1.MachineSpec{
Version: ptr.To("1.21.1"),
},
},
AzureMachine: &infrav1.AzureMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
Annotations: map[string]string{
"runtime": "dockershim",
},
},
Spec: infrav1.AzureMachineSpec{
OSDisk: infrav1.OSDisk{
OSType: azure.WindowsOS,
},
},
},
ClusterScoper: clusterMock,
},
want: func() *infrav1.Image {
image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.21.1", "dockershim", "")
return image
}(),
expectedErr: "",
expectedErr: "unsupported runtime dockershim",
},
{
name: "if no image is specified and os specified is windows with version is less and 1.22 with annotation containerd, returns error",
machineScope: MachineScope{
Machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
},
Spec: clusterv1.MachineSpec{
Version: ptr.To("1.21.1"),
},
},
AzureMachine: &infrav1.AzureMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
Annotations: map[string]string{
"runtime": "containerd",
},
},
Spec: infrav1.AzureMachineSpec{
OSDisk: infrav1.OSDisk{
OSType: azure.WindowsOS,
},
},
},
ClusterScoper: clusterMock,
},
want: nil,
expectedErr: "containerd image only supported in 1.22+",
},
{
name: "if no image is specified and os specified is windows with windowsServerVersion annotation set to 2019, retrurns 2019 image",
name: "if no image is specified and os specified is windows with windowsServerVersion annotation set to 2019, returns error",
machineScope: MachineScope{
Machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1746,7 +1655,7 @@ func TestMachineScope_GetVMImage(t *testing.T) {
image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.23.3", "", "windows-2019")
return image
}(),
expectedErr: "",
expectedErr: "unsupported osAndVersion windows-2019",
},
{
name: "if no image is specified and os specified is windows with windowsServerVersion annotation set to 2022, retrurns 2022 image",
Expand Down Expand Up @@ -1799,7 +1708,7 @@ func TestMachineScope_GetVMImage(t *testing.T) {
ClusterScoper: clusterMock,
},
want: func() *infrav1.Image {
image, _ := svc.GetDefaultUbuntuImage(context.TODO(), "", "1.20.1")
image, _ := svc.GetDefaultLinuxImage(context.TODO(), "", "1.20.1")
return image
}(),
expectedErr: "",
Expand Down
2 changes: 1 addition & 1 deletion azure/scope/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ func (m *MachinePoolScope) GetVMImage(ctx context.Context) (*infrav1.Image, erro
log.V(4).Info("No image specified for machine, using default Windows Image", "machine", m.MachinePool.GetName(), "runtime", runtime, "windowsServerVersion", windowsServerVersion)
defaultImage, err = svc.GetDefaultWindowsImage(ctx, m.Location(), ptr.Deref(m.MachinePool.Spec.Template.Spec.Version, ""), runtime, windowsServerVersion)
} else {
defaultImage, err = svc.GetDefaultUbuntuImage(ctx, m.Location(), ptr.Deref(m.MachinePool.Spec.Template.Spec.Version, ""))
defaultImage, err = svc.GetDefaultLinuxImage(ctx, m.Location(), ptr.Deref(m.MachinePool.Spec.Template.Spec.Version, ""))
}

if err != nil {
Expand Down
12 changes: 4 additions & 8 deletions azure/scope/machinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,10 @@ func TestMachinePoolScope_GetVMImage(t *testing.T) {
Verify: func(g *WithT, amp *infrav1exp.AzureMachinePool, vmImage *infrav1.Image, err error) {
g.Expect(err).NotTo(HaveOccurred())
image := &infrav1.Image{
Marketplace: &infrav1.AzureMarketplaceImage{
ImagePlan: infrav1.ImagePlan{
Publisher: "cncf-upstream",
Offer: "capi",
SKU: "k8s-1dot19dot11-ubuntu-1804",
},
Version: "latest",
ThirdPartyImage: false,
ComputeGallery: &infrav1.AzureComputeGalleryImage{
Gallery: "capzed-489de9a5-a0a0-4e79-a806-ad5479ec43a5",
Name: "capi-ubun2-2404",
Version: "1.19.11",
},
}
g.Expect(vmImage).To(Equal(image))
Expand Down
134 changes: 0 additions & 134 deletions azure/services/virtualmachineimages/cache.go

This file was deleted.

Loading