sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/bastionhosts/bastionhosts.go (about) 1 /* 2 Copyright 2020 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 22 asonetworkv1 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701" 23 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" 24 "sigs.k8s.io/cluster-api-provider-azure/azure" 25 "sigs.k8s.io/cluster-api-provider-azure/azure/services/aso" 26 "sigs.k8s.io/cluster-api-provider-azure/util/slice" 27 "sigs.k8s.io/controller-runtime/pkg/client" 28 ) 29 30 const serviceName = "bastionhosts" 31 32 // BastionScope defines the scope interface for a bastion host service. 33 type BastionScope interface { 34 aso.Scope 35 AzureBastionSpec() azure.ASOResourceSpecGetter[*asonetworkv1.BastionHost] 36 } 37 38 // New creates a new service. 39 func New(scope BastionScope) *aso.Service[*asonetworkv1.BastionHost, BastionScope] { 40 svc := aso.NewService[*asonetworkv1.BastionHost, BastionScope](serviceName, scope) 41 spec := scope.AzureBastionSpec() 42 if spec != nil { 43 svc.Specs = []azure.ASOResourceSpecGetter[*asonetworkv1.BastionHost]{spec} 44 } 45 svc.ListFunc = list 46 svc.ConditionType = infrav1.BastionHostReadyCondition 47 return svc 48 } 49 50 func list(ctx context.Context, client client.Client, opts ...client.ListOption) ([]*asonetworkv1.BastionHost, error) { 51 list := &asonetworkv1.BastionHostList{} 52 err := client.List(ctx, list, opts...) 53 return slice.ToPtrs(list.Items), err 54 }