Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Oct 17, 2023
1 parent 831ac19 commit d7f3b9f
Show file tree
Hide file tree
Showing 9 changed files with 601 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ WEBHOOK_ROOT ?= $(MANIFEST_ROOT)/webhook
RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac
ASO_CRDS_PATH := $(MANIFEST_ROOT)/aso/crds.yaml
ASO_VERSION := v2.3.0
ASO_CRDS := resourcegroups.resources.azure.com natgateways.network.azure.com
ASO_CRDS := resourcegroups.resources.azure.com natgateways.network.azure.com bastionhosts.network.azure.com

# Allow overriding the imagePullPolicy
PULL_POLICY ?= Always
Expand Down
16 changes: 2 additions & 14 deletions azure/services/bastionhosts/bastionhosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package bastionhosts

import (
"context"

asonetworkv1 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
Expand All @@ -41,7 +39,7 @@ type Service struct {
}

// New creates a new service.
func New(scope BastionScope) (*Service, error) {
func New(scope BastionScope) *Service {
svc := aso.NewService[*asonetworkv1.BastionHost, BastionScope](serviceName, scope)
spec := scope.AzureBastionSpec()
if spec != nil {
Expand All @@ -51,15 +49,5 @@ func New(scope BastionScope) (*Service, error) {
return &Service{
Scope: scope,
Service: svc,
}, nil
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// IsManaged returns always returns true as CAPZ does not support BYO bastion.
func (s *Service) IsManaged(ctx context.Context) (bool, error) {
return true, nil
}
}
12 changes: 5 additions & 7 deletions azure/services/bastionhosts/bastionhosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
SubnetID: fakeSubnetID,
PublicIPID: fakePublicIPID,
}
conditionType = clusterv1.ConditionType(infrav1.BastionHostReadyCondition)
conditionType = infrav1.BastionHostReadyCondition
internalError = autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusInternalServerError}, "Internal Server Error")
)

Expand Down Expand Up @@ -112,11 +112,10 @@ func TestReconcileBastionHosts(t *testing.T) {

tc.expect(scopeMock.EXPECT(), reconcilerMock.EXPECT())

s, err := New(scopeMock)
g.Expect(err).NotTo(HaveOccurred())
s := New(scopeMock)
s.Reconciler = reconcilerMock

err = s.Reconcile(context.TODO())
err := s.Reconcile(context.TODO())
if tc.expectedError != "" {
g.Expect(err).To(HaveOccurred())
g.Expect(err).To(MatchError(tc.expectedError))
Expand Down Expand Up @@ -184,11 +183,10 @@ func TestDeleteBastionHost(t *testing.T) {

tc.expect(scopeMock.EXPECT(), reconcilerMock.EXPECT())

s, err := New(scopeMock)
g.Expect(err).NotTo(HaveOccurred())
s := New(scopeMock)
s.Reconciler = reconcilerMock

err = s.Delete(context.TODO())
err := s.Delete(context.TODO())
if tc.expectedError != "" {
g.Expect(err).To(HaveOccurred())
g.Expect(err).To(MatchError(tc.expectedError))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 34 additions & 40 deletions azure/services/bastionhosts/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ type AzureBastionSpec struct {
EnableTunneling bool
}

// AzureBastionSpecInput defines the required inputs to construct an azure bastion spec.
type AzureBastionSpecInput struct {
SubnetName string
PublicIPName string
VNetName string
}

// ResourceRef implements azure.ASOResourceSpecGetter.
func (s *AzureBastionSpec) ResourceRef() *asonetworkv1.BastionHost {
return &asonetworkv1.BastionHost{
Expand All @@ -58,48 +51,49 @@ func (s *AzureBastionSpec) ResourceRef() *asonetworkv1.BastionHost {
}
}

// Parameters returns the parameters for the bastion host.
// Parameters implements azure.ASOResourceSpecGetter.
func (s *AzureBastionSpec) Parameters(ctx context.Context, existingBastionHost *asonetworkv1.BastionHost) (parameters *asonetworkv1.BastionHost, err error) {
bastionHost := &asonetworkv1.BastionHost{}
bastionHost.Spec = asonetworkv1.BastionHost_Spec{}
if existingBastionHost != nil {
// bastion host already exists
return existingBastionHost, nil
bastionHost = existingBastionHost
}

bastionHostIPConfigName := fmt.Sprintf("%s-%s", s.Name, "bastionIP")

return &asonetworkv1.BastionHost{
Spec: asonetworkv1.BastionHost_Spec{
AzureName: s.Name,
Location: ptr.To(s.Location),
Tags: infrav1.Build(infrav1.BuildParams{
ClusterName: s.ClusterName,
Lifecycle: infrav1.ResourceLifecycleOwned,
Name: ptr.To(s.Name),
Role: ptr.To("Bastion"),
}),
Sku: &asonetworkv1.Sku{
Name: ptr.To(asonetworkv1.Sku_Name(s.Sku)),
bastionHost.Spec.AzureName = s.Name
bastionHost.Spec.Location = ptr.To(s.Location)
bastionHost.Spec.Owner = &genruntime.KnownResourceReference{
Name: s.ClusterName,
}
bastionHost.Spec.Tags = infrav1.Build(infrav1.BuildParams{
ClusterName: s.ClusterName,
Lifecycle: infrav1.ResourceLifecycleOwned,
Name: ptr.To(s.Name),
Role: ptr.To("Bastion"),
})
bastionHost.Spec.Sku = &asonetworkv1.Sku{
Name: ptr.To(asonetworkv1.Sku_Name(s.Sku)),
}
bastionHost.Spec.EnableTunneling = ptr.To(s.EnableTunneling)
bastionHost.Spec.DnsName = ptr.To(fmt.Sprintf("%s-bastion", strings.ToLower(s.Name)))
bastionHost.Spec.IpConfigurations = []asonetworkv1.BastionHostIPConfiguration{
{
Name: ptr.To(bastionHostIPConfigName),
Subnet: &asonetworkv1.BastionHostSubResource{
Reference: &genruntime.ResourceReference{
ARMID: s.SubnetID,
},
},
EnableTunneling: ptr.To(s.EnableTunneling),
DnsName: ptr.To(fmt.Sprintf("%s-bastion", strings.ToLower(s.Name))),
IpConfigurations: []asonetworkv1.BastionHostIPConfiguration{
{
Name: ptr.To(bastionHostIPConfigName),
Subnet: &asonetworkv1.BastionHostSubResource{
Reference: &genruntime.ResourceReference{
ARMID: s.SubnetID,
},
},
PublicIPAddress: &asonetworkv1.BastionHostSubResource{
Reference: &genruntime.ResourceReference{
ARMID: s.PublicIPID,
},
},
PrivateIPAllocationMethod: ptr.To(asonetworkv1.IPAllocationMethod_Dynamic),
PublicIPAddress: &asonetworkv1.BastionHostSubResource{
Reference: &genruntime.ResourceReference{
ARMID: s.PublicIPID,
},
},
PrivateIPAllocationMethod: ptr.To(asonetworkv1.IPAllocationMethod_Dynamic),
},
}, nil
}

return bastionHost, nil
}

// WasManaged implements azure.ASOResourceSpecGetter.
Expand Down
Loading

0 comments on commit d7f3b9f

Please sign in to comment.