Skip to content

Commit

Permalink
Merge pull request #4052 from CecileRobertMichon/byo-aks-node
Browse files Browse the repository at this point in the history
Allow joining AzureMachinePools to AKS clusters
  • Loading branch information
k8s-ci-robot authored Nov 4, 2023
2 parents 822ea7d + 74a8a2b commit b81d0c7
Show file tree
Hide file tree
Showing 43 changed files with 1,213 additions and 236 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type AzureManagedControlPlaneSpec struct {
// NetworkPlugin used for building Kubernetes network.
// Allowed values are "azure", "kubenet".
// Immutable.
// +kubebuilder:validation:Enum=azure;kubenet
// +kubebuilder:validation:Enum=azure;kubenet;none
// +optional
NetworkPlugin *string `json:"networkPlugin,omitempty"`

Expand Down
6 changes: 6 additions & 0 deletions azure/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// Reconciler is a generic interface for a controller reconciler which has Reconcile and Delete methods.
Expand Down Expand Up @@ -79,6 +81,7 @@ type NetworkDescriber interface {
type ClusterDescriber interface {
Authorizer
ResourceGroup() string
NodeResourceGroup() string
ClusterName() string
Location() string
ExtendedLocation() *infrav1.ExtendedLocationSpec
Expand All @@ -104,6 +107,9 @@ type AsyncStatusUpdater interface {
type ClusterScoper interface {
ClusterDescriber
NetworkDescriber
AsyncStatusUpdater
GetClient() client.Client
GetDeletionTimestamp() *metav1.Time
}

// ManagedClusterScoper defines the interface for ManagedClusterScope.
Expand Down
132 changes: 132 additions & 0 deletions azure/mock_azure/azure_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (s *ClusterScope) GetClient() client.Client {
return s.Client
}

// GetDeletionTimestamp returns the deletion timestamp of the Cluster.
func (s *ClusterScope) GetDeletionTimestamp() *metav1.Time {
return s.Cluster.DeletionTimestamp
}

// PublicIPSpecs returns the public IP specs.
func (s *ClusterScope) PublicIPSpecs() []azure.ResourceSpecGetter {
var publicIPSpecs []azure.ResourceSpecGetter
Expand Down Expand Up @@ -740,6 +745,12 @@ func (s *ClusterScope) ResourceGroup() string {
return s.AzureCluster.Spec.ResourceGroup
}

// NodeResourceGroup returns the resource group where nodes live.
// For AzureClusters this is the same as the cluster RG.
func (s *ClusterScope) NodeResourceGroup() string {
return s.ResourceGroup()
}

// ClusterName returns the cluster name.
func (s *ClusterScope) ClusterName() string {
return s.Cluster.Name
Expand Down
26 changes: 13 additions & 13 deletions azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (m *MachineScope) VMSpec() azure.ResourceSpecGetter {
Name: m.Name(),
Location: m.Location(),
ExtendedLocation: m.ExtendedLocation(),
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
ClusterName: m.ClusterName(),
Role: m.Role(),
NICIDs: m.NICIDs(),
Expand Down Expand Up @@ -193,7 +193,7 @@ func (m *MachineScope) VMSpec() azure.ResourceSpecGetter {
func (m *MachineScope) TagsSpecs() []azure.TagsSpec {
return []azure.TagsSpec{
{
Scope: azure.VMID(m.SubscriptionID(), m.ResourceGroup(), m.Name()),
Scope: azure.VMID(m.SubscriptionID(), m.NodeResourceGroup(), m.Name()),
Tags: m.AdditionalTags(),
Annotation: azure.VMTagsLastAppliedAnnotation,
},
Expand All @@ -206,7 +206,7 @@ func (m *MachineScope) PublicIPSpecs() []azure.ResourceSpecGetter {
if m.AzureMachine.Spec.AllocatePublicIP {
specs = append(specs, &publicips.PublicIPSpec{
Name: azure.GenerateNodePublicIPName(m.Name()),
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
ClusterName: m.ClusterName(),
DNSName: "", // Set to default value
IsIPv6: false, // Set to default value
Expand All @@ -225,13 +225,13 @@ func (m *MachineScope) InboundNatSpecs() []azure.ResourceSpecGetter {
if m.Role() == infrav1.ControlPlane {
spec := &inboundnatrules.InboundNatSpec{
Name: m.Name(),
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
LoadBalancerName: m.APIServerLBName(),
FrontendIPConfigurationID: nil,
}
if frontEndIPs := m.APIServerLB().FrontendIPs; len(frontEndIPs) > 0 {
ipConfig := frontEndIPs[0].Name
id := azure.FrontendIPConfigID(m.SubscriptionID(), m.ResourceGroup(), m.APIServerLBName(), ipConfig)
id := azure.FrontendIPConfigID(m.SubscriptionID(), m.NodeResourceGroup(), m.APIServerLBName(), ipConfig)
spec.FrontendIPConfigurationID = ptr.To(id)
}

Expand Down Expand Up @@ -260,7 +260,7 @@ func (m *MachineScope) NICSpecs() []azure.ResourceSpecGetter {
func (m *MachineScope) BuildNICSpec(nicName string, infrav1NetworkInterface infrav1.NetworkInterface, primaryNetworkInterface bool) *networkinterfaces.NICSpec {
spec := &networkinterfaces.NICSpec{
Name: nicName,
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
Location: m.Location(),
ExtendedLocation: m.ExtendedLocation(),
SubscriptionID: m.SubscriptionID(),
Expand Down Expand Up @@ -328,13 +328,13 @@ func (m *MachineScope) DiskSpecs() []azure.ResourceSpecGetter {
diskSpecs := make([]azure.ResourceSpecGetter, 1+len(m.AzureMachine.Spec.DataDisks))
diskSpecs[0] = &disks.DiskSpec{
Name: azure.GenerateOSDiskName(m.Name()),
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
}

for i, dd := range m.AzureMachine.Spec.DataDisks {
diskSpecs[i+1] = &disks.DiskSpec{
Name: azure.GenerateDataDiskName(m.Name(), dd.NameSuffix),
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
}
}
return diskSpecs
Expand All @@ -348,7 +348,7 @@ func (m *MachineScope) RoleAssignmentSpecs(principalID *string) []azure.Resource
Name: m.SystemAssignedIdentityName(),
MachineName: m.Name(),
ResourceType: azure.VirtualMachine,
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
Scope: m.SystemAssignedIdentityScope(),
RoleDefinitionID: m.SystemAssignedIdentityDefinitionID(),
PrincipalID: principalID,
Expand Down Expand Up @@ -382,7 +382,7 @@ func (m *MachineScope) VMExtensionSpecs() []azure.ResourceSpecGetter {
Settings: extension.Settings,
ProtectedSettings: extension.ProtectedSettings,
},
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
Location: m.Location(),
})
}
Expand All @@ -393,7 +393,7 @@ func (m *MachineScope) VMExtensionSpecs() []azure.ResourceSpecGetter {
if bootstrapExtensionSpec != nil {
extensionSpecs = append(extensionSpecs, &vmextensions.VMExtensionSpec{
ExtensionSpec: *bootstrapExtensionSpec,
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
Location: m.Location(),
})
}
Expand Down Expand Up @@ -482,7 +482,7 @@ func (m *MachineScope) AvailabilitySetSpec() azure.ResourceSpecGetter {

spec := &availabilitysets.AvailabilitySetSpec{
Name: availabilitySetName,
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
ClusterName: m.ClusterName(),
Location: m.Location(),
SKU: nil,
Expand Down Expand Up @@ -524,7 +524,7 @@ func (m *MachineScope) AvailabilitySet() (string, bool) {
func (m *MachineScope) AvailabilitySetID() string {
var asID string
if asName, ok := m.AvailabilitySet(); ok {
asID = azure.AvailabilitySetID(m.SubscriptionID(), m.ResourceGroup(), asName)
asID = azure.AvailabilitySetID(m.SubscriptionID(), m.NodeResourceGroup(), asName)
}
return asID
}
Expand Down
8 changes: 4 additions & 4 deletions azure/scope/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (m *MachinePoolScope) ScaleSetSpec(ctx context.Context) azure.ResourceSpecG

spec := &scalesets.ScaleSetSpec{
Name: m.Name(),
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
Size: m.AzureMachinePool.Spec.Template.VMSize,
Capacity: int64(ptr.Deref[int32](m.MachinePool.Spec.Replicas, 0)),
SSHKeyData: m.AzureMachinePool.Spec.Template.SSHPublicKey,
Expand Down Expand Up @@ -741,7 +741,7 @@ func (m *MachinePoolScope) RoleAssignmentSpecs(principalID *string) []azure.Reso
roles[0] = &roleassignments.RoleAssignmentSpec{
Name: m.SystemAssignedIdentityName(),
MachineName: m.Name(),
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
ResourceType: azure.VirtualMachineScaleSet,
Scope: m.SystemAssignedIdentityScope(),
RoleDefinitionID: m.SystemAssignedIdentityDefinitionID(),
Expand Down Expand Up @@ -777,7 +777,7 @@ func (m *MachinePoolScope) VMSSExtensionSpecs() []azure.ResourceSpecGetter {
Settings: extension.Settings,
ProtectedSettings: extension.ProtectedSettings,
},
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
})
}

Expand All @@ -787,7 +787,7 @@ func (m *MachinePoolScope) VMSSExtensionSpecs() []azure.ResourceSpecGetter {
if bootstrapExtensionSpec != nil {
extensionSpecs = append(extensionSpecs, &scalesets.VMSSExtensionSpec{
ExtensionSpec: *bootstrapExtensionSpec,
ResourceGroup: m.ResourceGroup(),
ResourceGroup: m.NodeResourceGroup(),
})
}

Expand Down
Loading

0 comments on commit b81d0c7

Please sign in to comment.