Skip to content

Commit

Permalink
Partially enable direct controller for regional tcp proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Dec 5, 2024
1 parent bc85425 commit 19bf1c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"reflect"
"strings"

kccpredicate "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/predicate"

"google.golang.org/api/option"

gcp "cloud.google.com/go/compute/apiv1"
Expand All @@ -38,13 +40,32 @@ import (
const ctrlName = "firewallpolicyrule-controller"

func init() {
registry.RegisterModel(krm.ComputeTargetTCPProxyGVK, NewtargetTCPProxyModel)
rg := &TargetTCPProxyReconcileGate{}
registry.RegisterModelWithReconcileGate(krm.ComputeTargetTCPProxyGVK, NewTargetTCPProxyModel, rg)
}

func NewtargetTCPProxyModel(ctx context.Context, config *config.ControllerConfig) (directbase.Model, error) {
func NewTargetTCPProxyModel(ctx context.Context, config *config.ControllerConfig) (directbase.Model, error) {
return &targetTCPProxyModel{config: config}, nil
}

type TargetTCPProxyReconcileGate struct {
optIn kccpredicate.OptInToDirectReconciliation
}

var _ kccpredicate.ReconcileGate = &TargetTCPProxyReconcileGate{}

func (r *TargetTCPProxyReconcileGate) ShouldReconcile(o *unstructured.Unstructured) bool {
if r.optIn.ShouldReconcile(o) {
return true
}
obj := &krm.ComputeTargetTCPProxy{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(o.Object, &obj); err != nil {
return false
}
// Run the direct reconciler only when spec.location is specified and not global
return obj.Spec.Location != nil && obj.Spec.Location != direct.PtrTo("global")
}

type targetTCPProxyModel struct {
config *config.ControllerConfig
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeTargetTCPProxy
metadata:
annotations:
alpha.cnrm.cloud.google.com/reconciler: direct
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/project-id: ${projectId}
finalizers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ kind: ComputeTargetTCPProxy
metadata:
annotations:
cnrm.cloud.google.com/project-id: ${projectId}
alpha.cnrm.cloud.google.com/reconciler: "direct"
name: computetargettcpproxy-${uniqueId}
spec:
description: "test target tcp proxy"
Expand Down

0 comments on commit 19bf1c4

Please sign in to comment.