github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/testutil/dataprotection/utils.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  This file is part of KubeBlocks project
     5  
     6  This program is free software: you can redistribute it and/or modify
     7  it under the terms of the GNU Affero General Public License as published by
     8  the Free Software Foundation, either version 3 of the License, or
     9  (at your option) any later version.
    10  
    11  This program is distributed in the hope that it will be useful
    12  but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  GNU Affero General Public License for more details.
    15  
    16  You should have received a copy of the GNU Affero General Public License
    17  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18  */
    19  
    20  package dataprotection
    21  
    22  import (
    23  	. "github.com/onsi/gomega"
    24  
    25  	vsv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
    26  	batchv1 "k8s.io/api/batch/v1"
    27  	corev1 "k8s.io/api/core/v1"
    28  	"sigs.k8s.io/controller-runtime/pkg/client"
    29  
    30  	dpv1alpha1 "github.com/1aal/kubeblocks/apis/dataprotection/v1alpha1"
    31  	"github.com/1aal/kubeblocks/pkg/testutil"
    32  	testapps "github.com/1aal/kubeblocks/pkg/testutil/apps"
    33  )
    34  
    35  func PatchK8sJobStatus(testCtx *testutil.TestContext, key client.ObjectKey, jobStatus batchv1.JobConditionType) {
    36  	Eventually(testapps.GetAndChangeObjStatus(testCtx, key, func(fetched *batchv1.Job) {
    37  		jobCondition := batchv1.JobCondition{Type: jobStatus, Status: corev1.ConditionTrue}
    38  		fetched.Status.Conditions = append(fetched.Status.Conditions, jobCondition)
    39  	})).Should(Succeed())
    40  }
    41  
    42  func ReplaceK8sJobStatus(testCtx *testutil.TestContext, key client.ObjectKey, jobStatus batchv1.JobConditionType) {
    43  	Eventually(testapps.GetAndChangeObjStatus(testCtx, key, func(fetched *batchv1.Job) {
    44  		jobCondition := batchv1.JobCondition{Type: jobStatus, Status: corev1.ConditionTrue}
    45  		fetched.Status.Conditions = []batchv1.JobCondition{jobCondition}
    46  	})).Should(Succeed())
    47  }
    48  
    49  func PatchVolumeSnapshotStatus(testCtx *testutil.TestContext, key client.ObjectKey, readyToUse bool) {
    50  	Eventually(testapps.GetAndChangeObjStatus(testCtx, key, func(fetched *vsv1.VolumeSnapshot) {
    51  		snapStatus := vsv1.VolumeSnapshotStatus{ReadyToUse: &readyToUse}
    52  		fetched.Status = &snapStatus
    53  	})).Should(Succeed())
    54  }
    55  
    56  func PatchBackupStatus(testCtx *testutil.TestContext, key client.ObjectKey, status dpv1alpha1.BackupStatus) {
    57  	Eventually(testapps.GetAndChangeObjStatus(testCtx, key, func(fetched *dpv1alpha1.Backup) {
    58  		fetched.Status = status
    59  	})).Should(Succeed())
    60  }