minio_suite_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package minio_test
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "testing"
  7. "time"
  8. . "github.com/onsi/ginkgo/v2"
  9. . "github.com/onsi/gomega"
  10. batchv1 "k8s.io/api/batch/v1"
  11. v1 "k8s.io/api/core/v1"
  12. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  13. "k8s.io/client-go/kubernetes"
  14. )
  15. var (
  16. kubeconfig string
  17. deployName string
  18. namespace string
  19. username string
  20. password string
  21. timeoutSeconds int
  22. timeout time.Duration
  23. )
  24. func init() {
  25. flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
  26. flag.StringVar(&deployName, "name", "", "name of the primary statefulset")
  27. flag.StringVar(&namespace, "namespace", "", "namespace where the application is running")
  28. flag.StringVar(&username, "username", "", "database user")
  29. flag.StringVar(&password, "password", "", "database password for username")
  30. flag.IntVar(&timeoutSeconds, "timeout", 120, "timeout in seconds")
  31. timeout = time.Duration(timeoutSeconds) * time.Second
  32. }
  33. func TestMinio(t *testing.T) {
  34. RegisterFailHandler(Fail)
  35. RunSpecs(t, "Minio Persistence Test Suite")
  36. }
  37. func createJob(ctx context.Context, c kubernetes.Interface, name, port, image, stmt string) error {
  38. securityContext := &v1.SecurityContext{
  39. Privileged: &[]bool{false}[0],
  40. AllowPrivilegeEscalation: &[]bool{false}[0],
  41. RunAsNonRoot: &[]bool{true}[0],
  42. Capabilities: &v1.Capabilities{
  43. Drop: []v1.Capability{"ALL"},
  44. },
  45. SeccompProfile: &v1.SeccompProfile{
  46. Type: "RuntimeDefault",
  47. },
  48. }
  49. job := &batchv1.Job{
  50. ObjectMeta: metav1.ObjectMeta{
  51. Name: name,
  52. },
  53. TypeMeta: metav1.TypeMeta{
  54. Kind: "Job",
  55. },
  56. Spec: batchv1.JobSpec{
  57. Template: v1.PodTemplateSpec{
  58. Spec: v1.PodSpec{
  59. RestartPolicy: "Never",
  60. Containers: []v1.Container{
  61. {
  62. Name: "minio",
  63. Image: image,
  64. Command: []string{"bash", "-ec", fmt.Sprintf(
  65. "mc alias set miniotest http://$MINIO_HOST:$MINIO_PORT $MINIO_USERNAME $MINIO_PASSWORD\n%s", stmt)},
  66. Env: []v1.EnvVar{
  67. {
  68. Name: "MINIO_PASSWORD",
  69. Value: password,
  70. },
  71. {
  72. Name: "MINIO_USERNAME",
  73. Value: username,
  74. },
  75. {
  76. Name: "MINIO_HOST",
  77. Value: deployName,
  78. },
  79. {
  80. Name: "MINIO_PORT",
  81. Value: port,
  82. },
  83. },
  84. SecurityContext: securityContext,
  85. },
  86. },
  87. },
  88. },
  89. },
  90. }
  91. _, err := c.BatchV1().Jobs(namespace).Create(ctx, job, metav1.CreateOptions{})
  92. return err
  93. }