Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions e2e/volumestatefulset/volumestatefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ func TestVolumeStatefulSet(t *testing.T) {
runtimeHandler, err := manifest.RuntimeHandler(platform)
require.NoError(t, err)

// We have two resource sets for testing volumes: VolumeStatefulSet and MySQL. The former is
// designed for testing, while the latter is a demo artifact we include in releases. The
// functional tests below mostly use the VolumeStatefulSet, but we include MySQL and some basic
// checks as a smoke test.
resources := kuberesource.VolumeStatefulSet()
resources = append(resources, kuberesource.MySQL()...)

coordinator := kuberesource.CoordinatorBundle()

Expand Down Expand Up @@ -95,6 +100,32 @@ func TestVolumeStatefulSet(t *testing.T) {
require.NoError(err, "stdout: %s, stderr: %s", stdOut, stdErr)
require.Equal("test\n", stdOut)
})

t.Run("MySQL demo works", func(t *testing.T) {
const (
mysqlBackend = "mysql-backend"
mysqlClient = "mysql-client"
)

require := require.New(t)

// The MySQL server runs initialization on first boot if the volume is empty, which takes
// a considerable amount of time. Combined with a medium sized image and docker hubs slow
// pull bandwidth, it can take quite some time until the server comes up.
ctx, cancel := context.WithTimeout(t.Context(), ct.FactorPlatformTimeout(5*time.Minute))
defer cancel()

require.NoError(ct.Kubeclient.WaitForStatefulSet(ctx, ct.Namespace, mysqlBackend))
require.NoError(ct.Kubeclient.WaitForDeployment(ctx, ct.Namespace, mysqlClient))

pods, err := ct.Kubeclient.PodsFromDeployment(ctx, ct.Namespace, mysqlClient)
require.NoError(err)
require.Len(pods, 1)
command := []string{"/bin/sh", "-c", `mysql -h 127.137.0.1 -u root -D my_db -e "SELECT * FROM my_table;"`}
stdout, stderr, err := ct.Kubeclient.ExecRetry(ctx, ct.Namespace, pods[0].Name, mysqlClient, command, time.Second)
require.NoErrorf(err, "mysql command failed - stderr:\n%s", stderr)
require.Contains(stdout, "uuid")
})
}

func TestMain(m *testing.M) {
Expand Down
39 changes: 35 additions & 4 deletions internal/kuberesource/sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func MySQL() []any {
WithContainers(
Container().
WithName("mysql-backend").
WithImage("docker.io/library/mysql:9.1.0@sha256:0255b469f0135a0236d672d60e3154ae2f4538b146744966d96440318cc822c6").
WithImage("docker.io/library/mysql:9.7.1@sha256:ad88e1c86cbf12ef52d0a0360cd4b774d22956c5ee9c565645fb019d7aacb6c3").
WithEnv(NewEnvVar("MYSQL_ALLOW_EMPTY_PASSWORD", "1")).
WithPorts(
ContainerPort().
Expand All @@ -728,7 +728,17 @@ func MySQL() []any {
).
WithResources(
ResourceRequirements().
WithMemoryLimitAndRequest(2000),
WithMemoryLimitAndRequest(3000),
).
WithReadinessProbe(
applycorev1.Probe().
WithExec(
applycorev1.ExecAction().WithCommand(
"sh", "-c", "mysqladmin ping -h 127.0.0.1 -u root --silent",
),
).
WithInitialDelaySeconds(5).
WithPeriodSeconds(5),
),
).
WithVolumes(
Expand Down Expand Up @@ -764,6 +774,7 @@ mysql -h 127.137.0.1 -u root -D my_db -e "CREATE TABLE my_table (id INT NOT NULL
while true; do
mysql -h 127.137.0.1 -u root -D my_db -e "INSERT INTO my_table (uuid) VALUES (UUID());"
mysql -h 127.137.0.1 -u root -D my_db -e "SELECT * FROM my_table;"
touch /done
sleep 5;
done
`
Expand All @@ -785,13 +796,33 @@ done
WithContainers(
Container().
WithName("mysql-client").
WithImage("docker.io/library/mysql:9.1.0@sha256:0255b469f0135a0236d672d60e3154ae2f4538b146744966d96440318cc822c6").
WithImage("docker.io/library/mysql:9.7.1@sha256:ad88e1c86cbf12ef52d0a0360cd4b774d22956c5ee9c565645fb019d7aacb6c3").
WithEnv(NewEnvVar("MYSQL_ALLOW_EMPTY_PASSWORD", "1")).
WithCommand("/bin/sh", "-c", clientCmd).
WithResources(
ResourceRequirements().
WithMemoryLimitAndRequest(2000),
WithMemoryLimitAndRequest(3000),
).
WithVolumeMounts(
VolumeMount().
WithName("dummy").
WithMountPath("/var/lib/mysql"),
).
WithReadinessProbe(
applycorev1.Probe().
WithExec(
applycorev1.ExecAction().WithCommand(
"sh", "-c", "test -f /done",
),
).
WithInitialDelaySeconds(5).
WithPeriodSeconds(5),
),
).
WithVolumes(
applycorev1.Volume().
WithName("dummy").
WithEmptyDir(applycorev1.EmptyDirVolumeSource().WithMedium(corev1.StorageMediumMemory)),
),
),
),
Expand Down
Loading