Skip to content

Commit

Permalink
Add identity field
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Dec 12, 2023
1 parent 07d7bac commit a428181
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ type MarketplaceExtension struct {
// Version is the version of the extension.
// +optional
Version *string `json:"version,omitempty"`

// Identity is the identity type of the Extension resource in an AKS cluster.
// +optional
Identity ExtensionIdentity `json:"identity,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
28 changes: 23 additions & 5 deletions api/v1beta1/azuremanagedcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,15 @@ func (m *AzureManagedControlPlane) validateOIDCIssuerProfileUpdate(old *AzureMan
func (m *AzureManagedControlPlane) validateMarketplaceExtensionsUpdate(old *AzureManagedControlPlane) field.ErrorList {
var allErrs field.ErrorList

if m.Spec.MarketplaceExtensions != nil && old.Spec.MarketplaceExtensions != nil {
for i, extension := range m.Spec.MarketplaceExtensions {
if extension.Name != old.Spec.MarketplaceExtensions[i].Name {
oldMarketplaceExtensionsMap := make(map[string]MarketplaceExtension, len(old.Spec.MarketplaceExtensions))
oldMarketplaceExtensionsIndex := make(map[string]int, len(old.Spec.MarketplaceExtensions))
for i, extension := range old.Spec.MarketplaceExtensions {
oldMarketplaceExtensionsMap[extension.Name] = extension
oldMarketplaceExtensionsIndex[extension.Name] = i
}

Check warning on line 695 in api/v1beta1/azuremanagedcontrolplane_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azuremanagedcontrolplane_webhook.go#L693-L695

Added lines #L693 - L695 were not covered by tests
for i, extension := range m.Spec.MarketplaceExtensions {
if oldExtension, ok := oldMarketplaceExtensionsMap[extension.Name]; ok {
if extension.Name != oldExtension.Name {
allErrs = append(allErrs,
field.Invalid(
field.NewPath("Spec", "MarketplaceExtensions", fmt.Sprintf("[%d]", i), "Name"),
Expand All @@ -698,7 +704,16 @@ func (m *AzureManagedControlPlane) validateMarketplaceExtensionsUpdate(old *Azur
),
)
}
if extension.Plan.Publisher != old.Spec.MarketplaceExtensions[i].Plan.Publisher {
if extension.ExtensionType != oldExtension.ExtensionType {
allErrs = append(allErrs,
field.Invalid(
field.NewPath("Spec", "MarketplaceExtensions", fmt.Sprintf("[%d]", i), "ExtensionType"),
extension.ExtensionType,
"field is immutable",
),
)
}
if extension.Plan.Publisher != oldExtension.Plan.Publisher {
allErrs = append(allErrs,
field.Invalid(
field.NewPath("Spec", "MarketplaceExtensions", fmt.Sprintf("[%d]", i), "Publisher"),
Expand All @@ -707,7 +722,7 @@ func (m *AzureManagedControlPlane) validateMarketplaceExtensionsUpdate(old *Azur
),
)
}
if extension.Plan.Product != old.Spec.MarketplaceExtensions[i].Plan.Product {
if extension.Plan.Product != oldExtension.Plan.Product {
allErrs = append(allErrs,
field.Invalid(
field.NewPath("Spec", "MarketplaceExtensions", fmt.Sprintf("[%d]", i), "Product"),
Expand Down Expand Up @@ -746,6 +761,9 @@ func validateMarketplaceExtensions(extensions []MarketplaceExtension, fldPath *f
if extension.Plan.Publisher == "" {
allErrs = append(allErrs, field.Required(fldPath.Child("Plan", "Publisher"), "Publisher must be provided"))
}
if extension.AutoUpgradeMinorVersion == ptr.To(false) && extension.ReleaseTrain != nil {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("ReleaseTrain"), "ReleaseTrain must not be given if AutoUpgradeMinorVersion is false"))
}

Check warning on line 766 in api/v1beta1/azuremanagedcontrolplane_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azuremanagedcontrolplane_webhook.go#L765-L766

Added lines #L765 - L766 were not covered by tests
}

return allErrs
Expand Down
11 changes: 11 additions & 0 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,3 +1109,14 @@ type MarketplacePlan struct {
// +optional
Version string `json:"version,omitempty"`
}

// ExtensionIdentity defines the identity of the aks marketplace extension, if configured.
// +kubebuilder:validation:Enum=SystemAssigned;UserAssigned
type ExtensionIdentity string

const (
// ExtensionIdentitySystemAssigned ...
ExtensionIdentitySystemAssigned ExtensionIdentity = "SystemAssigned"
// ExtensionIdentityUserAssigned ...
ExtensionIdentityUserAssigned ExtensionIdentity = "UserAssigned"
)
2 changes: 1 addition & 1 deletion azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ func (s *ManagedControlPlaneScope) AKSExtensionSpecs() []azure.ASOResourceSpecGe
Owner: azure.ManagedClusterID(s.SubscriptionID(), s.ResourceGroup(), s.ControlPlane.Name),
OwnerRef: *metav1.NewControllerRef(s.ControlPlane, infrav1.GroupVersion.WithKind(infrav1.AzureManagedControlPlaneKind)),
Plan: *extension.Plan,
// AKSAssignedIdentityType: extension.AKSAssignedIdentityType,
AKSAssignedIdentityType: extension.Identity,
}

extensionSpecs = append(extensionSpecs, extensionSpec)
Expand Down
7 changes: 6 additions & 1 deletion azure/services/aksextensions/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
type AKSExtensionSpec struct {
Name string
Namespace string
AKSAssignedIdentityType string
AKSAssignedIdentityType infrav1.ExtensionIdentity
AutoUpgradeMinorVersion *bool
ConfigurationSettings map[string]string
ExtensionType *string
Expand Down Expand Up @@ -77,6 +77,11 @@ func (s *AKSExtensionSpec) Parameters(ctx context.Context, existingAKSExtension
Publisher: ptr.To(s.Plan.Publisher),
Version: ptr.To(s.Plan.Version),
}
if s.AKSAssignedIdentityType != "" {
aksExtension.Spec.Identity = &asokubernetesconfigurationv1.Identity{
Type: (*asokubernetesconfigurationv1.Identity_Type)(&s.AKSAssignedIdentityType),
}
}

return aksExtension, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ spec:
Types registered with Microsoft.KubernetesConfiguration by
the Extension publisher.
type: string
identity:
description: Identity is the identity type of the Extension
resource in an AKS cluster.
enum:
- SystemAssigned
- UserAssigned
type: string
name:
description: Name is the name of the extension.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ spec:
be one of the Extension Types registered with Microsoft.KubernetesConfiguration
by the Extension publisher.
type: string
identity:
description: Identity is the identity type of the Extension
resource in an AKS cluster.
enum:
- SystemAssigned
- UserAssigned
type: string
name:
description: Name is the name of the extension.
type: string
Expand Down

0 comments on commit a428181

Please sign in to comment.