sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/bastionhosts/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 bastionhosts 18 19 import ( 20 "context" 21 "fmt" 22 "strings" 23 24 asonetworkv1 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701" 25 "github.com/Azure/azure-service-operator/v2/pkg/genruntime" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 "k8s.io/utils/ptr" 28 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" 29 ) 30 31 // AzureBastionSpec defines the specification for azure bastion feature. 32 type AzureBastionSpec struct { 33 Name string 34 ResourceGroup string 35 Location string 36 ClusterName string 37 SubnetID string 38 PublicIPID string 39 Sku infrav1.BastionHostSkuName 40 EnableTunneling bool 41 } 42 43 // ResourceRef implements azure.ASOResourceSpecGetter. 44 func (s *AzureBastionSpec) ResourceRef() *asonetworkv1.BastionHost { 45 return &asonetworkv1.BastionHost{ 46 ObjectMeta: metav1.ObjectMeta{ 47 Name: s.Name, 48 }, 49 } 50 } 51 52 // Parameters implements azure.ASOResourceSpecGetter. 53 func (s *AzureBastionSpec) Parameters(ctx context.Context, existingBastionHost *asonetworkv1.BastionHost) (parameters *asonetworkv1.BastionHost, err error) { 54 bastionHost := &asonetworkv1.BastionHost{} 55 if existingBastionHost != nil { 56 bastionHost = existingBastionHost 57 } 58 59 bastionHostIPConfigName := fmt.Sprintf("%s-%s", s.Name, "bastionIP") 60 bastionHost.Spec.AzureName = s.Name 61 bastionHost.Spec.Location = ptr.To(s.Location) 62 bastionHost.Spec.Owner = &genruntime.KnownResourceReference{ 63 Name: s.ResourceGroup, 64 } 65 bastionHost.Spec.Tags = infrav1.Build(infrav1.BuildParams{ 66 ClusterName: s.ClusterName, 67 Lifecycle: infrav1.ResourceLifecycleOwned, 68 Name: ptr.To(s.Name), 69 Role: ptr.To("Bastion"), 70 }) 71 bastionHost.Spec.Sku = &asonetworkv1.Sku{ 72 Name: ptr.To(asonetworkv1.Sku_Name(s.Sku)), 73 } 74 bastionHost.Spec.EnableTunneling = ptr.To(s.EnableTunneling) 75 bastionHost.Spec.DnsName = ptr.To(fmt.Sprintf("%s-bastion", strings.ToLower(s.Name))) 76 bastionHost.Spec.IpConfigurations = []asonetworkv1.BastionHostIPConfiguration{ 77 { 78 Name: ptr.To(bastionHostIPConfigName), 79 Subnet: &asonetworkv1.BastionHostSubResource{ 80 Reference: &genruntime.ResourceReference{ 81 ARMID: s.SubnetID, 82 }, 83 }, 84 PublicIPAddress: &asonetworkv1.BastionHostSubResource{ 85 Reference: &genruntime.ResourceReference{ 86 ARMID: s.PublicIPID, 87 }, 88 }, 89 PrivateIPAllocationMethod: ptr.To(asonetworkv1.IPAllocationMethod_Dynamic), 90 }, 91 } 92 93 return bastionHost, nil 94 } 95 96 // WasManaged implements azure.ASOResourceSpecGetter. 97 func (s *AzureBastionSpec) WasManaged(resource *asonetworkv1.BastionHost) bool { 98 // returns always returns true as CAPZ does not support BYO bastion. 99 return true 100 }