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 054e513 commit 23d9cde
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 10 deletions.
27 changes: 27 additions & 0 deletions charts/magout-mastodon-server/templates/gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ spec:
app.kubernetes.io/component: gateway
app.kubernetes.io/part-of: mastodon
spec:
initContainers:
- name: copy-assets
image: {{ .Values.mastodonVersion.image }}
command:
- bash
- -c
- |
cp -ra /opt/mastodon/public/* /mnt/public/
volumeMounts:
- name: mnt-public
mountPath: /mnt/public
containers:
- name: nginx
image: "{{ .Values.gateway.deploy.image }}"
Expand All @@ -25,6 +36,22 @@ spec:
protocol: TCP
resources:
{{- toYaml .Values.gateway.deploy.resources | nindent 12 }}
volumeMounts:
- name: mnt-public
mountPath: /mnt/public
readyOnly: true
- name: nginx-conf
mountPath: /etc/nginx/conf.d
readyOnly: true
volumes:
- name: mnt-public
emptyDir: {}
- name: nginx-conf
configMap:
name: {{ include "magout-mastodon-server.fullname" . }}-gateway-nginx-conf
items:
- key: nginx.conf
path: mastodon.conf
---
apiVersion: v1
kind: Service
Expand Down
6 changes: 3 additions & 3 deletions charts/magout-mastodon-server/templates/mastodonserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: {{ .Release.Namespace }}
spec:
sidekiq:
image: {{ .Values.mastodonServer.sidekiq.image }}
image: {{ .Values.mastodonVersion.image }}
{{- with .Values.mastodonServer.sidekiq.replicas }}
replicas: {{ . }}
{{- end }}
Expand All @@ -26,7 +26,7 @@ spec:
{{- toYaml . | nindent 6 }}
{{- end }}
web:
image: {{ .Values.mastodonServer.web.image }}
image: {{ .Values.mastodonVersion.image }}
{{- with .Values.mastodonServer.web.replicas }}
replicas: {{ . }}
{{- end }}
Expand All @@ -47,7 +47,7 @@ spec:
{{- toYaml . | nindent 6 }}
{{- end }}
streaming:
image: {{ .Values.mastodonServer.streaming.image }}
image: {{ .Values.mastodonVersion.streamingImage }}
{{- with .Values.mastodonServer.streaming.replicas }}
replicas: {{ . }}
{{- end }}
Expand Down
9 changes: 6 additions & 3 deletions charts/magout-mastodon-server/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#fullnameOverride: ""

mastodonVersion:
#image: ghcr.io/mastodon/mastodon:latest
#streamingImage: ghcr.io/mastodon/mastodon-streaming:latest

gateway:
#serverName: "example.com"
deploy:
Expand All @@ -10,22 +16,19 @@ gateway:

mastodonServer:
sidekiq:
#image: ghcr.io/mastodon/mastodon:latest
#replicas: 1
#labels: {}
#annotations: {}
#envFrom: {}
#resources: {}
web:
#replicas: 1
#image: ghcr.io/mastodon/mastodon:latest
#labels: {}
#annotations: {}
#envFrom: {}
#resources: {}
streaming:
#replicas: 1
#image: ghcr.io/mastodon/mastodon:latest
#labels: {}
#annotations: {}
#envFrom: {}
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e_test
import (
"fmt"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -11,6 +12,10 @@ import (
// Run e2e tests using the Ginkgo runner.
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)

SetDefaultEventuallyTimeout(100 * time.Second)
SetDefaultEventuallyPollingInterval(1 * time.Second)

_, _ = fmt.Fprintf(GinkgoWriter, "Starting magout suite\n")
RunSpecs(t, "e2e suite")
}
69 changes: 68 additions & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package e2e_test

import (
"bytes"
"encoding/json"
"errors"
"log/slog"
"os"
"os/exec"
Expand Down Expand Up @@ -53,15 +55,80 @@ func helm(input []byte, args ...string) ([]byte, []byte, error) {
return command(input, fields...)
}

func waitCondition(kind, name, namespace, condition string) error {
_, _, err := kubectl(nil, "wait", "-n", namespace,
"--for=condition="+condition, "--timeout=1s", kind, name)
return err
}

func waitDeployAvailable(name, namespace string) error {
return waitCondition("deployment", name, namespace, "Available")
}

func httpGet(uri string) error {
_, _, err := kubectl(nil, "exec", "deploy/toolbox", "--",
"curl", "--silent", uri)
return err
}

func checkMastodonVersion(host, endpoint, expected string) error {
stdout, _, err := kubectl(nil, "exec", "deploy/toolbox", "--",
"curl", "--silent", "-H", "Host: "+host, endpoint+"/api/v1/instance")
if err != nil {
return err
}

result := map[string]any{}
if err := json.Unmarshal(stdout, &result); err != nil {
return err
}

version, ok := result["version"]
if !ok {
return errors.New("version not found in the result")
}

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

return nil
}

var _ = Describe("controller", Ordered, func() {
Context("Operator", func() {
It("should run successfully", func() {
var err error

_, _, err = helm(nil, "upgrade", "--install", "--namespace=e2e",
namespace := "e2e"

_, _, err = helm(nil, "upgrade", "--install", "--namespace", namespace,
"magout-mastodon-server", "../../charts/magout-mastodon-server", "--wait",
"-f", "testdata/values-v4.2.12.yaml")
Expect(err).NotTo(HaveOccurred())

Eventually(func() error {
if err := waitDeployAvailable("mastodon0-web", namespace); err != nil {
return err
}
if err := waitDeployAvailable("mastodon0-sidekiq", namespace); err != nil {
return err
}
if err := waitDeployAvailable("mastodon0-streaming", namespace); err != nil {
return err
}
if err := waitDeployAvailable("mastodon0-gateway", namespace); err != nil {
return err
}
if err := httpGet("http://mastodon0-gateway.e2e.svc/health"); err != nil {
return err
}
if err := checkMastodonVersion("mastodon.test",
"http://mastodon0-gateway.e2e.svc", "4.2.12"); err != nil {
return err
}
return nil
}).Should(Succeed())
})
})
})
9 changes: 6 additions & 3 deletions test/e2e/testdata/values-v4.2.12.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
fullnameOverride: "mastodon0"

mastodonVersion:
image: ghcr.io/mastodon/mastodon:v4.2.12
streamingImage: ghcr.io/mastodon/mastodon:v4.2.12

gateway:
serverName: mastodon.test

mastodonServer:
sidekiq:
image: ghcr.io/mastodon/mastodon:v4.2.12
envFrom:
- secretRef:
name: secret-env
streaming:
image: ghcr.io/mastodon/mastodon:v4.2.12
annotations:
test.mahout.anqou.net/role: streaming
envFrom:
- secretRef:
name: secret-env
web:
image: ghcr.io/mastodon/mastodon:v4.2.12
envFrom:
- secretRef:
name: secret-env
Expand Down

0 comments on commit 23d9cde

Please sign in to comment.