Skip to content

Commit

Permalink
Merge pull request #219 from caiofralmeida/enable-management-policies
Browse files Browse the repository at this point in the history
feat: Supporting management policies beta feature
  • Loading branch information
ytsarev authored Dec 16, 2023
2 parents 6c487a3 + d49bfa9 commit 743bb95
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]))

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
15 changes: 12 additions & 3 deletions internal/controller/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
Expand All @@ -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).
Expand Down

0 comments on commit 743bb95

Please sign in to comment.