Skip to content

Commit 0fe49c0

Browse files
committed
Add openapi v3 schema for values file (#27)
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 41b3eaf commit 0fe49c0

File tree

1,262 files changed

+247627
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,262 files changed

+247627
-69
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616

17-
- name: Set up Go 1.13
17+
- name: Set up Go 1.14
1818
uses: actions/setup-go@v1
1919
with:
20-
go-version: 1.13
20+
go-version: 1.14
2121
id: go
2222

2323
- name: Check out code into the Go module directory
@@ -36,6 +36,15 @@ jobs:
3636
run: |
3737
sudo apt-get -qq update || true
3838
sudo apt-get install -y bzr
39+
# install yq
40+
curl -fsSL -o yq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64
41+
chmod +x yq
42+
sudo mv yq /usr/local/bin/yq
43+
# install kubectl
44+
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl
45+
chmod +x ./kubectl
46+
sudo mv ./kubectl /usr/local/bin/kubectl
47+
# run checks
3948
make ci
4049
4150
- name: Build

Makefile

Lines changed: 138 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ REPO := $(notdir $(shell pwd))
2020
BIN := stash-postgres
2121
COMPRESS ?= no
2222

23+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
24+
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
25+
# https://github.com/appscodelabs/gengo-builder
26+
CODE_GENERATOR_IMAGE ?= appscode/gengo:release-1.16
27+
API_GROUPS ?= installer:v1alpha1
28+
2329
# Where to push the docker image.
2430
REGISTRY ?= stashed
2531

@@ -71,9 +77,9 @@ TAG := $(VERSION)_$(OS)_$(ARCH)
7177
TAG_PROD := $(TAG)
7278
TAG_DBG := $(VERSION)-dbg_$(OS)_$(ARCH)
7379

74-
GO_VERSION ?= 1.13.6
80+
GO_VERSION ?= 1.14.2
7581
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)
76-
CHART_TEST_IMAGE ?= quay.io/helmpack/chart-testing:v3.0.0-beta.1
82+
CHART_TEST_IMAGE ?= quay.io/helmpack/chart-testing:v3.0.0-rc.1
7783

7884
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
7985
ifeq ($(OS),windows)
@@ -134,8 +140,134 @@ version:
134140
@echo ::set-output name=commit_hash::$(commit_hash)
135141
@echo ::set-output name=commit_timestamp::$(commit_timestamp)
136142

137-
gen:
138-
@true
143+
.PHONY: clientset
144+
clientset:
145+
@docker run --rm \
146+
-u $$(id -u):$$(id -g) \
147+
-v /tmp:/.cache \
148+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
149+
-w $(DOCKER_REPO_ROOT) \
150+
--env HTTP_PROXY=$(HTTP_PROXY) \
151+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
152+
$(CODE_GENERATOR_IMAGE) \
153+
/go/src/k8s.io/code-generator/generate-groups.sh \
154+
"deepcopy" \
155+
$(GO_PKG)/$(REPO)/client \
156+
$(GO_PKG)/$(REPO)/apis \
157+
"$(API_GROUPS)" \
158+
--go-header-file "./hack/license/go.txt"
159+
160+
# Generate openapi schema
161+
.PHONY: openapi
162+
openapi: $(addprefix openapi-, $(subst :,_, $(API_GROUPS)))
163+
@echo "Generating api/openapi-spec/swagger.json"
164+
@docker run --rm \
165+
-u $$(id -u):$$(id -g) \
166+
-v /tmp:/.cache \
167+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
168+
-w $(DOCKER_REPO_ROOT) \
169+
--env HTTP_PROXY=$(HTTP_PROXY) \
170+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
171+
--env GO111MODULE=on \
172+
--env GOFLAGS="-mod=vendor" \
173+
$(BUILD_IMAGE) \
174+
go run hack/gencrd/main.go
175+
176+
openapi-%:
177+
@echo "Generating openapi schema for $(subst _,/,$*)"
178+
@docker run --rm \
179+
-u $$(id -u):$$(id -g) \
180+
-v /tmp:/.cache \
181+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
182+
-w $(DOCKER_REPO_ROOT) \
183+
--env HTTP_PROXY=$(HTTP_PROXY) \
184+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
185+
$(CODE_GENERATOR_IMAGE) \
186+
openapi-gen \
187+
--v 1 --logtostderr \
188+
--go-header-file "./hack/license/go.txt" \
189+
--input-dirs "$(GO_PKG)/$(REPO)/apis/$(subst _,/,$*),k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/version,k8s.io/api/core/v1,k8s.io/api/apps/v1,k8s.io/api/rbac/v1" \
190+
--output-package "$(GO_PKG)/$(REPO)/apis/$(subst _,/,$*)" \
191+
--report-filename /tmp/violation_exceptions.list
192+
193+
# Generate CRD manifests
194+
.PHONY: gen-crds
195+
gen-crds:
196+
@echo "Generating CRD manifests"
197+
@docker run --rm \
198+
-u $$(id -u):$$(id -g) \
199+
-v /tmp:/.cache \
200+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
201+
-w $(DOCKER_REPO_ROOT) \
202+
--env HTTP_PROXY=$(HTTP_PROXY) \
203+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
204+
$(CODE_GENERATOR_IMAGE) \
205+
controller-gen \
206+
$(CRD_OPTIONS) \
207+
paths="./apis/..." \
208+
output:crd:artifacts:config=api/crds
209+
210+
crds_to_patch := installer.stash.appscode.com_stashpostgreses.yaml
211+
212+
.PHONY: patch-crds
213+
patch-crds: $(addprefix patch-crd-, $(crds_to_patch))
214+
patch-crd-%: $(BUILD_DIRS)
215+
@echo "patching $*"
216+
@kubectl patch -f api/crds/$* -p "$$(cat hack/crd-patch.json)" --type=json --local=true -o yaml > bin/$*
217+
@mv bin/$* api/crds/$*
218+
219+
.PHONY: label-crds
220+
label-crds: $(BUILD_DIRS)
221+
@for f in api/crds/*.yaml; do \
222+
echo "applying app=stash label to $$f"; \
223+
kubectl label --overwrite -f $$f --local=true -o yaml app=stash > bin/crd.yaml; \
224+
mv bin/crd.yaml $$f; \
225+
done
226+
227+
.PHONY: gen-crd-protos
228+
gen-crd-protos: $(addprefix gen-crd-protos-, $(subst :,_, $(API_GROUPS)))
229+
230+
gen-crd-protos-%:
231+
@echo "Generating protobuf for $(subst _,/,$*)"
232+
@docker run --rm \
233+
-u $$(id -u):$$(id -g) \
234+
-v /tmp:/.cache \
235+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
236+
-w $(DOCKER_REPO_ROOT) \
237+
--env HTTP_PROXY=$(HTTP_PROXY) \
238+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
239+
$(CODE_GENERATOR_IMAGE) \
240+
go-to-protobuf \
241+
--go-header-file "./hack/license/go.txt" \
242+
--proto-import=$(DOCKER_REPO_ROOT)/vendor \
243+
--proto-import=$(DOCKER_REPO_ROOT)/third_party/protobuf \
244+
--apimachinery-packages=-k8s.io/apimachinery/pkg/api/resource,-k8s.io/apimachinery/pkg/apis/meta/v1,-k8s.io/apimachinery/pkg/apis/meta/v1beta1,-k8s.io/apimachinery/pkg/runtime,-k8s.io/apimachinery/pkg/runtime/schema,-k8s.io/apimachinery/pkg/util/intstr \
245+
--packages=-k8s.io/api/core/v1,stash.appscode.dev/postgres/apis/$(subst _,/,$*)
246+
247+
.PHONY: gen-bindata
248+
gen-bindata:
249+
@docker run \
250+
-i \
251+
--rm \
252+
-u $$(id -u):$$(id -g) \
253+
-v $$(pwd):/src \
254+
-w /src/api/crds \
255+
-v /tmp:/.cache \
256+
--env HTTP_PROXY=$(HTTP_PROXY) \
257+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
258+
$(BUILD_IMAGE) \
259+
go-bindata -ignore=\\.go -ignore=\\.DS_Store -mode=0644 -modtime=1573722179 -o bindata.go -pkg crds ./...
260+
261+
.PHONY: gen-values-schema
262+
gen-values-schema:
263+
@yq r api/crds/installer.stash.appscode.com_stashpostgreses.yaml spec.validation.openAPIV3Schema.properties.spec > /tmp/stash-postgres-values.openapiv3_schema.yaml
264+
@yq d /tmp/stash-postgres-values.openapiv3_schema.yaml description > charts/stash-postgres/values.openapiv3_schema.yaml
265+
266+
.PHONY: manifests
267+
manifests: gen-crds patch-crds label-crds gen-bindata gen-values-schema
268+
269+
.PHONY: gen
270+
gen: clientset gen-crd-protos manifests openapi
139271

140272
fmt: $(BUILD_DIRS)
141273
@docker run \
@@ -311,7 +443,7 @@ lint: $(BUILD_DIRS)
311443
--env GO111MODULE=on \
312444
--env GOFLAGS="-mod=vendor" \
313445
$(BUILD_IMAGE) \
314-
golangci-lint run --enable $(ADDTL_LINTERS) --deadline=10m --skip-files="generated.*\.go$\" --skip-dirs-use-default
446+
golangci-lint run --enable $(ADDTL_LINTERS) --timeout=30m --skip-files="generated.*\.go$\" --skip-dirs-use-default --skip-dirs=client,vendor
315447

316448
$(BUILD_DIRS):
317449
@mkdir -p $@
@@ -333,7 +465,7 @@ verify-modules:
333465
.PHONY: verify-gen
334466
verify-gen: gen fmt
335467
@if !(git diff --exit-code HEAD); then \
336-
echo "files are out of date, run make gen fmt"; exit 1; \
468+
echo "generated files are out of date, run make gen"; exit 1; \
337469
fi
338470

339471
.PHONY: add-license

0 commit comments

Comments
 (0)