Skip to content

Commit 8daee8c

Browse files
Ignore default tags during reconciliation (#131)
1 parent abbd0a3 commit 8daee8c

23 files changed

+51
-512
lines changed

cloud/scope/cluster.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@ package scope
1919
import (
2020
"context"
2121
"fmt"
22-
"reflect"
23-
"sigs.k8s.io/cluster-api/util/conditions"
2422
"strconv"
2523

26-
"github.com/oracle/cluster-api-provider-oci/cloud/services/vcn"
27-
2824
"github.com/go-logr/logr"
2925
infrastructurev1beta1 "github.com/oracle/cluster-api-provider-oci/api/v1beta1"
3026
"github.com/oracle/cluster-api-provider-oci/cloud/ociutil"
3127
identityClent "github.com/oracle/cluster-api-provider-oci/cloud/services/identity"
3228
nlb "github.com/oracle/cluster-api-provider-oci/cloud/services/networkloadbalancer"
29+
"github.com/oracle/cluster-api-provider-oci/cloud/services/vcn"
3330
"github.com/oracle/oci-go-sdk/v63/common"
3431
"github.com/oracle/oci-go-sdk/v63/identity"
3532
"github.com/pkg/errors"
3633
"k8s.io/klog/v2/klogr"
3734
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
35+
"sigs.k8s.io/cluster-api/util/conditions"
3836
"sigs.k8s.io/cluster-api/util/patch"
3937
"sigs.k8s.io/controller-runtime/pkg/client"
4038
)
@@ -223,13 +221,6 @@ func (s *ClusterScope) setAvailabiltyDomainStatus(ctx context.Context, ads []ide
223221
return nil
224222
}
225223

226-
func (s *ClusterScope) IsTagsEqual(freeFromTags map[string]string, definedTags map[string]map[string]interface{}) bool {
227-
if reflect.DeepEqual(freeFromTags, s.GetFreeFormTags()) && reflect.DeepEqual(definedTags, s.GetDefinedTags()) {
228-
return true
229-
}
230-
return false
231-
}
232-
233224
// GetRegionCodeFromRegion pulls all OCI regions available and returns the passed in region's code if contained in
234225
// the list.
235226
//
@@ -280,14 +271,15 @@ func (s *ClusterScope) APIServerPort() int32 {
280271
// GetFreeFormTags returns a map of FreeformTags defined in the OCICluster's spec
281272
func (s *ClusterScope) GetFreeFormTags() map[string]string {
282273
tags := s.OCICluster.Spec.FreeformTags
283-
if tags == nil {
284-
tags = make(map[string]string)
274+
completeTags := make(map[string]string)
275+
for k, v := range tags {
276+
completeTags[k] = v
285277
}
286-
tagsAddedByClusterAPI := ociutil.BuildClusterTags(string(s.OCICluster.GetOCIResourceIdentifier()))
278+
tagsAddedByClusterAPI := ociutil.BuildClusterTags(s.OCICluster.GetOCIResourceIdentifier())
287279
for k, v := range tagsAddedByClusterAPI {
288-
tags[k] = v
280+
completeTags[k] = v
289281
}
290-
return tags
282+
return completeTags
291283
}
292284

293285
func (s *ClusterScope) GetOCICluster() *infrastructurev1beta1.OCICluster {

cloud/scope/drg_reconciler.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ func (s *ClusterScope) ReconcileDRG(ctx context.Context) error {
4646
}
4747
if drg != nil {
4848
s.getDRG().ID = drg.Id
49-
if !s.IsTagsEqual(drg.FreeformTags, drg.DefinedTags) {
50-
_, err := s.updateDRG(ctx)
51-
if err != nil {
52-
return err
53-
}
54-
}
5549
s.Logger.Info("No Reconciliation Required for DRG", "drg", drg.Id)
5650
return nil
5751
}
@@ -131,20 +125,6 @@ func (s *ClusterScope) createDRG(ctx context.Context) (*core.Drg, error) {
131125
return &response.Drg, nil
132126
}
133127

134-
func (s *ClusterScope) updateDRG(ctx context.Context) (*core.Drg, error) {
135-
response, err := s.VCNClient.UpdateDrg(ctx, core.UpdateDrgRequest{
136-
DrgId: s.getDRG().ID,
137-
UpdateDrgDetails: core.UpdateDrgDetails{
138-
FreeformTags: s.GetFreeFormTags(),
139-
DefinedTags: s.GetDefinedTags(),
140-
},
141-
})
142-
if err != nil {
143-
return nil, err
144-
}
145-
return &response.Drg, nil
146-
}
147-
148128
func (s *ClusterScope) GetDRGName() string {
149129
if s.getDRG().Name != "" {
150130
return s.getDRG().Name

cloud/scope/drg_reconciler_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ func TestDRGReconciliation(t *testing.T) {
160160
}, nil)
161161
},
162162
},
163-
{
164-
name: "drg update",
165-
errorExpected: false,
166-
testSpecificSetup: func(clusterScope *ClusterScope, vcnClient *mock_vcn.MockClient) {
167-
vcnPeering.DRG = &infrastructurev1beta1.DRG{}
168-
vcnPeering.DRG.Manage = true
169-
vcnPeering.DRG.ID = common.String("drg-id")
170-
existingTags := make(map[string]string)
171-
existingTags[ociutil.CreatedBy] = ociutil.OCIClusterAPIProvider
172-
existingTags[ociutil.ClusterResourceIdentifier] = "resource_uid"
173-
existingTags["test"] = "test"
174-
clusterScope.OCICluster.Spec.NetworkSpec.VCNPeering = &vcnPeering
175-
vcnClient.EXPECT().GetDrg(gomock.Any(), gomock.Eq(core.GetDrgRequest{
176-
DrgId: common.String("drg-id"),
177-
})).
178-
Return(core.GetDrgResponse{
179-
Drg: core.Drg{
180-
Id: common.String("drg-id"),
181-
FreeformTags: existingTags,
182-
DefinedTags: make(map[string]map[string]interface{}),
183-
},
184-
}, nil)
185-
vcnClient.EXPECT().UpdateDrg(gomock.Any(), gomock.Eq(core.UpdateDrgRequest{
186-
DrgId: common.String("drg-id"),
187-
UpdateDrgDetails: core.UpdateDrgDetails{
188-
FreeformTags: tags,
189-
DefinedTags: make(map[string]map[string]interface{}),
190-
},
191-
})).
192-
Return(core.UpdateDrgResponse{}, nil)
193-
},
194-
},
195163
{
196164
name: "drg create",
197165
errorExpected: false,

cloud/scope/drg_rpc_attachment_reconciler.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ func (s *ClusterScope) ReconcileDRGRPCAttachment(ctx context.Context) error {
5555
if localRpc != nil {
5656
rpcSpec.RPCConnectionId = localRpc.Id
5757
s.Logger.Info("Local RPC exists", "rpcId", localRpc.Id)
58-
if !s.IsTagsEqual(localRpc.FreeformTags, localRpc.DefinedTags) {
59-
_, err := s.updateDRGRpc(ctx, localRpc.Id, s.VCNClient)
60-
if err != nil {
61-
return err
62-
}
63-
s.Logger.Info("Local RPC has been updated", "rpcId", localRpc.Id)
64-
}
6558
} else {
6659
localRpc, err = s.createRPC(ctx, s.getDrgID(), s.OCICluster.Name, s.VCNClient)
6760
if err != nil {
@@ -91,13 +84,6 @@ func (s *ClusterScope) ReconcileDRGRPCAttachment(ctx context.Context) error {
9184
s.Logger.Info("Remote RPC exists", "rpcId", localRpc.Id)
9285
s.Logger.Info("Connection status of 2 peered RPCs", "status", localRpc.PeeringStatus)
9386
rpcSpec.PeerRPCConnectionId = remoteRpc.Id
94-
if !s.IsTagsEqual(remoteRpc.FreeformTags, remoteRpc.DefinedTags) {
95-
_, err := s.updateDRGRpc(ctx, remoteRpc.Id, clientProvider.VCNClient)
96-
if err != nil {
97-
return err
98-
}
99-
s.Logger.Info("Remote RPC has been updated", "rpcId", remoteRpc.Id)
100-
}
10187
} else {
10288
remoteRpc, err = s.createRPC(ctx, rpcSpec.PeerDRGId, s.OCICluster.Name, clientProvider.VCNClient)
10389
if err != nil {

cloud/scope/drg_vcn_attachment_reconciler.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ func (s *ClusterScope) ReconcileDRGVCNAttachment(ctx context.Context) error {
4343
if err != nil {
4444
return err
4545
}
46-
if !s.IsTagsEqual(attachment.FreeformTags, attachment.DefinedTags) {
47-
_, err := s.UpdateDRGAttachment(ctx)
48-
if err != nil {
49-
return err
50-
}
51-
}
5246
return nil
5347
}
5448

cloud/scope/drg_vcn_attachment_reconciler_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -130,39 +130,6 @@ func TestDRGVCNAttachmentReconciliation(t *testing.T) {
130130
}, nil)
131131
},
132132
},
133-
{
134-
name: "drg attachment update",
135-
errorExpected: false,
136-
testSpecificSetup: func(clusterScope *ClusterScope, vcnClient *mock_vcn.MockClient) {
137-
vcnPeering.DRG = &infrastructurev1beta1.DRG{}
138-
vcnPeering.DRG.Manage = true
139-
vcnPeering.DRG.ID = common.String("drg-id")
140-
vcnPeering.DRG.VcnAttachmentId = common.String("attachment-id")
141-
clusterScope.OCICluster.Spec.NetworkSpec.VCNPeering = &vcnPeering
142-
existingTags := make(map[string]string)
143-
existingTags[ociutil.CreatedBy] = ociutil.OCIClusterAPIProvider
144-
existingTags[ociutil.ClusterResourceIdentifier] = "resource_uid"
145-
existingTags["test"] = "test"
146-
vcnClient.EXPECT().GetDrgAttachment(gomock.Any(), gomock.Eq(core.GetDrgAttachmentRequest{
147-
DrgAttachmentId: common.String("attachment-id"),
148-
})).
149-
Return(core.GetDrgAttachmentResponse{
150-
DrgAttachment: core.DrgAttachment{
151-
Id: common.String("attachment-id"),
152-
FreeformTags: existingTags,
153-
DefinedTags: make(map[string]map[string]interface{}),
154-
},
155-
}, nil)
156-
vcnClient.EXPECT().UpdateDrgAttachment(gomock.Any(), gomock.Eq(core.UpdateDrgAttachmentRequest{
157-
DrgAttachmentId: common.String("attachment-id"),
158-
UpdateDrgAttachmentDetails: core.UpdateDrgAttachmentDetails{
159-
FreeformTags: tags,
160-
DefinedTags: make(map[string]map[string]interface{}),
161-
},
162-
})).
163-
Return(core.UpdateDrgAttachmentResponse{}, nil)
164-
},
165-
},
166133
{
167134
name: "drg attachment create",
168135
errorExpected: false,

cloud/scope/internet_gateway_reconciler.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ func (s *ClusterScope) ReconcileInternetGateway(ctx context.Context) error {
3838
}
3939
if igw != nil {
4040
s.OCICluster.Spec.NetworkSpec.Vcn.InternetGatewayId = igw.Id
41-
if !s.IsTagsEqual(igw.FreeformTags, igw.DefinedTags) {
42-
return s.UpdateInternetGateway(ctx)
43-
}
4441
s.Logger.Info("No Reconciliation Required for Internet Gateway", "internet_gateway", igw.Id)
4542
return nil
4643
}
@@ -90,24 +87,6 @@ func (s *ClusterScope) GetInternetGateway(ctx context.Context) (*core.InternetGa
9087
return nil, nil
9188
}
9289

93-
// UpdateInternetGateway updates the FreeFormTags and DefinedTags
94-
func (s *ClusterScope) UpdateInternetGateway(ctx context.Context) error {
95-
updateIGWDetails := core.UpdateInternetGatewayDetails{
96-
FreeformTags: s.GetFreeFormTags(),
97-
DefinedTags: s.GetDefinedTags(),
98-
}
99-
igwResponse, err := s.VCNClient.UpdateInternetGateway(ctx, core.UpdateInternetGatewayRequest{
100-
IgId: s.OCICluster.Spec.NetworkSpec.Vcn.InternetGatewayId,
101-
UpdateInternetGatewayDetails: updateIGWDetails,
102-
})
103-
if err != nil {
104-
s.Logger.Error(err, "failed to reconcile the internet gateway, failed to update")
105-
return errors.Wrap(err, "failed to reconcile the internet gateway, failed to update")
106-
}
107-
s.Logger.Info("successfully updated the internet gateway", "internet_gateway", *igwResponse.Id)
108-
return nil
109-
}
110-
11190
// CreateInternetGateway creates the Internet Gateway for the cluster based on the ClusterScope
11291
func (s *ClusterScope) CreateInternetGateway(ctx context.Context) (*string, error) {
11392
igwDetails := core.CreateInternetGatewayDetails{

cloud/scope/internet_gateway_reconciler_test.go

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,13 @@ func TestClusterScope_ReconcileInternetGateway(t *testing.T) {
7070
FreeformTags: tags,
7171
DefinedTags: definedTagsInterface,
7272
},
73-
}, nil).Times(2)
73+
}, nil)
7474

7575
updatedTags := make(map[string]string)
7676
for k, v := range tags {
7777
updatedTags[k] = v
7878
}
7979
updatedTags["foo"] = "bar"
80-
vcnClient.EXPECT().UpdateInternetGateway(gomock.Any(), gomock.Eq(core.UpdateInternetGatewayRequest{
81-
IgId: common.String("foo"),
82-
UpdateInternetGatewayDetails: core.UpdateInternetGatewayDetails{
83-
FreeformTags: updatedTags,
84-
DefinedTags: definedTagsInterface,
85-
},
86-
})).
87-
Return(core.UpdateInternetGatewayResponse{
88-
InternetGateway: core.InternetGateway{
89-
Id: common.String("foo"),
90-
FreeformTags: tags,
91-
},
92-
}, nil)
93-
vcnClient.EXPECT().UpdateInternetGateway(gomock.Any(), gomock.Eq(core.UpdateInternetGatewayRequest{
94-
IgId: common.String("igw_id"),
95-
UpdateInternetGatewayDetails: core.UpdateInternetGatewayDetails{
96-
FreeformTags: updatedTags,
97-
DefinedTags: definedTagsInterface,
98-
},
99-
})).
100-
Return(core.UpdateInternetGatewayResponse{}, errors.New("some error"))
10180
vcnClient.EXPECT().ListInternetGateways(gomock.Any(), gomock.Eq(core.ListInternetGatewaysRequest{
10281
CompartmentId: common.String("foo"),
10382
DisplayName: common.String("internet-gateway"),
@@ -190,22 +169,7 @@ func TestClusterScope_ReconcileInternetGateway(t *testing.T) {
190169
wantErr: false,
191170
},
192171
{
193-
name: "update needed",
194-
spec: infrastructurev1beta1.OCIClusterSpec{
195-
FreeformTags: map[string]string{
196-
"foo": "bar",
197-
},
198-
DefinedTags: definedTags,
199-
NetworkSpec: infrastructurev1beta1.NetworkSpec{
200-
Vcn: infrastructurev1beta1.VCN{
201-
InternetGatewayId: common.String("foo"),
202-
},
203-
},
204-
},
205-
wantErr: false,
206-
},
207-
{
208-
name: "id not present in spec but found by name and update needed but error out",
172+
name: "id not present in spec but found by name and no update needed",
209173
spec: infrastructurev1beta1.OCIClusterSpec{
210174
CompartmentId: "foo",
211175
FreeformTags: map[string]string{
@@ -218,8 +182,7 @@ func TestClusterScope_ReconcileInternetGateway(t *testing.T) {
218182
},
219183
},
220184
},
221-
wantErr: true,
222-
expectedError: "failed to reconcile the internet gateway, failed to update: some error",
185+
wantErr: false,
223186
},
224187
{
225188
name: "creation needed",

cloud/scope/load_balancer_reconciler.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ func (s *ClusterScope) GetControlPlaneLoadBalancerName() string {
112112
func (s *ClusterScope) UpdateLB(ctx context.Context, lb infrastructurev1beta1.LoadBalancer) error {
113113
lbId := s.OCICluster.Spec.NetworkSpec.APIServerLB.LoadBalancerId
114114
updateLBDetails := networkloadbalancer.UpdateNetworkLoadBalancerDetails{
115-
DisplayName: common.String(lb.Name),
116-
FreeformTags: s.GetFreeFormTags(),
117-
DefinedTags: s.GetDefinedTags(),
115+
DisplayName: common.String(lb.Name),
118116
}
119117
lbResponse, err := s.LoadBalancerClient.UpdateNetworkLoadBalancer(ctx, networkloadbalancer.UpdateNetworkLoadBalancerRequest{
120118
UpdateNetworkLoadBalancerDetails: updateLBDetails,
@@ -244,12 +242,12 @@ func (s *ClusterScope) getLoadbalancerIp(nlb networkloadbalancer.NetworkLoadBala
244242
}
245243

246244
// IsLBEqual determines if the actual networkloadbalancer.NetworkLoadBalancer is equal to the desired.
247-
// Equality is determined by DisplayName, FreeformTags and DefinedTags matching.
245+
// Equality is determined by DisplayName
248246
func (s *ClusterScope) IsLBEqual(actual *networkloadbalancer.NetworkLoadBalancer, desired infrastructurev1beta1.LoadBalancer) bool {
249247
if desired.Name != *actual.DisplayName {
250248
return false
251249
}
252-
return s.IsTagsEqual(actual.FreeformTags, actual.DefinedTags)
250+
return true
253251
}
254252

255253
// GetLoadBalancer retrieves the Cluster's networkloadbalancer.NetworkLoadBalancer using the one of the following methods

0 commit comments

Comments
 (0)