Skip to content

Commit

Permalink
Pass management policy flag to the controllers
Browse files Browse the repository at this point in the history
Fixes #1726

hacked using emacs:

	for f in $(grep -lr 'func Setup' pkg/controller/  ); do emacs --load refactor.el "$f"; done

refactor.el:

	(defun last-macro ()
	  (interactive)
	  (atomic-change-group
		(search-forward "func Setup")
		(search-forward "managed.NewReconciler")
		(search-backward "m")
		(set-mark-command nil)
		(search-forward "(")
		(left-char 1)
		(forward-sexp 1 (point))

		(kill-region nil nil 'region)
		(insert "r")

		(search-backward "return")

		(previous-line 1 1)
		(end-of-line)
		(newline nil 1)
		(insert "r := ")
		(yank nil)
		(newline nil 1)
		(search-backward "r := ")
		(search-forward "resource.ManagedKind")
		(forward-sexp 1 (point))
		(move-end-of-line 1)

		(newline nil 1)
		(insert "reconcilerOpts...")
		(set-mark-command nil)
		(search-backward "managed.NewReconciler")
		(search-forward "(")
		(left-char 1)
		(forward-sexp 1 (point))
		(left-char 1)
		(kill-region nil nil 'region)

		(search-backward "r :=")
		(previous-line 1 1)
		(insert "

	reconcilerOpts := []managed.ReconcilerOption{")
		(yank nil)
		(insert ",
	}

	")
		(insert "if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
			reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
		}
	")

		(goto-line 1)
		(search-forward "github.com/crossplane-contrib/provider-aws")
		(end-of-line)
		(insert "\n\"github.com/crossplane-contrib/provider-aws/pkg/features\"")

		(save-buffer 1)
		))

	(add-hook 'go-mode-hook #'last-macro)

Signed-off-by: Carl Henrik Lunde <[email protected]>
  • Loading branch information
chlunde committed Apr 27, 2023
1 parent 43a6ba2 commit 5af8f50
Show file tree
Hide file tree
Showing 160 changed files with 2,987 additions and 1,371 deletions.
30 changes: 20 additions & 10 deletions pkg/controller/acm/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,31 @@ func SetupCertificate(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), v1alpha1.StoreConfigGroupVersionKind))
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{client: mgr.GetClient(), newClientFn: acm.NewClient}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithInitializers(&tagger{kube: mgr.GetClient()}),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.CertificateGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&v1beta1.Certificate{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.CertificateGroupVersionKind),
managed.WithExternalConnecter(&connector{client: mgr.GetClient(), newClientFn: acm.NewClient}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithInitializers(&tagger{kube: mgr.GetClient()}),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...)))
Complete(r)
}

type connector struct {
Expand Down
28 changes: 19 additions & 9 deletions pkg/controller/acmpca/certificateauthority/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,30 @@ func SetupCertificateAuthority(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), v1alpha1.StoreConfigGroupVersionKind))
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{client: mgr.GetClient(), newClientFn: acmpca.NewClient}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithInitializers(&tagger{kube: mgr.GetClient()}),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.CertificateAuthorityGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&v1beta1.CertificateAuthority{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.CertificateAuthorityGroupVersionKind),
managed.WithExternalConnecter(&connector{client: mgr.GetClient(), newClientFn: acmpca.NewClient}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithInitializers(&tagger{kube: mgr.GetClient()}),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...)))
Complete(r)
}

type connector struct {
Expand Down
30 changes: 20 additions & 10 deletions pkg/controller/acmpca/certificateauthoritypermission/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,31 @@ func SetupCertificateAuthorityPermission(mgr ctrl.Manager, o controller.Options)
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), v1alpha1.StoreConfigGroupVersionKind))
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{client: mgr.GetClient(), newClientFn: acmpca.NewCAPermissionClient}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithInitializers(),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.CertificateAuthorityPermissionGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&v1beta1.CertificateAuthorityPermission{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.CertificateAuthorityPermissionGroupVersionKind),
managed.WithExternalConnecter(&connector{client: mgr.GetClient(), newClientFn: acmpca.NewCAPermissionClient}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithInitializers(),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...)))
Complete(r)
}

type connector struct {
Expand Down
26 changes: 19 additions & 7 deletions pkg/controller/apigateway/method/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
svcapitypes "github.com/crossplane-contrib/provider-aws/apis/apigateway/v1alpha1"
aws "github.com/crossplane-contrib/provider-aws/pkg/clients"
apigwclient "github.com/crossplane-contrib/provider-aws/pkg/clients/apigateway"
"github.com/crossplane-contrib/provider-aws/pkg/features"
)

// SetupMethod adds a controller that reconciles Method.
Expand All @@ -36,18 +37,29 @@ func SetupMethod(mgr ctrl.Manager, o controller.Options) error {
e.lateInitialize = c.lateInitialize
},
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.MethodGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&svcapitypes.Method{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.MethodGroupVersionKind),
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
Complete(r)
}

type custom struct {
Expand Down
26 changes: 19 additions & 7 deletions pkg/controller/apigateway/resource/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
svcapitypes "github.com/crossplane-contrib/provider-aws/apis/apigateway/v1alpha1"
aws "github.com/crossplane-contrib/provider-aws/pkg/clients"
apigwclient "github.com/crossplane-contrib/provider-aws/pkg/clients/apigateway"
"github.com/crossplane-contrib/provider-aws/pkg/features"
)

// SetupResource adds a controller that reconciles Resource.
Expand All @@ -55,18 +56,29 @@ func SetupResource(mgr ctrl.Manager, o controller.Options) error {
e.preCreate = c.preCreate
},
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.ResourceGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&svcapitypes.Resource{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.ResourceGroupVersionKind),
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
Complete(r)
}

type custom struct {
Expand Down
26 changes: 19 additions & 7 deletions pkg/controller/apigateway/restapi/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
svcapitypes "github.com/crossplane-contrib/provider-aws/apis/apigateway/v1alpha1"
aws "github.com/crossplane-contrib/provider-aws/pkg/clients"
apigwclient "github.com/crossplane-contrib/provider-aws/pkg/clients/apigateway"
"github.com/crossplane-contrib/provider-aws/pkg/features"
)

// SetupRestAPI adds a controller that reconciles RestAPI.
Expand All @@ -54,18 +55,29 @@ func SetupRestAPI(mgr ctrl.Manager, o controller.Options) error {
e.preUpdate = c.preUpdate
},
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.RestAPIGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&svcapitypes.RestAPI{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.RestAPIGroupVersionKind),
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
Complete(r)
}

type custom struct {
Expand Down
26 changes: 18 additions & 8 deletions pkg/controller/apigatewayv2/api/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,29 @@ func SetupAPI(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), v1alpha1.StoreConfigGroupVersionKind))
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.APIGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&svcapitypes.API{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.APIGroupVersionKind),
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...)))
Complete(r)
}

func preObserve(_ context.Context, cr *svcapitypes.API, obj *svcsdk.GetApiInput) error {
Expand Down
26 changes: 18 additions & 8 deletions pkg/controller/apigatewayv2/apimapping/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,29 @@ func SetupAPIMapping(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), v1alpha1.StoreConfigGroupVersionKind))
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.APIMappingGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&svcapitypes.APIMapping{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.APIMappingGroupVersionKind),
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...)))
Complete(r)
}

func preObserve(_ context.Context, cr *svcapitypes.APIMapping, obj *svcsdk.GetApiMappingInput) error {
Expand Down
26 changes: 18 additions & 8 deletions pkg/controller/apigatewayv2/authorizer/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,29 @@ func SetupAuthorizer(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), v1alpha1.StoreConfigGroupVersionKind))
}

reconcilerOpts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.AuthorizerGroupVersionKind),
reconcilerOpts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
WithOptions(o.ForControllerRuntime()).
WithEventFilter(resource.DesiredStateChanged()).
For(&svcapitypes.Authorizer{}).
Complete(managed.NewReconciler(mgr,
resource.ManagedKind(svcapitypes.AuthorizerGroupVersionKind),
managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...)))
Complete(r)
}

func preObserve(_ context.Context, cr *svcapitypes.Authorizer, obj *svcsdk.GetAuthorizerInput) error {
Expand Down
Loading

0 comments on commit 5af8f50

Please sign in to comment.