Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enable TF-based reconciler for SQLInstances without clone source #2731

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/sql/v1beta1/sqlinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ type SQLInstanceStatus struct {
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=gcp,shortName=gcpsqlinstance;gcpsqlinstances
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/stability-level=stable";"cnrm.cloud.google.com/system=true"
// +kubebuilder:metadata:labels="cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/stability-level=stable";"cnrm.cloud.google.com/system=true";"cnrm.cloud.google.com/tf2crd=true"
// +kubebuilder:printcolumn:name="Age",JSONPath=".metadata.creationTimestamp",type="date"
// +kubebuilder:printcolumn:name="Ready",JSONPath=".status.conditions[?(@.type=='Ready')].status",type="string",description="When 'True', the most recent reconcile of the resource succeeded"
// +kubebuilder:printcolumn:name="Status",JSONPath=".status.conditions[?(@.type=='Ready')].reason",type="string",description="The reason for the value in 'Ready'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
cnrm.cloud.google.com/managed-by-kcc: "true"
cnrm.cloud.google.com/stability-level: stable
cnrm.cloud.google.com/system: "true"
cnrm.cloud.google.com/tf2crd: "true"
name: sqlinstances.sql.cnrm.cloud.google.com
spec:
group: sql.cnrm.cloud.google.com
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions pkg/controller/registration/registration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,12 @@ func registerDefaultController(r *ReconcileRegistration, config *config.Controll

// If we have a choice of controllers, construct predicates to choose between them
if hasDirectController && (hasTerraformController || hasDCLController) {
reconcileGate := registry.GetReconcileGate(gvk.GroupKind())
if reconcileGate != nil {
if reconcileGate := registry.GetReconcileGate(gvk.GroupKind()); reconcileGate != nil {
// If reconcile gate is enabled for this gvk, generate a controller-runtime predicate that will
// run the direct reconciler only when the reconcile gate returns true.
useDirectReconcilerPredicate = kccpredicate.NewReconcilePredicate(r.mgr.GetClient(), gvk, reconcileGate)
useLegacyPredicate = kccpredicate.NewInverseReconcilePredicate(r.mgr.GetClient(), gvk, reconcileGate)
}

if !hasTerraformController && !hasDCLController {
// We're always going to use the direct reconciler
useDirectReconcilerPredicate = nil
useLegacyPredicate = nil
}

if (hasTerraformController || hasDCLController) && useDirectReconcilerPredicate == nil {
} else {
logger.Error(fmt.Errorf("no predicate where we have multiple controllers"), "skipping direct controller registration", "group", gvk.Group, "version", gvk.Version, "kind", gvk.Kind)
hasDirectController = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we decouple the CRDs and controllers and let the labels on CRD to choose the controller. It only moves from TF to direct but not vice versa (which is an important precondition).

Now the controller decision is switched to the CR object.

I like the reconcile gate idea overall (except that it is very challenge to figure out which reconciler is being used, that could make triaging more difficult). I think my concern is mainly that the reconcile gate has changed the concept about some basic concept about the direct registry and label based reconciliations, that is not covered by any of our guides, tools, and test.

}
Expand All @@ -282,7 +273,6 @@ func registerDefaultController(r *ReconcileRegistration, config *config.Controll
return nil, fmt.Errorf("error adding direct controller for %v to a manager: %w", crd.Spec.Names.Kind, err)
}
}

// register controllers for dcl-based CRDs
if hasDCLController {
su, err := dclcontroller.Add(r.mgr, crd, r.dclConverter, r.dclConfig, r.smLoader, r.defaulters, r.jitterGenerator, useLegacyPredicate)
Expand Down
7 changes: 5 additions & 2 deletions scripts/github-actions/tests-e2e-fixtures-vcr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ source ${REPO_ROOT}/scripts/fetch_ext_bins.sh && \
cd ${REPO_ROOT}/
echo "Running e2e fixtures test with vcr replay mode..."
E2E_KUBE_TARGET=envtest \
RUN_E2E=1 E2E_GCP_TARGET=vcr VCR_MODE=replay \
go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures 2>&1
RUN_E2E=1 \
E2E_GCP_TARGET=vcr \
VCR_MODE=replay \
KCC_USE_DIRECT_RECONCILERS="SQLInstance" \
go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures 2>&1
Loading