From db7be29d6ca0bd75495ff9a42b2fad06212e012a Mon Sep 17 00:00:00 2001 From: rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Thu, 19 Oct 2023 16:53:55 +0800 Subject: [PATCH] feat: add pvc setting into the helm chart --- Dockerfile | 11 +++++------ Makefile | 2 +- console/atest-ui/src/views/TestSuite.vue | 12 ++++++++---- helm/api-testing/Chart.yaml | 2 +- helm/api-testing/templates/deployment.yaml | 21 +++++++++++++++++++++ helm/api-testing/templates/pvc.yaml | 22 ++++++++++++++++++++++ helm/api-testing/templates/service.yaml | 3 +++ helm/api-testing/values.yaml | 11 +++++++++++ pkg/server/convert.go | 5 +++-- pkg/testing/store.go | 21 ++++++++++++++++++++- pkg/testing/store_test.go | 5 +++-- pkg/testing/testdata/stores.yaml | 7 +++++-- 12 files changed, 103 insertions(+), 19 deletions(-) create mode 100644 helm/api-testing/templates/pvc.yaml diff --git a/Dockerfile b/Dockerfile index 87a7166a..f8537185 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ -FROM node:20-alpine3.17 AS ui +FROM docker.io/library/node:20-alpine3.17 AS ui WORKDIR /workspace COPY console/atest-ui . RUN npm install --ignore-scripts --registry=https://registry.npmmirror.com RUN npm run build-only -FROM apache/skywalking-go:0.2.0-go1.18 AS sk +FROM docker.io/apache/skywalking-go:0.2.0-go1.18 AS sk -FROM golang:1.19 AS builder +FROM docker.io/golang:1.19 AS builder ARG VERSION ARG GOPROXY @@ -42,7 +42,7 @@ RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-or RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-s3 extensions/store-s3/main.go RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-git extensions/store-git/main.go -FROM ubuntu:23.04 +FROM docker.io/library/ubuntu:23.04 LABEL "com.github.actions.name"="API testing" LABEL "com.github.actions.description"="API testing" @@ -63,11 +63,10 @@ COPY --from=builder /workspace/atest-store-git /usr/local/bin/atest-store-git COPY --from=builder /workspace/LICENSE /LICENSE COPY --from=builder /workspace/README.md /README.md -RUN mkdir -p /var/www/data COPY --from=builder /workspace/sample /var/www/sample RUN apt update -y && \ # required for atest-store-git apt install -y --no-install-recommends ssh-client ca-certificates -CMD ["atest", "server", "--local-storage=/var/www/sample/*.yaml", "--local-storage=/var/www/data/*.yaml"] +CMD ["atest", "server", "--local-storage=/var/www/sample/*.yaml"] diff --git a/Makefile b/Makefile index c9e8f2d1..43bac5c8 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ IMG_TOOL?=podman BINARY?=atest TOOLEXEC?=-toolexec="skywalking-go-agent" GOPROXY?=https://goproxy.cn,direct -HELM_VERSION?=v0.0.1 +HELM_VERSION?=v0.0.2 APP_VERSION?=v0.0.13 build: diff --git a/console/atest-ui/src/views/TestSuite.vue b/console/atest-ui/src/views/TestSuite.vue index f1d52528..514c9f47 100644 --- a/console/atest-ui/src/views/TestSuite.vue +++ b/console/atest-ui/src/views/TestSuite.vue @@ -68,10 +68,14 @@ function save() { fetch('/server.Runner/UpdateTestSuite', requestOptions) .then((response) => response.json()) .then((e) => { - ElMessage({ - message: 'Updated.', - type: 'success' - }) + if (e.error === "") { + ElMessage({ + message: 'Updated.', + type: 'success' + }) + } else { + ElMessage.error('Oops, ' + e.message) + } }) .catch((e) => { ElMessage.error('Oops, ' + e) diff --git a/helm/api-testing/Chart.yaml b/helm/api-testing/Chart.yaml index 4f11de26..fffd0905 100644 --- a/helm/api-testing/Chart.yaml +++ b/helm/api-testing/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: v0.0.1 +version: v0.0.2 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/helm/api-testing/templates/deployment.yaml b/helm/api-testing/templates/deployment.yaml index 89f50820..52aec79b 100644 --- a/helm/api-testing/templates/deployment.yaml +++ b/helm/api-testing/templates/deployment.yaml @@ -1,3 +1,4 @@ +{{- $core := .Values.persistence.persistentVolumeClaim.core -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -45,6 +46,13 @@ spec: httpGet: path: / port: http + volumeMounts: + - name: data + mountPath: /var/www/sample + subPath: {{ $core.subPath }} + - name: data + mountPath: /root + subPath: config resources: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.nodeSelector }} @@ -59,3 +67,16 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + volumes: + {{- if not .Values.persistence.enabled }} + - name: "data" + emptyDir: {} + {{- else if $core.existingClaim }} + - name: "data" + persistentVolumeClaim: + claimName: {{ $core.existingClaim }} + {{- else }} + - name: "data" + persistentVolumeClaim: + claimName: {{ include "api-testing.fullname" . }} + {{- end -}} diff --git a/helm/api-testing/templates/pvc.yaml b/helm/api-testing/templates/pvc.yaml new file mode 100644 index 00000000..2514de20 --- /dev/null +++ b/helm/api-testing/templates/pvc.yaml @@ -0,0 +1,22 @@ +{{- $core := .Values.persistence.persistentVolumeClaim.core -}} +{{- if and .Values.persistence.enabled (not $core.existingClaim) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "api-testing.fullname" . }} + labels: + {{- include "api-testing.labels" . | nindent 4 }} +spec: + accessModes: + - {{ $core.accessMode }} + resources: + requests: + storage: {{ $core.size }} + {{- if $core.storageClass }} + {{- if eq "-" $core.storageClass }} + storageClassName: "" + {{- else }} + storageClassName: {{ $core.storageClass }} + {{- end }} + {{- end }} +{{- end }} diff --git a/helm/api-testing/templates/service.yaml b/helm/api-testing/templates/service.yaml index 1473d402..1a2d5beb 100644 --- a/helm/api-testing/templates/service.yaml +++ b/helm/api-testing/templates/service.yaml @@ -11,5 +11,8 @@ spec: targetPort: http protocol: TCP name: http + {{- if and .Values.service.nodePort }} + nodePort: {{ .Values.service.nodePort }} + {{- end}} selector: {{- include "api-testing.selectorLabels" . | nindent 4 }} diff --git a/helm/api-testing/values.yaml b/helm/api-testing/values.yaml index a4c900e8..1c1719ba 100644 --- a/helm/api-testing/values.yaml +++ b/helm/api-testing/values.yaml @@ -39,6 +39,7 @@ securityContext: {} service: type: ClusterIP port: 8080 + nodePort: "" ingress: enabled: false @@ -75,6 +76,16 @@ autoscaling: targetCPUUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80 +persistence: + enabled: true + persistentVolumeClaim: + core: + existingClaim: "" + storageClass: "" + subPath: "" + accessMode: ReadWriteMany + size: 500Mi + nodeSelector: {} tolerations: [] diff --git a/pkg/server/convert.go b/pkg/server/convert.go index 1f5c96ab..2f32a796 100644 --- a/pkg/server/convert.go +++ b/pkg/server/convert.go @@ -31,8 +31,9 @@ func ToGRPCStore(store testing.Store) (result *Store) { result = &Store{ Name: store.Name, Kind: &StoreKind{ - Name: store.Kind.Name, - Url: store.Kind.URL, + Name: store.Kind.Name, + Url: store.Kind.URL, + Enabled: store.Kind.Enabled, }, Description: store.Description, Url: store.URL, diff --git a/pkg/testing/store.go b/pkg/testing/store.go index 371a4f08..21d99d80 100644 --- a/pkg/testing/store.go +++ b/pkg/testing/store.go @@ -199,7 +199,26 @@ func (s *storeFactory) CreateStore(store Store) (err error) { } func (s *storeFactory) save(storeConfig *StoreConfig) (err error) { - if err = os.MkdirAll(s.configDir, 0755);err==nil{ + for i, item := range storeConfig.Stores { + if item.Kind.Name != "" { + storeConfig.Stores[i].Kind.Enabled = true + + foundPlugin := false + for j, kind := range storeConfig.Plugins { + if kind.Name == item.Kind.Name { + foundPlugin = true + storeConfig.Plugins[j].Enabled = true + break + } + } + + if !foundPlugin { + storeConfig.Plugins = append(storeConfig.Plugins, storeConfig.Stores[i].Kind) + } + } + } + + if err = os.MkdirAll(s.configDir, 0755); err == nil { var data []byte if data, err = yaml.Marshal(storeConfig); err == nil { err = os.WriteFile(path.Join(s.configDir, "stores.yaml"), data, 0644) diff --git a/pkg/testing/store_test.go b/pkg/testing/store_test.go index b3fa5f51..2612a973 100644 --- a/pkg/testing/store_test.go +++ b/pkg/testing/store_test.go @@ -62,8 +62,9 @@ func TestStoreFactory(t *testing.T) { assert.Equal(t, &Store{ Name: "db", Kind: StoreKind{ - Name: "database", - URL: "localhost:7071", + Name: "database", + URL: "localhost:7071", + Enabled: true, }, URL: "localhost:4000", Username: "root", diff --git a/pkg/testing/testdata/stores.yaml b/pkg/testing/testdata/stores.yaml index 3e3d03db..b3470612 100644 --- a/pkg/testing/testdata/stores.yaml +++ b/pkg/testing/testdata/stores.yaml @@ -3,11 +3,14 @@ stores: kind: name: database url: localhost:7071 - enabled: false + enabled: true description: "" url: localhost:4000 username: root password: "" properties: database: test -plugins: [] +plugins: + - name: database + url: localhost:7071 + enabled: true