Skip to content

Commit 2e9295a

Browse files
committed
fix adb webhook and reconcile issue
1 parent c614050 commit 2e9295a

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ test: manifests generate fmt vet envtest ## Run unit tests.
6161

6262
E2ETEST ?= ./test/e2e/
6363
e2e: manifests generate fmt vet envtest ## Run e2e tests.
64-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" ginkgo -v --timeout=2h30m --fail-fast $(E2ETEST)
64+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(E2ETEST) -test.timeout 0 -test.v --ginkgo.fail-fast
6565

6666
##@ Build
6767

apis/database/v1alpha1/autonomousdatabase_webhook.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ func (r *AutonomousDatabase) ValidateUpdate(old runtime.Object) error {
164164
// cannot change lifecycleState with other fields together (except the oci config)
165165
var lifecycleChanged, otherFieldsChanged bool
166166

167-
lifecycleChanged = oldADB.Spec.Details.LifecycleState != "" && oldADB.Spec.Details.LifecycleState != r.Spec.Details.LifecycleState
167+
lifecycleChanged = oldADB.Spec.Details.LifecycleState != "" &&
168+
r.Spec.Details.LifecycleState != "" &&
169+
oldADB.Spec.Details.LifecycleState != r.Spec.Details.LifecycleState
168170
var copiedADB *AutonomousDatabaseSpec = r.Spec.DeepCopy()
169171
copiedADB.Details.LifecycleState = oldADB.Spec.Details.LifecycleState
170172
copiedADB.OCIConfig = oldADB.Spec.OCIConfig

controllers/database/autonomousdatabase_controller.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,15 @@ func (r *AutonomousDatabaseReconciler) eventFilterPredicate() predicate.Predicat
157157
if adbOk {
158158
oldADB := e.ObjectOld.(*dbv1alpha1.AutonomousDatabase)
159159

160-
if !reflect.DeepEqual(oldADB.Status, desiredADB.Status) ||
161-
(controllerutil.ContainsFinalizer(oldADB, dbv1alpha1.LastSuccessfulSpec) != controllerutil.ContainsFinalizer(desiredADB, dbv1alpha1.LastSuccessfulSpec)) ||
160+
statusChanged := !reflect.DeepEqual(oldADB.Status, desiredADB.Status)
161+
162+
oldLastSucSpec := oldADB.GetAnnotations()[dbv1alpha1.LastSuccessfulSpec]
163+
desiredLastSucSpec := desiredADB.GetAnnotations()[dbv1alpha1.LastSuccessfulSpec]
164+
lastSucSpecChanged := oldLastSucSpec != desiredLastSucSpec
165+
166+
if statusChanged || lastSucSpecChanged ||
162167
(controllerutil.ContainsFinalizer(oldADB, dbv1alpha1.ADBFinalizer) != controllerutil.ContainsFinalizer(desiredADB, dbv1alpha1.ADBFinalizer)) {
163-
// Don't enqueue if the status, lastSucSpec, or the finalizler changes
168+
// Don't enqueue if the status, lastSucSpec, or the finalizler changes the first time
164169
return false
165170
}
166171

@@ -458,8 +463,6 @@ func (r *AutonomousDatabaseReconciler) validateOperation(
458463
} else {
459464
l.Info("No operation specified; sync the resource")
460465

461-
testOldADB := adb.DeepCopy()
462-
463466
// The user doesn't change the spec and the controller should pull the spec from the OCI.
464467
specChanged, err := r.getADB(logger, adb)
465468
if err != nil {
@@ -470,12 +473,12 @@ func (r *AutonomousDatabaseReconciler) validateOperation(
470473
l.Info("The local spec doesn't match the oci's spec; update the CR")
471474

472475
// Erase the status.lifecycleState temporarily to avoid the webhook error.
473-
oldADB := adb.DeepCopy()
476+
tmpADB := adb.DeepCopy()
474477
adb.Status.LifecycleState = ""
475-
r.KubeClient.Status().Update(context.TODO(), adb)
476-
adb.Spec = oldADB.Spec
477-
478-
adb.DeepCopy().RemoveUnchangedDetails(testOldADB.Spec)
478+
if err := r.KubeClient.Status().Update(context.TODO(), adb); err != nil {
479+
return false, emptyResult, err
480+
}
481+
adb.Spec = tmpADB.Spec
479482

480483
if err := r.updateCR(adb); err != nil {
481484
return false, emptyResult, err
@@ -580,7 +583,9 @@ func (r *AutonomousDatabaseReconciler) validateFinalizer(logger logr.Logger, adb
580583
// updateCR updates the lastSucSpec and the CR
581584
func (r *AutonomousDatabaseReconciler) updateCR(adb *dbv1alpha1.AutonomousDatabase) error {
582585
// Update the lastSucSpec
583-
if err := adb.UpdateLastSuccessfulSpec(); err != nil {
586+
// Should patch the lastSuccessfulSpec first, otherwise, the update event will be
587+
// filtered out by predicate since the lastSuccessfulSpec is changed.
588+
if err := r.patchLastSuccessfulSpec(adb); err != nil {
584589
return err
585590
}
586591

@@ -933,22 +938,23 @@ func (r *AutonomousDatabaseReconciler) validateDesiredLifecycleState(
933938
}
934939

935940
// The logic of updating the network access configurations is as follows:
936-
// 1. Shared databases:
937-
// If the network access type changes
938-
// a. to PUBLIC:
941+
//
942+
// 1. Shared databases:
943+
// If the network access type changes
944+
// a. to PUBLIC:
939945
// was RESTRICTED: re-enable IsMTLSConnectionRequired if its not. Then set WhitelistedIps to an array with a single empty string entry.
940946
// was PRIVATE: re-enable IsMTLSConnectionRequired if its not. Then set PrivateEndpointLabel to an emtpy string.
941-
// b. to RESTRICTED:
947+
// b. to RESTRICTED:
942948
// was PUBLIC: set WhitelistedIps to desired IPs/CIDR blocks/VCN OCID. Configure the IsMTLSConnectionRequired settings if it is set to disabled.
943949
// was PRIVATE: re-enable IsMTLSConnectionRequired if its not. Set the type to PUBLIC first, and then configure the WhitelistedIps. Finally resume the IsMTLSConnectionRequired settings if it was, or is configured as disabled.
944-
// c. to PRIVATE:
950+
// c. to PRIVATE:
945951
// was PUBLIC: set subnetOCID and nsgOCIDs. Configure the IsMTLSConnectionRequired settings if it is set.
946952
// was RESTRICTED: set subnetOCID and nsgOCIDs. Configure the IsMTLSConnectionRequired settings if it is set.
947953
//
948-
// Otherwise, if the network access type remains the same, apply the network configuration, and then set the IsMTLSConnectionRequired.
954+
// Otherwise, if the network access type remains the same, apply the network configuration, and then set the IsMTLSConnectionRequired.
949955
//
950-
// 2. Dedicated databases:
951-
// Apply the configs directly
956+
// 2. Dedicated databases:
957+
// Apply the configs directly
952958
func (r *AutonomousDatabaseReconciler) validateGeneralNetworkAccess(
953959
logger logr.Logger,
954960
adb *dbv1alpha1.AutonomousDatabase,

0 commit comments

Comments
 (0)