sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/aksextensions/spec.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package aksextensions 18 19 import ( 20 "context" 21 22 asokubernetesconfigurationv1 "github.com/Azure/azure-service-operator/v2/api/kubernetesconfiguration/v1api20230501" 23 "github.com/Azure/azure-service-operator/v2/pkg/genruntime" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 "k8s.io/utils/ptr" 26 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" 27 ) 28 29 // AKSExtensionSpec defines the specification for an AKS Extension. 30 type AKSExtensionSpec struct { 31 Name string 32 Namespace string 33 AKSAssignedIdentityType infrav1.AKSAssignedIdentity 34 ExtensionIdentity infrav1.ExtensionIdentity 35 AutoUpgradeMinorVersion *bool 36 ConfigurationSettings map[string]string 37 ExtensionType *string 38 ReleaseTrain *string 39 Version *string 40 Owner string 41 OwnerRef metav1.OwnerReference 42 Plan *infrav1.ExtensionPlan 43 Scope infrav1.ExtensionScope 44 } 45 46 // ResourceRef implements azure.ASOResourceSpecGetter. 47 func (s *AKSExtensionSpec) ResourceRef() *asokubernetesconfigurationv1.Extension { 48 return &asokubernetesconfigurationv1.Extension{ 49 ObjectMeta: metav1.ObjectMeta{ 50 Name: s.Name, 51 Namespace: s.Namespace, 52 }, 53 } 54 } 55 56 // Parameters implements azure.ASOResourceSpecGetter. 57 func (s *AKSExtensionSpec) Parameters(ctx context.Context, existingAKSExtension *asokubernetesconfigurationv1.Extension) (parameters *asokubernetesconfigurationv1.Extension, err error) { 58 aksExtension := &asokubernetesconfigurationv1.Extension{} 59 if existingAKSExtension != nil { 60 aksExtension = existingAKSExtension 61 } 62 63 aksExtension.Spec = asokubernetesconfigurationv1.Extension_Spec{} 64 aksExtension.Spec.AzureName = s.Name 65 aksExtension.Spec.AutoUpgradeMinorVersion = s.AutoUpgradeMinorVersion 66 aksExtension.Spec.ConfigurationSettings = s.ConfigurationSettings 67 aksExtension.Spec.ExtensionType = s.ExtensionType 68 aksExtension.Spec.ReleaseTrain = s.ReleaseTrain 69 aksExtension.Spec.Version = s.Version 70 aksExtension.Spec.Owner = &genruntime.ArbitraryOwnerReference{ 71 ARMID: s.Owner, 72 } 73 74 if s.Plan != nil { 75 aksExtension.Spec.Plan = &asokubernetesconfigurationv1.Plan{ 76 Name: ptr.To(s.Plan.Name), 77 Product: ptr.To(s.Plan.Product), 78 Publisher: ptr.To(s.Plan.Publisher), 79 Version: ptr.To(s.Plan.Version), 80 } 81 } 82 if s.ExtensionIdentity != "" { 83 aksExtension.Spec.Identity = &asokubernetesconfigurationv1.Identity{ 84 Type: (*asokubernetesconfigurationv1.Identity_Type)(ptr.To(s.ExtensionIdentity)), 85 } 86 } 87 if s.AKSAssignedIdentityType != "" { 88 aksExtension.Spec.AksAssignedIdentity = &asokubernetesconfigurationv1.Extension_Properties_AksAssignedIdentity_Spec{ 89 Type: (*asokubernetesconfigurationv1.Extension_Properties_AksAssignedIdentity_Type_Spec)(ptr.To(s.AKSAssignedIdentityType)), 90 } 91 } 92 if s.Scope.ScopeType == infrav1.ExtensionScopeCluster { 93 aksExtension.Spec.Scope = &asokubernetesconfigurationv1.Scope{ 94 Cluster: &asokubernetesconfigurationv1.ScopeCluster{ 95 ReleaseNamespace: ptr.To(s.Scope.ReleaseNamespace), 96 }, 97 } 98 } else if s.Scope.ScopeType == infrav1.ExtensionScopeNamespace { 99 aksExtension.Spec.Scope = &asokubernetesconfigurationv1.Scope{ 100 Namespace: &asokubernetesconfigurationv1.ScopeNamespace{ 101 TargetNamespace: ptr.To(s.Scope.TargetNamespace), 102 }, 103 } 104 } 105 106 return aksExtension, nil 107 } 108 109 // WasManaged implements azure.ASOResourceSpecGetter. 110 func (s *AKSExtensionSpec) WasManaged(resource *asokubernetesconfigurationv1.Extension) bool { 111 // returns always returns true as CAPZ does not support BYO extension. 112 return true 113 }