Skip to content

Commit

Permalink
fix: set backuppolicy.spec.backofflimit to default value (#7192)
Browse files Browse the repository at this point in the history
Set backofflimit to default value when creating backuppolicy

(cherry picked from commit 4b299f2)
  • Loading branch information
gnolong authored and wangyelei committed May 7, 2024
1 parent c0aee07 commit f164b11
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions apis/apps/v1alpha1/backuppolicytemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type BackupPolicy struct {
// Specifies the maximum number of retry attempts for a backup before it is considered a failure.
//
// +optional
// +kubebuilder:default=2
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=10
BackoffLimit *int32 `json:"backoffLimit,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions apis/dataprotection/v1alpha1/backuppolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type BackupPolicySpec struct {
// Specifies the number of retries before marking the backup as failed.
//
// +optional
// +kubebuilder:default=2
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=10
BackoffLimit *int32 `json:"backoffLimit,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ spec:
are different versions of definitions of the same component.
properties:
backoffLimit:
default: 2
description: Specifies the maximum number of retry attempts
for a backup before it is considered a failure.
format: int32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ spec:
description: BackupPolicySpec defines the desired state of BackupPolicy
properties:
backoffLimit:
default: 2
description: Specifies the number of retries before marking the backup
as failed.
format: int32
Expand Down
1 change: 0 additions & 1 deletion controllers/apps/transformer_cluster_backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ func (r *clusterBackupPolicyTransformer) syncBackupPolicy(comp *appsv1alpha1.Clu
backupPolicy.Spec.BackupRepoName = &r.Cluster.Spec.Backup.RepoName
}
backupPolicy.Spec.BackoffLimit = r.backupPolicy.BackoffLimit

r.syncBackupMethods(backupPolicy, comp)
r.syncBackupPolicyTargetSpec(backupPolicy, comp)
}
Expand Down
1 change: 1 addition & 0 deletions controllers/dataprotection/backuppolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (r *BackupPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
return intctrlutil.Reconciled()
}

if err = patchStatus(dpv1alpha1.AvailablePhase, ""); err != nil {
return intctrlutil.CheckedRequeueWithError(err, reqCtx.Log, "")
}
Expand Down
13 changes: 13 additions & 0 deletions controllers/dataprotection/backuppolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/constant"
dptypes "github.com/apecloud/kubeblocks/pkg/dataprotection/types"
"github.com/apecloud/kubeblocks/pkg/generics"
testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
testdp "github.com/apecloud/kubeblocks/pkg/testutil/dataprotection"
Expand Down Expand Up @@ -60,6 +61,18 @@ var _ = Describe("BackupPolicy Controller test", func() {
})

Context("create a backup policy", func() {
It("test backup policy without setting backoffLimit", func() {
By("creating backupPolicy without setting backoffLimit")
bp := testdp.NewFakeBackupPolicy(&testCtx, func(backupPolicy *dpv1alpha1.BackupPolicy) {
backupPolicy.Spec.BackoffLimit = nil
})
By("expect its backoffLimit should be set to the value of DefaultBackOffLimit")
Eventually(testapps.CheckObj(&testCtx, client.ObjectKeyFromObject(bp),
func(g Gomega, bp *dpv1alpha1.BackupPolicy) {
g.Expect(*bp.Spec.BackoffLimit).Should(Equal(dptypes.DefaultBackOffLimit))
})).Should(Succeed())
})

It("backup policy should be available for target", func() {
By("creating actionSet used by backup policy")
as := testdp.NewFakeActionSet(&testCtx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ spec:
are different versions of definitions of the same component.
properties:
backoffLimit:
default: 2
description: Specifies the maximum number of retry attempts
for a backup before it is considered a failure.
format: int32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ spec:
description: BackupPolicySpec defines the desired state of BackupPolicy
properties:
backoffLimit:
default: 2
description: Specifies the number of retries before marking the backup
as failed.
format: int32
Expand Down

0 comments on commit f164b11

Please sign in to comment.