From d49bfa9fe40048ad07b38700deca8a82b9fa7969 Mon Sep 17 00:00:00 2001 From: Caio Almeida Date: Thu, 30 Nov 2023 11:06:18 -0300 Subject: [PATCH] Supporting management policies feature --- cmd/provider/main.go | 6 ++++++ internal/controller/features/features.go | 5 +++++ internal/controller/workspace/workspace.go | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmd/provider/main.go b/cmd/provider/main.go index 741ef43f..e4cd04ba 100644 --- a/cmd/provider/main.go +++ b/cmd/provider/main.go @@ -58,6 +58,7 @@ func main() { maxReconcileRate = app.Flag("max-reconcile-rate", "The maximum number of concurrent reconciliation operations.").Default("1").Int() namespace = app.Flag("namespace", "Namespace used to set as default scope in default secret store config.").Default("crossplane-system").Envar("POD_NAMESPACE").String() enableExternalSecretStores = app.Flag("enable-external-secret-stores", "Enable support for ExternalSecretStores.").Default("false").Envar("ENABLE_EXTERNAL_SECRET_STORES").Bool() + enableManagementPolicies = app.Flag("enable-management-policies", "Enable support for Management Policies.").Default("true").Envar("ENABLE_MANAGEMENT_POLICIES").Bool() ) kingpin.MustParse(app.Parse(os.Args[1:])) @@ -109,6 +110,11 @@ func main() { Features: &feature.Flags{}, } + if *enableManagementPolicies { + o.Features.Enable(features.EnableBetaManagementPolicies) + log.Info("Beta feature enabled", "flag", features.EnableBetaManagementPolicies) + } + if *enableExternalSecretStores { o.Features.Enable(features.EnableAlphaExternalSecretStores) log.Info("Alpha feature enabled", "flag", features.EnableAlphaExternalSecretStores) diff --git a/internal/controller/features/features.go b/internal/controller/features/features.go index 8ab0c0bb..fad69608 100644 --- a/internal/controller/features/features.go +++ b/internal/controller/features/features.go @@ -24,4 +24,9 @@ const ( // External Secret Stores. See the below design for more details. // https://github.com/crossplane/crossplane/blob/390ddd/design/design-doc-external-secret-stores.md EnableAlphaExternalSecretStores feature.Flag = "EnableAlphaExternalSecretStores" + + // EnableBetaManagementPolicies enables beta support for + // Management Policies. See the below design for more details. + // https://github.com/crossplane/crossplane/pull/3531 + EnableBetaManagementPolicies feature.Flag = "EnableBetaManagementPolicies" ) diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go index f14b75a3..5c07d610 100644 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -122,6 +122,7 @@ func Setup(mgr ctrl.Manager, o controller.Options, timeout, pollJitter time.Dura if o.Features.Enabled(features.EnableAlphaExternalSecretStores) { cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), v1beta1.StoreConfigGroupVersionKind)) } + c := &connector{ kube: mgr.GetClient(), usage: resource.NewProviderConfigUsageTracker(mgr.GetClient(), &v1beta1.ProviderConfigUsage{}), @@ -130,15 +131,23 @@ func Setup(mgr ctrl.Manager, o controller.Options, timeout, pollJitter time.Dura terraform: func(dir string) tfclient { return terraform.Harness{Path: tfPath, Dir: dir} }, } - r := managed.NewReconciler(mgr, - resource.ManagedKind(v1beta1.WorkspaceGroupVersionKind), + opts := []managed.ReconcilerOption{ managed.WithPollInterval(o.PollInterval), managed.WithPollJitterHook(pollJitter), managed.WithExternalConnecter(c), managed.WithLogger(o.Logger.WithValues("controller", name)), managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))), managed.WithTimeout(timeout), - managed.WithConnectionPublishers(cps...)) + managed.WithConnectionPublishers(cps...), + } + + if o.Features.Enabled(features.EnableBetaManagementPolicies) { + opts = append(opts, managed.WithManagementPolicies()) + } + + r := managed.NewReconciler(mgr, + resource.ManagedKind(v1beta1.WorkspaceGroupVersionKind), + opts...) return ctrl.NewControllerManagedBy(mgr). Named(name).