mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
metrics: Add FIO runner k8s
Add program to execute FIO workloads using k8s. Signed-off-by: Gabriela Cervantes <gabriela.cervantes.tellez@intel.com>
This commit is contained in:
parent
8f7ef41c14
commit
ea198fddcc
8
tests/metrics/storage/fio-k8s/pkg/k8s/Makefile
Normal file
8
tests/metrics/storage/fio-k8s/pkg/k8s/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
#
|
||||
# Copyright (c) 2021 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
gomod:
|
||||
GO111MODULE=on go mod edit -replace=github.com/kata-containers/tests/metrics/exec=../exec
|
||||
GO111MODULE=on go mod tidy
|
35
tests/metrics/storage/fio-k8s/pkg/k8s/exec.go
Normal file
35
tests/metrics/storage/fio-k8s/pkg/k8s/exec.go
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2021 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
exec "github.com/kata-containers/tests/metrics/exec"
|
||||
)
|
||||
|
||||
type execOpt struct {
|
||||
showInStdOut bool
|
||||
}
|
||||
|
||||
type ExecOption func(e *execOpt)
|
||||
|
||||
func ExecOptShowStdOut() ExecOption {
|
||||
return func(e *execOpt) {
|
||||
e.showInStdOut = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (p *Pod) Exec(cmd string, opts ...ExecOption) (output string, err error) {
|
||||
log.Debugf("Exec %q in %s", cmd, p.YamlPath)
|
||||
o := &execOpt{showInStdOut: false}
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
|
||||
}
|
||||
execCmd := fmt.Sprintf("kubectl exec -f %s -- /bin/bash -c %q", p.YamlPath, cmd)
|
||||
return exec.ExecCmd(execCmd, Debug || o.showInStdOut)
|
||||
}
|
69
tests/metrics/storage/fio-k8s/pkg/k8s/k8s.go
Normal file
69
tests/metrics/storage/fio-k8s/pkg/k8s/k8s.go
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2021 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
exec "github.com/kata-containers/tests/metrics/exec"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//logger interface for pkg
|
||||
var log logger
|
||||
var Debug bool = false
|
||||
|
||||
type logger interface {
|
||||
Infof(string, ...interface{})
|
||||
Debugf(string, ...interface{})
|
||||
Errorf(string, ...interface{})
|
||||
}
|
||||
|
||||
func SetLogger(l logger) {
|
||||
log = l
|
||||
}
|
||||
|
||||
type Pod struct {
|
||||
YamlPath string
|
||||
}
|
||||
|
||||
func (p *Pod) waitForReady() (err error) {
|
||||
log.Debugf("Wait for pod %s", p.YamlPath)
|
||||
_, err = exec.ExecCmd("kubectl wait --for=condition=ready -f "+p.YamlPath, Debug)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Pod) Run() (err error) {
|
||||
|
||||
log.Debugf("Creating K8s Pod %s", p.YamlPath)
|
||||
_, err = exec.ExecCmd("kubectl apply -f "+p.YamlPath, Debug)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Failed to run pod %s", p.YamlPath)
|
||||
}
|
||||
|
||||
err = p.waitForReady()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Failed to wait for pod %s", p.YamlPath)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Pod) Delete() (err error) {
|
||||
log.Debugf("Delete pod %s", p.YamlPath)
|
||||
_, err = exec.ExecCmd("kubectl delete --ignore-not-found -f "+p.YamlPath, Debug)
|
||||
return errors.Wrapf(err, "Failed to delete pod %s", p.YamlPath)
|
||||
}
|
||||
|
||||
func (p *Pod) CopyFromHost(src, dst string) (err error) {
|
||||
podName, err := exec.ExecCmd("kubectl get -f "+p.YamlPath+" -o jsonpath={.metadata.name}", Debug)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debugf("Copy from host %q->%q in pod %s", src, dst, p.YamlPath)
|
||||
execCmd := fmt.Sprintf("kubectl cp %s %s:%s", src, podName, dst)
|
||||
_, err = exec.ExecCmd(execCmd, Debug)
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user