Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed Sep 9, 2024
1 parent 23d9cde commit 115dfeb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/controller/mastodonserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ func (r *MastodonServerReconciler) createMigrationJob(
env := []corev1.EnvVar{}
switch kind {
case jobPreMigration:
case jobPostMigration:
env = append(env, corev1.EnvVar{
Name: "SKIP_POST_DEPLOYMENT_MIGRATIONS", Value: "true",
})
case jobPostMigration:
default:
return errors.New("invalid job kind")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/mastodonserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ var _ = Describe("MastodonServer Controller", func() {
}, &job)
Expect(err).NotTo(HaveOccurred())
Expect(job.Spec.Template.Spec.Containers[0].Image).To(Equal(webImage))
Expect(job.Spec.Template.Spec.Containers[0].Env[0].Name).To(Equal("SKIP_POST_DEPLOYMENT_MIGRATIONS"))
Expect(job.Spec.Template.Spec.Containers[0].Env[0].Value).To(Equal("true"))
Expect(job.Spec.Template.Spec.Containers[0].Env).To(BeNil())

By("Making the post migration job completed")
job.Status.Succeeded = 1
Expand Down Expand Up @@ -211,7 +210,8 @@ var _ = Describe("MastodonServer Controller", func() {
}, &job)
Expect(err).NotTo(HaveOccurred())
Expect(job.Spec.Template.Spec.Containers[0].Image).To(Equal(webImage2))
Expect(job.Spec.Template.Spec.Containers[0].Env).To(BeNil())
Expect(job.Spec.Template.Spec.Containers[0].Env[0].Name).To(Equal("SKIP_POST_DEPLOYMENT_MIGRATIONS"))
Expect(job.Spec.Template.Spec.Containers[0].Env[0].Value).To(Equal("true"))

By("Making the pre migration job completed")
job.Status.Succeeded = 1
Expand Down
29 changes: 29 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log/slog"
"os"
"os/exec"
"strconv"
"strings"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -95,6 +96,31 @@ func checkMastodonVersion(host, endpoint, expected string) error {
return nil
}

func checkSchemaMigrationsCount(namespace string, expected int) error {
stdout, _, err := kubectl(nil, "exec", "-n", namespace, "postgres-0", "--",
"psql", "-U", "mastodon", "mastodon_production", "-c",
"SELECT COUNT(version) FROM schema_migrations;")
if err != nil {
return err
}

result := strings.Split(string(stdout), "\n")
if len(result) <= 2 {
return errors.New("invalid output of psql")
}

count, err := strconv.Atoi(strings.TrimSpace(result[2]))
if err != nil {
return errors.New("failed to parse the result")
}

if count != expected {
return errors.New("count not expected")
}

return nil
}

var _ = Describe("controller", Ordered, func() {
Context("Operator", func() {
It("should run successfully", func() {
Expand Down Expand Up @@ -127,6 +153,9 @@ var _ = Describe("controller", Ordered, func() {
"http://mastodon0-gateway.e2e.svc", "4.2.12"); err != nil {
return err
}
if err := checkSchemaMigrationsCount(namespace, 422); err != nil {
return err
}
return nil
}).Should(Succeed())
})
Expand Down

0 comments on commit 115dfeb

Please sign in to comment.