Skip to content

Commit

Permalink
fix: Enable TF-based reconciler for SQLInstances without clone source
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvigil committed Sep 18, 2024
1 parent 5b1307c commit 4d28f72
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
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
}
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

0 comments on commit 4d28f72

Please sign in to comment.