sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/interfaces.go (about) 1 /* 2 Copyright 2018 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 azure 18 19 import ( 20 "context" 21 "time" 22 23 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 24 "github.com/Azure/azure-service-operator/v2/pkg/genruntime" 25 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" 27 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 28 "sigs.k8s.io/controller-runtime/pkg/client" 29 ) 30 31 // Reconciler is a generic interface for a controller reconciler which has Reconcile and Delete methods. 32 type Reconciler interface { 33 Reconcile(ctx context.Context) error 34 Delete(ctx context.Context) error 35 } 36 37 // Pauser may be implemented for a ServiceReconciler that requires additional work to stop reconciliation. 38 type Pauser interface { 39 Pause(context.Context) error 40 } 41 42 // ServiceReconciler is an Azure service reconciler which can reconcile an Azure service. 43 type ServiceReconciler interface { 44 Name() string 45 Reconciler 46 } 47 48 // Authorizer is an interface which can get details such as subscription ID, base URI, and token 49 // for authorizing to an Azure service. 50 type Authorizer interface { 51 SubscriptionID() string 52 ClientID() string 53 ClientSecret() string 54 CloudEnvironment() string 55 TenantID() string 56 BaseURI() string 57 HashKey() string 58 Token() azcore.TokenCredential 59 } 60 61 // NetworkDescriber is an interface which can get common Azure Cluster Networking information. 62 type NetworkDescriber interface { 63 Vnet() *infrav1.VnetSpec 64 IsVnetManaged() bool 65 ControlPlaneSubnet() infrav1.SubnetSpec 66 Subnets() infrav1.Subnets 67 Subnet(string) infrav1.SubnetSpec 68 NodeSubnets() []infrav1.SubnetSpec 69 SetSubnet(infrav1.SubnetSpec) 70 IsIPv6Enabled() bool 71 ControlPlaneRouteTable() infrav1.RouteTable 72 APIServerLB() *infrav1.LoadBalancerSpec 73 APIServerLBName() string 74 APIServerLBPoolName() string 75 IsAPIServerPrivate() bool 76 GetPrivateDNSZoneName() string 77 OutboundLBName(string) string 78 OutboundPoolName(string) string 79 } 80 81 // ClusterDescriber is an interface which can get common Azure Cluster information. 82 type ClusterDescriber interface { 83 Authorizer 84 ResourceGroup() string 85 NodeResourceGroup() string 86 ClusterName() string 87 Location() string 88 ExtendedLocation() *infrav1.ExtendedLocationSpec 89 ExtendedLocationName() string 90 ExtendedLocationType() string 91 AdditionalTags() infrav1.Tags 92 AvailabilitySetEnabled() bool 93 CloudProviderConfigOverrides() *infrav1.CloudProviderConfigOverrides 94 FailureDomains() []*string 95 } 96 97 // AsyncStatusUpdater is an interface used to keep track of long running operations in Status that has Conditions and Futures. 98 type AsyncStatusUpdater interface { 99 SetLongRunningOperationState(*infrav1.Future) 100 GetLongRunningOperationState(string, string, string) *infrav1.Future 101 DeleteLongRunningOperationState(string, string, string) 102 UpdatePutStatus(clusterv1.ConditionType, string, error) 103 UpdateDeleteStatus(clusterv1.ConditionType, string, error) 104 UpdatePatchStatus(clusterv1.ConditionType, string, error) 105 AsyncReconciler 106 } 107 108 // AsyncReconciler is an interface used to get the default timeouts and requeue time for a reconciler that reconciles services asynchronously. 109 type AsyncReconciler interface { 110 DefaultedAzureCallTimeout() time.Duration 111 DefaultedAzureServiceReconcileTimeout() time.Duration 112 DefaultedReconcilerRequeue() time.Duration 113 } 114 115 // ClusterScoper combines the ClusterDescriber and NetworkDescriber interfaces. 116 type ClusterScoper interface { 117 ClusterDescriber 118 NetworkDescriber 119 AsyncStatusUpdater 120 GetClient() client.Client 121 GetDeletionTimestamp() *metav1.Time 122 } 123 124 // ManagedClusterScoper defines the interface for ManagedClusterScope. 125 type ManagedClusterScoper interface { 126 ClusterDescriber 127 NodeResourceGroup() string 128 AsyncReconciler 129 } 130 131 // ResourceSpecGetter is an interface for getting all the required information to create/update/delete an Azure resource. 132 type ResourceSpecGetter interface { 133 // ResourceName returns the name of the resource. 134 ResourceName() string 135 // OwnerResourceName returns the name of the resource that owns the resource 136 // in the case that the resource is an Azure subresource. 137 OwnerResourceName() string 138 // ResourceGroupName returns the name of the resource group the resource is in. 139 ResourceGroupName() string 140 // Parameters takes the existing resource and returns the desired parameters of the resource. 141 // If the resource does not exist, or we do not care about existing parameters to update the resource, existing should be nil. 142 // If no update is needed on the resource, Parameters should return nil. 143 Parameters(ctx context.Context, existing interface{}) (params interface{}, err error) 144 } 145 146 // ResourceSpecGetterWithHeaders is a ResourceSpecGetter that can return custom headers to be added to API calls. 147 type ResourceSpecGetterWithHeaders interface { 148 ResourceSpecGetter 149 // CustomHeaders returns the headers that should be added to Azure API calls. 150 CustomHeaders() map[string]string 151 } 152 153 // ASOResourceSpecGetter is an interface for getting all the required information to create/update/delete an Azure resource. 154 type ASOResourceSpecGetter[T genruntime.MetaObject] interface { 155 // ResourceRef returns a concrete, named ASO resource type to facilitate a 156 // strongly-typed GET. Namespace is not read if set here and is instead 157 // derived from OwnerReferences. 158 ResourceRef() T 159 // Parameters returns a modified object if it points to a non-nil resource. 160 // Otherwise it returns an unmodified object if no updates are needed. 161 Parameters(ctx context.Context, existing T) (T, error) 162 // WasManaged returns whether or not the given resource was managed by a 163 // non-ASO-backed CAPZ and should be considered eligible for adoption. 164 WasManaged(T) bool 165 }