Skip to content

Commit

Permalink
Add openapi v3 schema for values file
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Apr 23, 2020
1 parent 1c439f2 commit 9e92fe9
Show file tree
Hide file tree
Showing 46 changed files with 33,578 additions and 47 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.14
id: go

- name: Check out code into the Go module directory
Expand All @@ -36,6 +36,15 @@ jobs:
run: |
sudo apt-get -qq update || true
sudo apt-get install -y bzr
# install yq
curl -fsSL -o yq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64
chmod +x yq
sudo mv yq /usr/local/bin/yq
# install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
# run checks
make ci
- name: Build
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ TAG := $(VERSION)_$(OS)_$(ARCH)
TAG_PROD := $(TAG)
TAG_DBG := $(VERSION)-dbg_$(OS)_$(ARCH)

GO_VERSION ?= 1.13.6
GO_VERSION ?= 1.14.2
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)
CHART_TEST_IMAGE ?= quay.io/helmpack/chart-testing:v3.0.0-beta.1
CHART_TEST_IMAGE ?= quay.io/helmpack/chart-testing:v3.0.0-rc.1

OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
ifeq ($(OS),windows)
Expand Down Expand Up @@ -134,8 +134,10 @@ version:
@echo ::set-output name=commit_hash::$(commit_hash)
@echo ::set-output name=commit_timestamp::$(commit_timestamp)

.PHONY: gen
gen:
@true
@yq r vendor/stash.appscode.dev/installer/api/crds/installer.stash.appscode.com_stashmysqls.yaml spec.validation.openAPIV3Schema.properties.spec > /tmp/stash-mysql-values.openapiv3_schema.yaml
@yq d /tmp/stash-mysql-values.openapiv3_schema.yaml description > charts/stash-mysql/values.openapiv3_schema.yaml

fmt: $(BUILD_DIRS)
@docker run \
Expand Down
14 changes: 7 additions & 7 deletions charts/stash-mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ The command removes all the Kubernetes components associated with the chart and

The following table lists the configurable parameters of the `stash-mysql` chart and their default values.

| Parameter | Description | Default |
| :---------------: | -------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------: |
| `docker.registry` | Docker registry used to pull respective images | `stashed` |
| `docker.image` | Docker image used to take backup of MySQL databases and restore them | `stash-mysql` |
| `docker.tag` | Tag of the image that is used to take backup of MySQL databases and restore them. This is usually same as the database version it can take backup. | `8.0.14` |
| `backup.myArgs` | Optional arguments to pass to `mysqldump` command during bakcup process | `--all-databases` |
| `restore.myArgs` | Optional arguments to pass to `mysql` command during restore process | "" |
| Parameter | Description | Default |
| :----------------: | -------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------: |
| `image.registry` | Docker registry used to pull respective images | `stashed` |
| `image.repository` | Docker image used to take backup of MySQL databases and restore them | `stash-mysql` |
| `image.tag` | Tag of the image that is used to take backup of MySQL databases and restore them. This is usually same as the database version it can take backup. | `8.0.14` |
| `backup.args` | Optional arguments to pass to `mysqldump` command during bakcup process | `--all-databases` |
| `restore.args` | Optional arguments to pass to `mysql` command during restore process | "" |

Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.

Expand Down
43 changes: 25 additions & 18 deletions charts/stash-mysql/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,50 @@
Expand the name of the chart.
*/}}
{{- define "stash-mysql.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "stash-mysql.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "stash-mysql.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "stash-mysql.labels" -}}
app.kubernetes.io/name: {{ include "stash-mysql.name" . }}
helm.sh/chart: {{ include "stash-mysql.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{ include "stash-mysql.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "stash-mysql.selectorLabels" -}}
app.kubernetes.io/name: {{ include "stash-mysql.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
4 changes: 2 additions & 2 deletions charts/stash-mysql/templates/mysql-backup-function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
{{- include "stash-mysql.labels" . | nindent 4 }}
spec:
image: {{ .Values.docker.registry }}/{{ .Values.docker.image }}:{{- .Values.docker.tag }}
image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{- .Values.image.tag }}
args:
- backup-mysql
# setup information
Expand All @@ -19,7 +19,7 @@ spec:
- --enable-cache=${ENABLE_CACHE:=true}
- --max-connections=${MAX_CONNECTIONS:=0} # 0 indicates use default connection limit
- --hostname=${HOSTNAME:=}
- --mysql-args=${myArgs:={{ .Values.backup.myArgs }}} # optional arguments pass to mysqldump command
- --mysql-args=${args:={{ .Values.backup.args }}} # optional arguments pass to mysqldump command
# target information
- --namespace=${NAMESPACE:=default}
- --appbinding=${TARGET_NAME:=}
Expand Down
2 changes: 1 addition & 1 deletion charts/stash-mysql/templates/mysql-backup-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
value: /tmp/output
- name: secretVolume
value: secret-volume
# - name: myArgs
# - name: args
# value: "--all-databases"
- name: update-status
params:
Expand Down
4 changes: 2 additions & 2 deletions charts/stash-mysql/templates/mysql-restore-function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
{{- include "stash-mysql.labels" . | nindent 4 }}
spec:
image: {{ .Values.docker.registry }}/{{ .Values.docker.image }}:{{ .Values.docker.tag }}
image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
args:
- restore-mysql
# setup information
Expand All @@ -20,7 +20,7 @@ spec:
- --max-connections=${MAX_CONNECTIONS:=0} # 0 indicates use default connection limit
- --hostname=${HOSTNAME:=}
- --source-hostname=${SOURCE_HOSTNAME:=}
- --mysql-args=${myArgs:={{ .Values.restore.myArgs }}} # optional arguments pass to mysql command
- --mysql-args=${args:={{ .Values.restore.args }}} # optional arguments pass to mysql command
# target information
- --namespace=${NAMESPACE:=default}
- --appbinding=${TARGET_NAME:=}
Expand Down
37 changes: 37 additions & 0 deletions charts/stash-mysql/values.openapiv3_schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
properties:
backup:
properties:
args:
type: string
required:
- args
type: object
fullnameOverride:
type: string
image:
properties:
registry:
type: string
repository:
type: string
tag:
type: string
required:
- registry
- repository
- tag
type: object
nameOverride:
type: string
restore:
properties:
args:
type: string
required:
- args
type: object
required:
- backup
- image
- restore
type: object
14 changes: 8 additions & 6 deletions charts/stash-mysql/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

# we are declaring these values as global so that parent chart can overwrite them
docker:
nameOverride: ""
fullnameOverride: ""

image:
registry: stashed
image: stash-mysql
tag: 8.0.14
repository: stash-mysql
tag: "8.0.14"

# optional argument to send mysqldump or mysql command
backup:
myArgs: "--all-databases"
args: "--all-databases"
restore:
myArgs: ""
args: ""
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ module stash.appscode.dev/mysql
go 1.12

require (
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc
github.com/appscode/go v0.0.0-20200323182826-54e98e09185a
github.com/spf13/cobra v0.0.5
github.com/yudai/gojsondiff v1.0.0
k8s.io/apimachinery v0.16.5-beta.1
k8s.io/client-go v12.0.0+incompatible
kmodules.xyz/client-go v0.0.0-20200216080917-08714f78f885
kmodules.xyz/client-go v0.0.0-20200305091010-36ee6a593ed3
kmodules.xyz/custom-resources v0.0.0-20191130062942-f41b54f62419
kmodules.xyz/offshoot-api v0.0.0-20200216080509-45ee6418d1c1
sigs.k8s.io/yaml v1.1.0
stash.appscode.dev/apimachinery v0.9.0-rc.6
stash.appscode.dev/installer v0.9.0-rc.6.0.20200423190045-ab599e16e362
)

replace (
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/Rican7/retry v0.1.0/go.mod h1:FgOROf8P5bebcC1DS0PdOQiqGUridaZvikzUmkFW6gg=
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc h1:Q5jwbRq/a1Tien+Is8Zn6HMBRgE13+UOQ9mTvrIuvuE=
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE=
github.com/appscode/go v0.0.0-20200323182826-54e98e09185a h1:cZ80NKoLRaW1PVCWXAJE+YFkBAmLZ8BnrJmH0ClY1Gs=
github.com/appscode/go v0.0.0-20200323182826-54e98e09185a/go.mod h1:lIcm8Z6VPuvcw/a3EeOWcG6R3I13iHMLYbtVP7TKufY=
github.com/appscode/osm v0.13.0/go.mod h1:4UxQXV4+RFLd0r6olIFLwsZnCcevBFIzsE88w1+9SOk=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
Expand Down Expand Up @@ -624,8 +626,8 @@ kmodules.xyz/client-go v0.0.0-20191127054604-26981530831d/go.mod h1:OFxuKCiVR+MY
kmodules.xyz/client-go v0.0.0-20191211192817-f1dcd02124ba/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/client-go v0.0.0-20200116162153-e083ae16abca h1:WErv3VRRePgp4oszIHgrFnxIaIHyfP9+930B99B8BBM=
kmodules.xyz/client-go v0.0.0-20200116162153-e083ae16abca/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/client-go v0.0.0-20200216080917-08714f78f885 h1:1v803gTRPSfjMYwW3YXoxs36gQ9YVe/1qWixPfLZ6bM=
kmodules.xyz/client-go v0.0.0-20200216080917-08714f78f885/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/client-go v0.0.0-20200305091010-36ee6a593ed3 h1:Z+CECj6xED/x7OYd1hnQqFDPx9ou0Ixa5K69vqY7S4c=
kmodules.xyz/client-go v0.0.0-20200305091010-36ee6a593ed3/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/constants v0.0.0-20191024095500-cd4313df4aa6/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
kmodules.xyz/crd-schema-fuzz v0.0.0-20191129174258-81f984340891/go.mod h1:9NXNZ4xhqof0WngtIuo4vl+WoCQpLJEJcyuEo3mPpiM=
kmodules.xyz/custom-resources v0.0.0-20191130062942-f41b54f62419 h1:o6KD8XMxdyRR3rqScTsWvcufFDT7vQBnYXpHUp6UtRg=
Expand All @@ -650,4 +652,6 @@ sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
stash.appscode.dev/apimachinery v0.9.0-rc.6 h1:rYp77PiYd05HwAtqbhVJFvmeGRZzcbOOMr6Pmh3zKKw=
stash.appscode.dev/apimachinery v0.9.0-rc.6/go.mod h1:jLzf4kBtDJ1VeMuHm6PGPCR6is2cCfMO62FMrOwcig4=
stash.appscode.dev/installer v0.9.0-rc.6.0.20200423190045-ab599e16e362 h1:3PXapNtpCXtSzDOntagI8dlb+pl8Jk5Grq5vFKkd9VQ=
stash.appscode.dev/installer v0.9.0-rc.6.0.20200423190045-ab599e16e362/go.mod h1:omw5JB5rQwBtKdZlhbNjX+E/xP0ksE9Y1W8WPsHdY9A=
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=
92 changes: 92 additions & 0 deletions pkg/schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright The Stash Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package pkg_test

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"

"stash.appscode.dev/installer/apis/installer/v1alpha1"

diff "github.com/yudai/gojsondiff"
"github.com/yudai/gojsondiff/formatter"
"sigs.k8s.io/yaml"
)

func TestStashMySQLDefaultValues(t *testing.T) {
diffstring, err := compareStashMySQLDefaultValues()
if err != nil {
t.Error(err)
}
if diffstring != "" {
t.Errorf("values file does not match, diff: %s", diffstring)
}
}

func compareStashMySQLDefaultValues() (string, error) {
data, err := ioutil.ReadFile("../charts/stash-mysql/values.yaml")
if err != nil {
return "", err
}

var original map[string]interface{}
err = yaml.Unmarshal(data, &original)
if err != nil {
return "", err
}
sorted, err := json.Marshal(&original)
if err != nil {
return "", err
}

var spec v1alpha1.StashMySQLSpec
err = yaml.Unmarshal(data, &spec)
if err != nil {
return "", err
}
parsed, err := json.Marshal(spec)
if err != nil {
return "", err
}

// Then, compare them
differ := diff.New()
d, err := differ.Compare(sorted, parsed)
if err != nil {
fmt.Printf("Failed to unmarshal file: %s\n", err.Error())
os.Exit(3)
}

if d.Modified() {
config := formatter.AsciiFormatterConfig{
ShowArrayIndex: true,
Coloring: true,
}

f := formatter.NewAsciiFormatter(original, config)
diffString, err := f.Format(d)
if err != nil {
return "", err
}
return diffString, nil
}

return "", nil
}
Loading

0 comments on commit 9e92fe9

Please sign in to comment.