Skip to content

Commit 981220e

Browse files
authored
Merge pull request #217 from michaelhtm/fix/ignoretagspassedonstart
2 parents 10474d5 + a196b41 commit 981220e

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

mocks/pkg/types/aws_resource_manager.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type Config struct {
9898
AllowUnsafeEndpointURL bool
9999
LogLevel string
100100
ResourceTags []string
101+
ResourceTagKeys []string
101102
WatchNamespace string
102103
WatchSelectors string
103104
EnableWebhookServer bool
@@ -307,6 +308,15 @@ func (cfg *Config) SetAWSAccountID(ctx context.Context) error {
307308

308309
// Validate ensures the options are valid
309310
func (cfg *Config) Validate(ctx context.Context, options ...Option) error {
311+
cfg.ResourceTagKeys = []string{}
312+
// parse resource tags
313+
for _, tag := range cfg.ResourceTags {
314+
split := strings.Split(tag, "=")
315+
if len(split) != 2 {
316+
return fmt.Errorf("invalid resource tag: %s", tag)
317+
}
318+
cfg.ResourceTagKeys = append(cfg.ResourceTagKeys, split[0])
319+
}
310320
merged := mergeOptions(options)
311321
if len(merged.gvks) > 0 {
312322
err := cfg.validateReconcileConfigResources(merged.gvks)

pkg/runtime/reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ func (r *resourceReconciler) Sync(
591591
return latest, err
592592
}
593593
} else if adoptionPolicy == AdoptionPolicy_Adopt {
594-
rm.FilterSystemTags(latest)
594+
rm.FilterSystemTags(latest, r.cfg.ResourceTagKeys)
595595
if err = r.setResourceManagedAndAdopted(ctx, rm, latest); err != nil {
596596
return latest, err
597597
}

pkg/runtime/reconciler_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func reconcilerMocks(
120120
featuregate.ReadOnlyResources: {Enabled: true},
121121
featuregate.ResourceAdoption: {Enabled: true},
122122
},
123+
ResourceTagKeys: []string{},
123124
}
124125
metrics := ackmetrics.NewMetrics("bookstore")
125126

@@ -393,7 +394,7 @@ func TestReconcilerAdoptResource(t *testing.T) {
393394
rd.On("Delta", latest, latest).Return(ackcompare.NewDelta())
394395

395396
r, kc, scmd := reconcilerMocks(rmf)
396-
rm.On("FilterSystemTags", latest).Return()
397+
rm.On("FilterSystemTags", latest, []string{})
397398
rd.On("MarkAdopted", latest).Return()
398399
rm.On("EnsureTags", ctx, desired, scmd).Return(nil)
399400
statusWriter := &ctrlrtclientmock.SubResourceWriter{}
@@ -783,7 +784,7 @@ func TestReconcilerUpdate(t *testing.T) {
783784
rm.On("ReadOne", ctx, desired).Return(
784785
latest, nil,
785786
)
786-
rm.On("FilterSystemTags", latest)
787+
rm.On("FilterSystemTags", latest, []string{})
787788
rm.On("Update", ctx, desired, latest, delta).Return(
788789
latest, nil,
789790
)
@@ -1851,6 +1852,7 @@ func TestReconcile_AccountDrifted(t *testing.T) {
18511852

18521853
// Create caches with the k8s client
18531854
caches := ackrtcache.New(fakeLogger, ackrtcache.Config{}, featuregate.FeatureGates{})
1855+
irscaches := iamroleselector.NewCache(fakeLogger)
18541856

18551857
// Run the caches
18561858
stopCh := make(chan struct{})
@@ -1891,6 +1893,7 @@ func TestReconcile_AccountDrifted(t *testing.T) {
18911893
log: fakeLogger,
18921894
cfg: ackcfg.Config{AccountID: "333333333333"},
18931895
carmCache: caches,
1896+
irsCache: irscaches,
18941897
metrics: ackmetrics.NewMetrics("test"),
18951898
},
18961899
rmf: rmf,

pkg/types/aws_resource_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type AWSResourceManager interface {
9090
// and this function will remove them before adoption.
9191
// Eg. resources created with cloudformation have tags that cannot be
9292
//removed by an ACK controller
93-
FilterSystemTags(AWSResource)
93+
FilterSystemTags(AWSResource, []string)
9494
}
9595

9696
// AWSResourceManagerFactory returns an AWSResourceManager that can be used to

0 commit comments

Comments
 (0)