Skip to content

Commit

Permalink
Pass management policy flag to the controllers
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Turken <turkenh@gmail.com>
  • Loading branch information
turkenh committed Apr 14, 2023
1 parent 9a37cdd commit 68e4b9e
Show file tree
Hide file tree
Showing 25 changed files with 228 additions and 82 deletions.
12 changes: 9 additions & 3 deletions pkg/controller/cache/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@ func SetupCloudMemorystoreInstance(mgr ctrl.Manager, o controller.Options) error
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.CloudMemorystoreInstanceGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1beta1.CloudMemorystoreInstanceGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
13 changes: 9 additions & 4 deletions pkg/controller/compute/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ func SetupAddress(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.AddressGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&addressConnector{kube: mgr.GetClient()}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1beta1.AddressGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/compute/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ func SetupFirewall(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1alpha1.FirewallGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&firewallConnector{kube: mgr.GetClient()}),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithPollInterval(o.PollInterval),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.FirewallGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
13 changes: 9 additions & 4 deletions pkg/controller/compute/globaladdress.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ func SetupGlobalAddress(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.GlobalAddressGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&gaConnector{kube: mgr.GetClient()}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1beta1.GlobalAddressGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
13 changes: 9 additions & 4 deletions pkg/controller/compute/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ func SetupNetwork(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.NetworkGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&networkConnector{kube: mgr.GetClient()}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1beta1.NetworkGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/compute/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ func SetupRouter(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1alpha1.RouterGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&routerConnector{kube: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithPollInterval(o.PollInterval),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.RouterGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
13 changes: 9 additions & 4 deletions pkg/controller/compute/subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ func SetupSubnetwork(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.SubnetworkGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&subnetworkConnector{kube: mgr.GetClient()}),
managed.WithConnectionPublishers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1beta1.SubnetworkGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/container/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ func SetupCluster(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta2.ClusterGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&clusterConnector{kube: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1beta2.ClusterGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/container/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ func SetupNodePool(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.NodePoolGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&nodePoolConnector{kube: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1beta1.NodePoolGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/database/cloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,20 @@ func SetupCloudSQLInstance(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1beta1.CloudSQLInstanceGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&cloudsqlConnector{kube: mgr.GetClient()}),
managed.WithInitializers(managed.NewNameAsExternalName(mgr.GetClient()), &cloudsqlTagger{kube: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1beta1.CloudSQLInstanceGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/dns/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ func SetupPolicy(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1alpha1.PolicyGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&policyConnector{kube: mgr.GetClient()}),
managed.WithInitializers(managed.NewNameAsExternalName(mgr.GetClient())),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.PolicyGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/dns/resource_record_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ func SetupResourceRecordSet(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1alpha1.ResourceRecordSetGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connector{kube: mgr.GetClient()}),
managed.WithInitializers(rrsclient.NewCustomNameAsExternalName(mgr.GetClient())),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.ResourceRecordSetGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
17 changes: 12 additions & 5 deletions pkg/controller/iam/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ func SetupServiceAccount(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1alpha1.ServiceAccountGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.ServiceAccountGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down Expand Up @@ -190,8 +196,9 @@ func (e *external) Delete(ctx context.Context, mg resource.Managed) error {
}

// isUpToDate returns true if the supplied Kubernetes resource does not differ
// from the supplied GCP resource. It considers only fields that can be
// modified in place without deleting and recreating the Service Account.
//
// from the supplied GCP resource. It considers only fields that can be
// modified in place without deleting and recreating the Service Account.
func isUpToDate(in *v1alpha1.ServiceAccountParameters, observed *iamv1.ServiceAccount) bool {
// see comment in serviceaccount_types.go
if in.DisplayName != nil && *in.DisplayName != observed.DisplayName {
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/iam/serviceaccountkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,20 @@ func SetupServiceAccountKey(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1alpha1.ServiceAccountKeyGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithInitializers(),
managed.WithExternalConnecter(&serviceAccountKeyServiceConnector{client: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.ServiceAccountKeyGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/iam/serviceaccountpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ func SetupServiceAccountPolicy(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1alpha1.ServiceAccountPolicyGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&serviceAccountPolicyConnecter{client: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.ServiceAccountPolicyGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
12 changes: 9 additions & 3 deletions pkg/controller/kms/cryptokey.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ func SetupCryptoKey(mgr ctrl.Manager, o controller.Options) error {
cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), scv1alpha1.StoreConfigGroupVersionKind))
}

r := managed.NewReconciler(mgr,
resource.ManagedKind(v1alpha1.CryptoKeyGroupVersionKind),
opts := []managed.ReconcilerOption{
managed.WithExternalConnecter(&cryptoKeyConnecter{client: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...))
managed.WithConnectionPublishers(cps...),
}

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

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.CryptoKeyGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Named(name).
Expand Down
Loading

0 comments on commit 68e4b9e

Please sign in to comment.