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 9940109
Show file tree
Hide file tree
Showing 9 changed files with 573 additions and 37 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.

15 changes: 6 additions & 9 deletions azure/services/bastionhosts/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
type AzureBastionSpec struct {
Name string
Namespace string
AzureName string
ResourceGroup string
Location string
ClusterName string
Expand All @@ -41,13 +42,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,7 +52,7 @@ 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) {
if existingBastionHost != nil {
// bastion host already exists
Expand All @@ -69,8 +63,11 @@ func (s *AzureBastionSpec) Parameters(ctx context.Context, existingBastionHost *

return &asonetworkv1.BastionHost{
Spec: asonetworkv1.BastionHost_Spec{
AzureName: s.Name,
AzureName: s.AzureName,
Location: ptr.To(s.Location),
Owner: &genruntime.KnownResourceReference{
Name: s.ClusterName,
},
Tags: infrav1.Build(infrav1.BuildParams{
ClusterName: s.ClusterName,
Lifecycle: infrav1.ResourceLifecycleOwned,
Expand Down
Loading

0 comments on commit 9940109

Please sign in to comment.