1
0
Fork 0
mirror of https://github.com/kastenhq/kubestr.git synced 2024-12-14 11:57:56 +00:00

Added image option to fio command (#43)

This commit is contained in:
Sirish Bathina 2020-12-14 14:14:53 -10:00 committed by GitHub
parent 60c417eff1
commit d3e1ce5f2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 13 deletions

View file

@ -42,8 +42,9 @@ var (
},
}
storageClass string
namespace string
storageClass string
namespace string
containerImage string
fioCheckerSize string
fioCheckerFilePath string
@ -55,13 +56,12 @@ var (
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
Fio(ctx, output, storageClass, fioCheckerSize, namespace, fioCheckerTestName, fioCheckerFilePath)
Fio(ctx, output, storageClass, fioCheckerSize, namespace, fioCheckerTestName, fioCheckerFilePath, containerImage)
},
}
csiCheckVolumeSnapshotClass string
csiCheckRunAsUser int64
csiCheckContainerImage string
csiCheckCleanup bool
csiCheckSkipCFSCheck bool
csiCheckCmd = &cobra.Command{
@ -71,7 +71,7 @@ var (
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
CSICheck(ctx, output, namespace, storageClass, csiCheckVolumeSnapshotClass, csiCheckRunAsUser, csiCheckContainerImage, csiCheckCleanup, csiCheckSkipCFSCheck)
CSICheck(ctx, output, namespace, storageClass, csiCheckVolumeSnapshotClass, csiCheckRunAsUser, containerImage, csiCheckCleanup, csiCheckSkipCFSCheck)
},
}
)
@ -86,6 +86,7 @@ func init() {
fioCmd.Flags().StringVarP(&namespace, "namespace", "n", fio.DefaultNS, "The namespace used to run FIO.")
fioCmd.Flags().StringVarP(&fioCheckerFilePath, "fiofile", "f", "", "The path to a an fio config file.")
fioCmd.Flags().StringVarP(&fioCheckerTestName, "testname", "t", "", "The Name of a predefined kubestr fio test. Options(default-fio)")
fioCmd.Flags().StringVarP(&containerImage, "image", "i", "", "The container image used to create a pod.")
rootCmd.AddCommand(csiCheckCmd)
csiCheckCmd.Flags().StringVarP(&storageClass, "storageclass", "s", "", "The name of a Storageclass. (Required)")
@ -93,7 +94,7 @@ func init() {
csiCheckCmd.Flags().StringVarP(&csiCheckVolumeSnapshotClass, "volumesnapshotclass", "v", "", "The name of a VolumeSnapshotClass. (Required)")
_ = csiCheckCmd.MarkFlagRequired("volumesnapshotclass")
csiCheckCmd.Flags().StringVarP(&namespace, "namespace", "n", fio.DefaultNS, "The namespace used to run the check.")
csiCheckCmd.Flags().StringVarP(&csiCheckContainerImage, "image", "i", "", "The container image used to create a pod.")
csiCheckCmd.Flags().StringVarP(&containerImage, "image", "i", "", "The container image used to create a pod.")
csiCheckCmd.Flags().BoolVarP(&csiCheckCleanup, "cleanup", "c", true, "Clean up the objects created by tool")
csiCheckCmd.Flags().Int64VarP(&csiCheckRunAsUser, "runAsUser", "u", 0, "Runs the CSI check using pods as a user (int)")
csiCheckCmd.Flags().BoolVarP(&csiCheckSkipCFSCheck, "skipCFScheck", "k", false, "Use this flag to skip validating the ability to clone a snapshot.")
@ -145,7 +146,7 @@ func Baseline(ctx context.Context, output string) {
}
// Fio executes the FIO test.
func Fio(ctx context.Context, output, storageclass, size, namespace, jobName, fioFilePath string) {
func Fio(ctx context.Context, output, storageclass, size, namespace, jobName, fioFilePath string, containerImage string) {
cli, err := kubestr.LoadKubeCli()
if err != nil {
fmt.Println(err.Error())
@ -162,6 +163,7 @@ func Fio(ctx context.Context, output, storageclass, size, namespace, jobName, fi
Namespace: namespace,
FIOJobName: jobName,
FIOJobFilepath: fioFilePath,
Image: containerImage,
}); err != nil {
result = kubestr.MakeTestOutput(testName, kubestr.StatusError, err.Error(), fioResult)
} else {

View file

@ -42,6 +42,7 @@ const (
VolumeMountPath = "/dataset"
// CreatedByFIOLabel is the key that desrcibes the label used to mark configmaps
CreatedByFIOLabel = "createdbyfio"
DefaultPodImage = "ghcr.io/kastenhq/kubestr:latest"
)
// FIO is an interface that represents FIO related commands
@ -61,6 +62,7 @@ type RunFIOArgs struct {
Namespace string
FIOJobFilepath string
FIOJobName string
Image string
}
func (a *RunFIOArgs) Validate() error {
@ -128,7 +130,7 @@ func (f *FIOrunner) RunFioHelper(ctx context.Context, args *RunFIOArgs) (*RunFIO
}()
fmt.Println("PVC created", pvc.Name)
pod, err := f.fioSteps.createPod(ctx, pvc.Name, configMap.Name, testFileName, args.Namespace)
pod, err := f.fioSteps.createPod(ctx, pvc.Name, configMap.Name, testFileName, args.Namespace, args.Image)
defer func() {
_ = f.fioSteps.deletePod(context.TODO(), pod.Name, args.Namespace)
}()
@ -156,7 +158,7 @@ type fioSteps interface {
loadConfigMap(ctx context.Context, args *RunFIOArgs) (*v1.ConfigMap, error)
createPVC(ctx context.Context, storageclass, size, namespace string) (*v1.PersistentVolumeClaim, error)
deletePVC(ctx context.Context, pvcName, namespace string) error
createPod(ctx context.Context, pvcName, configMapName, testFileName, namespace string) (*v1.Pod, error)
createPod(ctx context.Context, pvcName, configMapName, testFileName, namespace string, image string) (*v1.Pod, error)
deletePod(ctx context.Context, podName, namespace string) error
runFIOCommand(ctx context.Context, podName, containerName, testFileName, namespace string) (string, error)
deleteConfigMap(ctx context.Context, configMap *v1.ConfigMap, namespace string) error
@ -230,10 +232,15 @@ func (s *fioStepper) deletePVC(ctx context.Context, pvcName, namespace string) e
return s.cli.CoreV1().PersistentVolumeClaims(namespace).Delete(ctx, pvcName, metav1.DeleteOptions{})
}
func (s *fioStepper) createPod(ctx context.Context, pvcName, configMapName, testFileName, namespace string) (*v1.Pod, error) {
func (s *fioStepper) createPod(ctx context.Context, pvcName, configMapName, testFileName, namespace string, image string) (*v1.Pod, error) {
if pvcName == "" || configMapName == "" || testFileName == "" {
return nil, fmt.Errorf("Create pod missing required arguments.")
}
if image == "" {
image = DefaultPodImage
}
pod := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: PodGenerateName,
@ -248,7 +255,7 @@ func (s *fioStepper) createPod(ctx context.Context, pvcName, configMapName, test
{Name: "persistent-storage", MountPath: VolumeMountPath},
{Name: "config-map", MountPath: ConfigMapMountPath},
},
Image: "ghcr.io/kastenhq/kubestr:latest",
Image: image,
}},
Volumes: []v1.Volume{
{

View file

@ -320,7 +320,7 @@ func (f *fakeFioStepper) deletePVC(ctx context.Context, pvcName, namespace strin
f.steps = append(f.steps, "DPVC")
return f.dPVCErr
}
func (f *fakeFioStepper) createPod(ctx context.Context, pvcName, configMapName, testFileName, namespace string) (*v1.Pod, error) {
func (f *fakeFioStepper) createPod(ctx context.Context, pvcName, configMapName, testFileName, namespace string, image string) (*v1.Pod, error) {
f.steps = append(f.steps, "CPOD")
f.cPodExpCM = configMapName
f.cPodExpFN = testFileName
@ -528,6 +528,7 @@ func (s *FIOTestSuite) TestCreatPod(c *C) {
pvcName string
configMapName string
testFileName string
image string
reactor []k8stesting.Reactor
podReadyErr error
errChecker Checker
@ -595,6 +596,7 @@ func (s *FIOTestSuite) TestCreatPod(c *C) {
pvcName: "pvc",
configMapName: "cm",
testFileName: "",
image: "someotherimage",
errChecker: NotNil,
},
{
@ -617,7 +619,7 @@ func (s *FIOTestSuite) TestCreatPod(c *C) {
if tc.reactor != nil {
stepper.cli.(*fake.Clientset).Fake.ReactionChain = tc.reactor
}
pod, err := stepper.createPod(ctx, tc.pvcName, tc.configMapName, tc.testFileName, DefaultNS)
pod, err := stepper.createPod(ctx, tc.pvcName, tc.configMapName, tc.testFileName, DefaultNS, tc.image)
c.Check(err, tc.errChecker)
if err == nil {
c.Assert(pod.GenerateName, Equals, PodGenerateName)
@ -638,6 +640,11 @@ func (s *FIOTestSuite) TestCreatPod(c *C) {
{Name: "persistent-storage", MountPath: VolumeMountPath},
{Name: "config-map", MountPath: ConfigMapMountPath},
})
if tc.image == "" {
c.Assert(pod.Spec.Containers[0].Image, Equals, DefaultPodImage)
} else {
c.Assert(pod.Spec.Containers[0].Image, Equals, tc.image)
}
}
}
}