Skip to content

Commit

Permalink
partially enable direct controller when target google api bundle is set
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Sep 24, 2024
1 parent b6b5ba4 commit d0b0f18
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/controller/direct/compute/forwardingrule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry"
kccpredicate "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/predicate"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -39,13 +40,32 @@ import (
const ctrlName = "forwardingrule-controller"

func init() {
registry.RegisterModel(krm.ComputeForwardingRuleGVK, NewForwardingRuleModel)
rg := &ForwardingRUleReconcileGate{}
registry.RegisterModelWithReconcileGate(krm.ComputeForwardingRuleGVK, NewForwardingRuleModel, rg)
}

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

type ForwardingRUleReconcileGate struct {
optIn kccpredicate.OptInToDirectReconciliation
}

var _ kccpredicate.ReconcileGate = &ForwardingRUleReconcileGate{}

func (r *ForwardingRUleReconcileGate) ShouldReconcile(o *unstructured.Unstructured) bool {
if r.optIn.ShouldReconcile(o) {
return true
}
obj := &krm.ComputeForwardingRule{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(o.Object, &obj); err != nil {
return false
}
// Run the direct reconciler only when spec.Target.GoogleAPIBundle is specified
return obj.Spec.Target != nil && obj.Spec.Target.GoogleAPIBundle != nil
}

type forwardingRuleModel struct {
config *config.ControllerConfig
}
Expand Down

0 comments on commit d0b0f18

Please sign in to comment.