Skip to content

Commit

Permalink
chore: remove the failure check for volumeExpansion opsRequest (#5379)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Oct 11, 2023
1 parent b9867a3 commit 22d1387
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 450 deletions.
9 changes: 0 additions & 9 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,6 @@ func main() {
os.Exit(1)
}

if err = (&k8scorecontrollers.PersistentVolumeClaimReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("pvc-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "PersistentVolumeClaim")
os.Exit(1)
}

if err = (&appscontrollers.ComponentClassReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Expand Down
7 changes: 0 additions & 7 deletions controllers/apps/operations/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1"
"github.com/apecloud/kubeblocks/controllers/apps/components"
"github.com/apecloud/kubeblocks/controllers/k8score"
"github.com/apecloud/kubeblocks/internal/constant"
intctrlutil "github.com/apecloud/kubeblocks/internal/controllerutil"
"github.com/apecloud/kubeblocks/internal/testutil"
Expand Down Expand Up @@ -120,12 +119,6 @@ var _ = BeforeSuite(func() {
Expect(err).ToNot(HaveOccurred())

eventRecorder = k8sManager.GetEventRecorderFor("event-controller")
err = (&k8score.PersistentVolumeClaimReconciler{
Client: k8sManager.GetClient(),
Scheme: k8sManager.GetScheme(),
Recorder: k8sManager.GetEventRecorderFor("pvc-controller"),
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

appsv1alpha1.RegisterWebhookManager(k8sManager)

Expand Down
54 changes: 0 additions & 54 deletions controllers/apps/operations/volume_expansion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,56 +145,6 @@ var _ = Describe("OpsRequest Controller Volume Expansion Handler", func() {
Expect(err).Should(BeNil())
}

testWarningEventOnPVC := func(reqCtx intctrlutil.RequestCtx, clusterObject *appsv1alpha1.Cluster, opsRes *OpsResource) {
// init resources for volume expansion
comp := opsRes.Cluster.Spec.GetComponentByName(consensusCompName)
newOps, pvcNames := initResourcesForVolumeExpansion(clusterObject, opsRes, "4Gi", int(comp.Replicas))

By("mock run volumeExpansion action and reconcileAction")
mockVolumeExpansionActionAndReconcile(reqCtx, opsRes, newOps, pvcNames)

By("test warning event and volumeExpansion failed")
// test when the event does not reach the conditions
event := &corev1.Event{
Count: 1,
Type: corev1.EventTypeWarning,
Reason: VolumeResizeFailed,
Message: OptimisticLockErrorMsg,
}
stsInvolvedObject := corev1.ObjectReference{
Name: pvcNames[0],
Kind: constant.PersistentVolumeClaimKind,
Namespace: "default",
}
event.InvolvedObject = stsInvolvedObject
pvcEventHandler := PersistentVolumeClaimEventHandler{}
Expect(pvcEventHandler.Handle(k8sClient, reqCtx, eventRecorder, event)).Should(Succeed())

// test when the event reaches the conditions
event.Count = 5
event.FirstTimestamp = metav1.Time{Time: time.Now()}
event.LastTimestamp = metav1.Time{Time: time.Now().Add(61 * time.Second)}

By("expect for progressDetail is not failed")
Expect(pvcEventHandler.Handle(k8sClient, reqCtx, eventRecorder, event)).Should(Succeed())
Eventually(testapps.CheckObj(&testCtx, client.ObjectKeyFromObject(newOps), func(g Gomega, tmpOps *appsv1alpha1.OpsRequest) {
progressDetails := tmpOps.Status.Components[consensusCompName].ProgressDetails
g.Expect(len(progressDetails) > 0).Should(BeTrue())
progressDetail := findStatusProgressDetail(progressDetails, getPVCProgressObjectKey(pvcNames[0]))
g.Expect(progressDetail.Status).ShouldNot(Equal(appsv1alpha1.FailedProgressStatus))
})).Should(Succeed())

By("expect for progressDetail is failed")
event.Message = "You've reached the maximum modification rate per volume limit. Wait at least 6 hours between modifications per EBS volume."
Expect(pvcEventHandler.Handle(k8sClient, reqCtx, eventRecorder, event)).Should(Succeed())
Eventually(testapps.CheckObj(&testCtx, client.ObjectKeyFromObject(newOps), func(g Gomega, tmpOps *appsv1alpha1.OpsRequest) {
progressDetails := tmpOps.Status.Components[consensusCompName].ProgressDetails
g.Expect(len(progressDetails) > 0).Should(BeTrue())
progressDetail := findStatusProgressDetail(progressDetails, getPVCProgressObjectKey(pvcNames[0]))
g.Expect(progressDetail.Status).Should(Equal(appsv1alpha1.FailedProgressStatus))
})).Should(Succeed())
}

testVolumeExpansion := func(reqCtx intctrlutil.RequestCtx, clusterObject *appsv1alpha1.Cluster, opsRes *OpsResource, randomStr string) {
// mock cluster is Running to support volume expansion ops
Expect(testapps.ChangeObjStatus(&testCtx, clusterObject, func() {
Expand Down Expand Up @@ -262,7 +212,6 @@ var _ = Describe("OpsRequest Controller Volume Expansion Handler", func() {
By("test handle the invalid volumeExpansion OpsRequest")
pvc := &corev1.PersistentVolumeClaim{}
Expect(k8sClient.Get(ctx, client.ObjectKey{Name: pvcNames[0], Namespace: testCtx.DefaultNamespace}, pvc)).Should(Succeed())
Expect(handleVolumeExpansionWithPVC(intctrlutil.RequestCtx{Ctx: ctx}, k8sClient, pvc)).Should(Succeed())

Eventually(testapps.GetClusterPhase(&testCtx, client.ObjectKeyFromObject(clusterObject))).Should(Equal(appsv1alpha1.RunningClusterPhase))
}
Expand Down Expand Up @@ -296,9 +245,6 @@ var _ = Describe("OpsRequest Controller Volume Expansion Handler", func() {
By("Test VolumeExpansion")
testVolumeExpansion(reqCtx, clusterObject, opsRes, randomStr)

By("Test Warning Event occurs during volume expanding")
testWarningEventOnPVC(reqCtx, clusterObject, opsRes)

By("Test delete the Running VolumeExpansion OpsRequest")
testDeleteRunningVolumeExpansion(clusterObject, opsRes)
})
Expand Down
197 changes: 0 additions & 197 deletions controllers/apps/operations/volume_expansion_updater.go

This file was deleted.

27 changes: 27 additions & 0 deletions controllers/apps/opsrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (r *OpsRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&appsv1alpha1.OpsRequest{}).
Watches(&appsv1alpha1.Cluster{}, handler.EnqueueRequestsFromMapFunc(r.parseAllOpsRequest)).
Watches(&dpv1alpha1.Backup{}, handler.EnqueueRequestsFromMapFunc(r.parseBackupOpsRequest)).
Watches(&corev1.PersistentVolumeClaim{}, handler.EnqueueRequestsFromMapFunc(r.parseVolumeExpansionOpsRequest)).
Complete(r)
}

Expand Down Expand Up @@ -305,6 +306,32 @@ func (r *OpsRequestReconciler) parseAllOpsRequest(ctx context.Context, object cl
return requests
}

func (r *OpsRequestReconciler) parseVolumeExpansionOpsRequest(ctx context.Context, object client.Object) []reconcile.Request {
pvc := object.(*corev1.PersistentVolumeClaim)
if pvc.Labels[constant.AppManagedByLabelKey] != constant.AppName {
return nil
}
clusterName := pvc.Labels[constant.AppInstanceLabelKey]
if clusterName == "" {
return nil
}
opsRequestList, err := appsv1alpha1.GetRunningOpsByOpsType(ctx, r.Client,
pvc.Labels[constant.AppInstanceLabelKey], pvc.Namespace, string(appsv1alpha1.VolumeExpansionType))
if err != nil {
return nil
}
var requests []reconcile.Request
for _, v := range opsRequestList {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: v.Namespace,
Name: v.Name,
},
})
}
return requests
}

func (r *OpsRequestReconciler) parseBackupOpsRequest(ctx context.Context, object client.Object) []reconcile.Request {
backup := object.(*dpv1alpha1.Backup)
var (
Expand Down
Loading

0 comments on commit 22d1387

Please sign in to comment.