diff --git a/azure/scope/cluster.go b/azure/scope/cluster.go index f514e0d88d62..3073d5da0eee 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,53 @@ 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: s.AdditionalTags(), + } + + links := make([]azure.ResourceSpecGetter, 1+len(s.Vnet().Peerings)) + links[0] = privatedns.LinkSpec{ + Name: azure.GenerateVNetLinkName(s.Vnet().Name), + ZoneName: s.GetPrivateDNSZoneName(), + SubscriptionID: s.SubscriptionID(), VNetResourceGroup: s.Vnet().ResourceGroup, - LinkName: azure.GenerateVNetLinkName(s.Vnet().Name), + VNetName: s.Vnet().Name, + ResourceGroup: s.ResourceGroup(), + ClusterName: s.ClusterName(), + AdditionalTags: s.AdditionalTags(), } 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(), + SubscriptionID: s.SubscriptionID(), VNetResourceGroup: peering.ResourceGroup, - LinkName: azure.GenerateVNetLinkName(peering.RemoteVnetName), + VNetName: peering.RemoteVnetName, + ResourceGroup: s.ResourceGroup(), + ClusterName: s.ClusterName(), + AdditionalTags: s.AdditionalTags(), } } - 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 +682,7 @@ func (s *ClusterScope) PatchObject(ctx context.Context) error { infrav1.NATGatewaysReadyCondition, infrav1.LoadBalancersReadyCondition, infrav1.BastionHostReadyCondition, + infrav1.PrivateDNSReadyCondition, ), ) @@ -678,6 +699,7 @@ func (s *ClusterScope) PatchObject(ctx context.Context) error { infrav1.NATGatewaysReadyCondition, infrav1.LoadBalancersReadyCondition, infrav1.BastionHostReadyCondition, + infrav1.PrivateDNSReadyCondition, }}) } diff --git a/azure/services/privatedns/client.go b/azure/services/privatedns/client.go index b3068b16dd93..89a068c13c7d 100644 --- a/azure/services/privatedns/client.go +++ b/azure/services/privatedns/client.go @@ -18,6 +18,7 @@ package privatedns import ( "context" + "sigs.k8s.io/cluster-api-provider-azure/azure" ) diff --git a/azure/services/privatedns/mock_privatedns/client_mock.go b/azure/services/privatedns/mock_privatedns/client_mock.go index cf9d71ec70cd..017af1efe973 100644 --- a/azure/services/privatedns/mock_privatedns/client_mock.go +++ b/azure/services/privatedns/mock_privatedns/client_mock.go @@ -24,143 +24,44 @@ import ( context "context" reflect "reflect" - privatedns "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" gomock "github.com/golang/mock/gomock" + azure "sigs.k8s.io/cluster-api-provider-azure/azure" ) -// Mockclient is a mock of client interface. -type Mockclient struct { +// MockGetter is a mock of Getter interface. +type MockGetter struct { ctrl *gomock.Controller - recorder *MockclientMockRecorder + recorder *MockGetterMockRecorder } -// MockclientMockRecorder is the mock recorder for Mockclient. -type MockclientMockRecorder struct { - mock *Mockclient +// MockGetterMockRecorder is the mock recorder for MockGetter. +type MockGetterMockRecorder struct { + mock *MockGetter } -// NewMockclient creates a new mock instance. -func NewMockclient(ctrl *gomock.Controller) *Mockclient { - mock := &Mockclient{ctrl: ctrl} - mock.recorder = &MockclientMockRecorder{mock} +// NewMockGetter creates a new mock instance. +func NewMockGetter(ctrl *gomock.Controller) *MockGetter { + mock := &MockGetter{ctrl: ctrl} + mock.recorder = &MockGetterMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *Mockclient) EXPECT() *MockclientMockRecorder { +func (m *MockGetter) EXPECT() *MockGetterMockRecorder { return m.recorder } -// CreateOrUpdateLink mocks base method. -func (m *Mockclient) CreateOrUpdateLink(arg0 context.Context, arg1, arg2, arg3 string, arg4 privatedns.VirtualNetworkLink) error { +// Get mocks base method. +func (m *MockGetter) Get(ctx context.Context, spec azure.ResourceSpecGetter) (interface{}, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateOrUpdateLink", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].(error) - return ret0 -} - -// CreateOrUpdateLink indicates an expected call of CreateOrUpdateLink. -func (mr *MockclientMockRecorder) CreateOrUpdateLink(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdateLink", reflect.TypeOf((*Mockclient)(nil).CreateOrUpdateLink), arg0, arg1, arg2, arg3, arg4) -} - -// CreateOrUpdateRecordSet mocks base method. -func (m *Mockclient) CreateOrUpdateRecordSet(arg0 context.Context, arg1, arg2 string, arg3 privatedns.RecordType, arg4 string, arg5 privatedns.RecordSet) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateOrUpdateRecordSet", arg0, arg1, arg2, arg3, arg4, arg5) - ret0, _ := ret[0].(error) - return ret0 -} - -// CreateOrUpdateRecordSet indicates an expected call of CreateOrUpdateRecordSet. -func (mr *MockclientMockRecorder) CreateOrUpdateRecordSet(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdateRecordSet", reflect.TypeOf((*Mockclient)(nil).CreateOrUpdateRecordSet), arg0, arg1, arg2, arg3, arg4, arg5) -} - -// CreateOrUpdateZone mocks base method. -func (m *Mockclient) CreateOrUpdateZone(arg0 context.Context, arg1, arg2 string, arg3 privatedns.PrivateZone) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateOrUpdateZone", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(error) - return ret0 -} - -// CreateOrUpdateZone indicates an expected call of CreateOrUpdateZone. -func (mr *MockclientMockRecorder) CreateOrUpdateZone(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdateZone", reflect.TypeOf((*Mockclient)(nil).CreateOrUpdateZone), arg0, arg1, arg2, arg3) -} - -// DeleteLink mocks base method. -func (m *Mockclient) DeleteLink(arg0 context.Context, arg1, arg2, arg3 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteLink", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteLink indicates an expected call of DeleteLink. -func (mr *MockclientMockRecorder) DeleteLink(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLink", reflect.TypeOf((*Mockclient)(nil).DeleteLink), arg0, arg1, arg2, arg3) -} - -// DeleteRecordSet mocks base method. -func (m *Mockclient) DeleteRecordSet(arg0 context.Context, arg1, arg2 string, arg3 privatedns.RecordType, arg4 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteRecordSet", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteRecordSet indicates an expected call of DeleteRecordSet. -func (mr *MockclientMockRecorder) DeleteRecordSet(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteRecordSet", reflect.TypeOf((*Mockclient)(nil).DeleteRecordSet), arg0, arg1, arg2, arg3, arg4) -} - -// DeleteZone mocks base method. -func (m *Mockclient) DeleteZone(arg0 context.Context, arg1, arg2 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteZone", arg0, arg1, arg2) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteZone indicates an expected call of DeleteZone. -func (mr *MockclientMockRecorder) DeleteZone(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteZone", reflect.TypeOf((*Mockclient)(nil).DeleteZone), arg0, arg1, arg2) -} - -// GetLink mocks base method. -func (m *Mockclient) GetLink(arg0 context.Context, arg1, arg2, arg3 string) (privatedns.VirtualNetworkLink, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetLink", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(privatedns.VirtualNetworkLink) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetLink indicates an expected call of GetLink. -func (mr *MockclientMockRecorder) GetLink(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLink", reflect.TypeOf((*Mockclient)(nil).GetLink), arg0, arg1, arg2, arg3) -} - -// GetZone mocks base method. -func (m *Mockclient) GetZone(arg0 context.Context, arg1, arg2 string) (privatedns.PrivateZone, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetZone", arg0, arg1, arg2) - ret0, _ := ret[0].(privatedns.PrivateZone) + ret := m.ctrl.Call(m, "Get", ctx, spec) + ret0, _ := ret[0].(interface{}) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetZone indicates an expected call of GetZone. -func (mr *MockclientMockRecorder) GetZone(arg0, arg1, arg2 interface{}) *gomock.Call { +// Get indicates an expected call of Get. +func (mr *MockGetterMockRecorder) Get(ctx, spec interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetZone", reflect.TypeOf((*Mockclient)(nil).GetZone), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockGetter)(nil).Get), ctx, spec) } diff --git a/azure/services/privatedns/mock_privatedns/doc.go b/azure/services/privatedns/mock_privatedns/doc.go index d62815a20b18..8b50fdf83406 100644 --- a/azure/services/privatedns/mock_privatedns/doc.go +++ b/azure/services/privatedns/mock_privatedns/doc.go @@ -15,7 +15,7 @@ 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 client_mock.go -package mock_privatedns -source ../client.go Getter //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" diff --git a/azure/services/privatedns/mock_privatedns/privatedns_mock.go b/azure/services/privatedns/mock_privatedns/privatedns_mock.go index b071e4e5e1f2..e6e48822ad50 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) +}