1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package scylladb_test
- import (
- "context"
- "flag"
- "testing"
- "time"
- . "github.com/onsi/ginkgo/v2"
- . "github.com/onsi/gomega"
- batchv1 "k8s.io/api/batch/v1"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- v1 "k8s.io/api/core/v1"
- "k8s.io/client-go/kubernetes"
- )
- var (
- kubeconfig string
- stsName string
- namespace string
- username string
- password string
- timeoutSeconds int
- timeout time.Duration
- )
- func init() {
- flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
- flag.StringVar(&stsName, "name", "", "name of the statefulset")
- flag.StringVar(&namespace, "namespace", "", "namespace where the application is running")
- flag.StringVar(&username, "username", "", "database user")
- flag.StringVar(&password, "password", "", "database password for username")
- flag.IntVar(&timeoutSeconds, "timeout", 500, "timeout in seconds")
- timeout = time.Duration(timeoutSeconds) * time.Second
- }
- func TestScylladb(t *testing.T) {
- RegisterFailHandler(Fail)
- RunSpecs(t, "Scylladb Persistence Test Suite")
- }
- func createJob(ctx context.Context, c kubernetes.Interface, name, port, image, stmt string) error {
- securityContext := &v1.SecurityContext{
- Privileged: &[]bool{false}[0],
- AllowPrivilegeEscalation: &[]bool{false}[0],
- RunAsNonRoot: &[]bool{true}[0],
- Capabilities: &v1.Capabilities{
- Drop: []v1.Capability{"ALL"},
- },
- SeccompProfile: &v1.SeccompProfile{
- Type: "RuntimeDefault",
- },
- }
- job := &batchv1.Job{
- ObjectMeta: metav1.ObjectMeta{
- Name: name,
- },
- TypeMeta: metav1.TypeMeta{
- Kind: "Job",
- },
- Spec: batchv1.JobSpec{
- Template: v1.PodTemplateSpec{
- Spec: v1.PodSpec{
- RestartPolicy: "Never",
- Containers: []v1.Container{
- {
- Name: "scylladb",
- Image: image,
- Command: []string{"cqlsh", "-u", username, "-p", password, "-e", stmt},
- Env: []v1.EnvVar{
- {
- Name: "CQLSH_HOST",
- Value: stsName,
- },
- {
- Name: "CQLSH_PORT",
- Value: port,
- },
- },
- SecurityContext: securityContext,
- },
- },
- },
- },
- },
- }
- _, err := c.BatchV1().Jobs(namespace).Create(ctx, job, metav1.CreateOptions{})
- return err
- }
|