From 03a15429547d0deea3bcd203d6d08b9e40539a79 Mon Sep 17 00:00:00 2001 From: shysank Date: Tue, 25 Jan 2022 19:23:11 -0800 Subject: [PATCH] update scope, generate mocks, add privatedns to conditions summary --- azure/scope/cluster.go | 54 ++++++++---- .../privatedns/mock_privatedns/doc.go | 2 - .../mock_privatedns/privatedns_mock.go | 83 ++++++++++++++++++- 3 files changed, 116 insertions(+), 23 deletions(-) diff --git a/azure/scope/cluster.go b/azure/scope/cluster.go index f514e0d88d6..9a5b4aec31b 100644 --- a/azure/scope/cluster.go +++ b/azure/scope/cluster.go @@ -24,6 +24,8 @@ import ( "strconv" "strings" + "sigs.k8s.io/cluster-api-provider-azure/azure/services/privatedns" + "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" @@ -371,35 +373,49 @@ func (s *ClusterScope) VNetSpec() azure.VNetSpec { } // PrivateDNSSpec returns the private dns zone spec. -func (s *ClusterScope) PrivateDNSSpec() *azure.PrivateDNSSpec { - var specs *azure.PrivateDNSSpec +func (s *ClusterScope) PrivateDNSSpec() (zoneSpec azure.ResourceSpecGetter, linkSpec, recordSpec []azure.ResourceSpecGetter) { if s.IsAPIServerPrivate() { - links := make([]azure.PrivateDNSLinkSpec, 1+len(s.Vnet().Peerings)) - links[0] = azure.PrivateDNSLinkSpec{ - VNetName: s.Vnet().Name, + zone := privatedns.ZoneSpec{ + Name: s.GetPrivateDNSZoneName(), + ResourceGroup: s.ResourceGroup(), + ClusterName: s.ClusterName(), + AdditionalTags: nil, + } + + links := make([]azure.ResourceSpecGetter, 1+len(s.Vnet().Peerings)) + links[0] = privatedns.LinkSpec{ + Name: azure.GenerateVNetLinkName(s.Vnet().Name), + ZoneName: s.GetPrivateDNSZoneName(), VNetResourceGroup: s.Vnet().ResourceGroup, - LinkName: azure.GenerateVNetLinkName(s.Vnet().Name), + VNetName: s.Vnet().Name, + ResourceGroup: s.ResourceGroup(), + ClusterName: s.ClusterName(), } for i, peering := range s.Vnet().Peerings { - links[i+1] = azure.PrivateDNSLinkSpec{ - VNetName: peering.RemoteVnetName, + links[i+1] = privatedns.LinkSpec{ + Name: azure.GenerateVNetLinkName(peering.RemoteVnetName), + ZoneName: s.GetPrivateDNSZoneName(), VNetResourceGroup: peering.ResourceGroup, - LinkName: azure.GenerateVNetLinkName(peering.RemoteVnetName), + VNetName: peering.RemoteVnetName, + ResourceGroup: s.ResourceGroup(), + ClusterName: s.ClusterName(), } } - specs = &azure.PrivateDNSSpec{ - ZoneName: s.GetPrivateDNSZoneName(), - Links: links, - Records: []infrav1.AddressRecord{ - { - Hostname: azure.PrivateAPIServerHostname, - IP: s.APIServerPrivateIP(), - }, + + records := make([]azure.ResourceSpecGetter, 1) + records[0] = privatedns.RecordSpec{ + Record: infrav1.AddressRecord{ + Hostname: azure.PrivateAPIServerHostname, + IP: s.APIServerPrivateIP(), }, + ZoneName: s.GetPrivateDNSZoneName(), + ResourceGroup: s.ResourceGroup(), } + + return zone, links, records } - return specs + return nil, nil, nil } // IsAzureBastionEnabled returns true if the azure bastion is enabled. @@ -662,6 +678,7 @@ func (s *ClusterScope) PatchObject(ctx context.Context) error { infrav1.NATGatewaysReadyCondition, infrav1.LoadBalancersReadyCondition, infrav1.BastionHostReadyCondition, + infrav1.PrivateDNSReadyCondition, ), ) @@ -678,6 +695,7 @@ func (s *ClusterScope) PatchObject(ctx context.Context) error { infrav1.NATGatewaysReadyCondition, infrav1.LoadBalancersReadyCondition, infrav1.BastionHostReadyCondition, + infrav1.PrivateDNSReadyCondition, }}) } diff --git a/azure/services/privatedns/mock_privatedns/doc.go b/azure/services/privatedns/mock_privatedns/doc.go index d62815a20b1..2f8c258f531 100644 --- a/azure/services/privatedns/mock_privatedns/doc.go +++ b/azure/services/privatedns/mock_privatedns/doc.go @@ -15,8 +15,6 @@ limitations under the License. */ // Run go generate to regenerate this mock. -//go:generate ../../../../hack/tools/bin/mockgen -destination client_mock.go -package mock_privatedns -source ../client.go Client //go:generate ../../../../hack/tools/bin/mockgen -destination privatedns_mock.go -package mock_privatedns -source ../privatedns.go Scope -//go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt client_mock.go > _client_mock.go && mv _client_mock.go client_mock.go" //go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt privatedns_mock.go > _privatedns_mock.go && mv _privatedns_mock.go privatedns_mock.go" package mock_privatedns //nolint diff --git a/azure/services/privatedns/mock_privatedns/privatedns_mock.go b/azure/services/privatedns/mock_privatedns/privatedns_mock.go index b071e4e5e1f..e6e48822ad5 100644 --- a/azure/services/privatedns/mock_privatedns/privatedns_mock.go +++ b/azure/services/privatedns/mock_privatedns/privatedns_mock.go @@ -27,6 +27,7 @@ import ( gomock "github.com/golang/mock/gomock" v1beta1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" azure "sigs.k8s.io/cluster-api-provider-azure/azure" + v1beta10 "sigs.k8s.io/cluster-api/api/v1beta1" ) // MockScope is a mock of Scope interface. @@ -178,6 +179,18 @@ func (mr *MockScopeMockRecorder) ClusterName() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClusterName", reflect.TypeOf((*MockScope)(nil).ClusterName)) } +// DeleteLongRunningOperationState mocks base method. +func (m *MockScope) DeleteLongRunningOperationState(arg0, arg1 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "DeleteLongRunningOperationState", arg0, arg1) +} + +// DeleteLongRunningOperationState indicates an expected call of DeleteLongRunningOperationState. +func (mr *MockScopeMockRecorder) DeleteLongRunningOperationState(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLongRunningOperationState", reflect.TypeOf((*MockScope)(nil).DeleteLongRunningOperationState), arg0, arg1) +} + // FailureDomains mocks base method. func (m *MockScope) FailureDomains() []string { m.ctrl.T.Helper() @@ -192,6 +205,20 @@ func (mr *MockScopeMockRecorder) FailureDomains() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FailureDomains", reflect.TypeOf((*MockScope)(nil).FailureDomains)) } +// GetLongRunningOperationState mocks base method. +func (m *MockScope) GetLongRunningOperationState(arg0, arg1 string) *v1beta1.Future { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetLongRunningOperationState", arg0, arg1) + ret0, _ := ret[0].(*v1beta1.Future) + return ret0 +} + +// GetLongRunningOperationState indicates an expected call of GetLongRunningOperationState. +func (mr *MockScopeMockRecorder) GetLongRunningOperationState(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLongRunningOperationState", reflect.TypeOf((*MockScope)(nil).GetLongRunningOperationState), arg0, arg1) +} + // HashKey mocks base method. func (m *MockScope) HashKey() string { m.ctrl.T.Helper() @@ -221,11 +248,13 @@ func (mr *MockScopeMockRecorder) Location() *gomock.Call { } // PrivateDNSSpec mocks base method. -func (m *MockScope) PrivateDNSSpec() *azure.PrivateDNSSpec { +func (m *MockScope) PrivateDNSSpec() (azure.ResourceSpecGetter, []azure.ResourceSpecGetter, []azure.ResourceSpecGetter) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PrivateDNSSpec") - ret0, _ := ret[0].(*azure.PrivateDNSSpec) - return ret0 + ret0, _ := ret[0].(azure.ResourceSpecGetter) + ret1, _ := ret[1].([]azure.ResourceSpecGetter) + ret2, _ := ret[2].([]azure.ResourceSpecGetter) + return ret0, ret1, ret2 } // PrivateDNSSpec indicates an expected call of PrivateDNSSpec. @@ -248,6 +277,18 @@ func (mr *MockScopeMockRecorder) ResourceGroup() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceGroup", reflect.TypeOf((*MockScope)(nil).ResourceGroup)) } +// SetLongRunningOperationState mocks base method. +func (m *MockScope) SetLongRunningOperationState(arg0 *v1beta1.Future) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetLongRunningOperationState", arg0) +} + +// SetLongRunningOperationState indicates an expected call of SetLongRunningOperationState. +func (mr *MockScopeMockRecorder) SetLongRunningOperationState(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLongRunningOperationState", reflect.TypeOf((*MockScope)(nil).SetLongRunningOperationState), arg0) +} + // SubscriptionID mocks base method. func (m *MockScope) SubscriptionID() string { m.ctrl.T.Helper() @@ -275,3 +316,39 @@ func (mr *MockScopeMockRecorder) TenantID() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TenantID", reflect.TypeOf((*MockScope)(nil).TenantID)) } + +// UpdateDeleteStatus mocks base method. +func (m *MockScope) UpdateDeleteStatus(arg0 v1beta10.ConditionType, arg1 string, arg2 error) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "UpdateDeleteStatus", arg0, arg1, arg2) +} + +// UpdateDeleteStatus indicates an expected call of UpdateDeleteStatus. +func (mr *MockScopeMockRecorder) UpdateDeleteStatus(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDeleteStatus", reflect.TypeOf((*MockScope)(nil).UpdateDeleteStatus), arg0, arg1, arg2) +} + +// UpdatePatchStatus mocks base method. +func (m *MockScope) UpdatePatchStatus(arg0 v1beta10.ConditionType, arg1 string, arg2 error) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "UpdatePatchStatus", arg0, arg1, arg2) +} + +// UpdatePatchStatus indicates an expected call of UpdatePatchStatus. +func (mr *MockScopeMockRecorder) UpdatePatchStatus(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdatePatchStatus", reflect.TypeOf((*MockScope)(nil).UpdatePatchStatus), arg0, arg1, arg2) +} + +// UpdatePutStatus mocks base method. +func (m *MockScope) UpdatePutStatus(arg0 v1beta10.ConditionType, arg1 string, arg2 error) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "UpdatePutStatus", arg0, arg1, arg2) +} + +// UpdatePutStatus indicates an expected call of UpdatePutStatus. +func (mr *MockScopeMockRecorder) UpdatePutStatus(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdatePutStatus", reflect.TypeOf((*MockScope)(nil).UpdatePutStatus), arg0, arg1, arg2) +}