Skip to content

Commit 74abc6e

Browse files
authored
Add StashOperator crd (#17)
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent c0ff647 commit 74abc6e

File tree

2,720 files changed

+904879
-12
lines changed

Some content is hidden

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

2,720 files changed

+904879
-12
lines changed

Makefile

Lines changed: 194 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ GO_PKG := stash.appscode.dev
1919
REPO := $(notdir $(shell pwd))
2020
BIN := installer
2121

22+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
23+
CRD_OPTIONS ?= "crd:trivialVersions=true"
24+
# https://github.com/appscodelabs/gengo-builder
25+
CODE_GENERATOR_IMAGE ?= appscode/gengo:release-1.14
26+
API_GROUPS ?= installer:v1alpha1
27+
2228
# This version-strategy uses git tags to set the version string
2329
git_branch := $(shell git rev-parse --abbrev-ref HEAD)
2430
git_tag := $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "")
@@ -43,10 +49,10 @@ endif
4349
### These variables should not need tweaking.
4450
###
4551

46-
SRC_DIRS := # directories which hold app source (not vendored)
52+
SRC_DIRS := api apis hack/gencrd # directories which hold app source (not vendored)
4753

4854
DOCKER_PLATFORMS := linux/amd64 linux/arm linux/arm64
49-
BIN_PLATFORMS := $(DOCKER_PLATFORMS) windows/amd64 darwin/amd64
55+
BIN_PLATFORMS := $(DOCKER_PLATFORMS)
5056

5157
# Used internally. Users should pass GOOS and/or GOARCH.
5258
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
@@ -56,7 +62,7 @@ BASEIMAGE_PROD ?= gcr.io/distroless/static
5662
BASEIMAGE_DBG ?= debian:stretch
5763

5864
GO_VERSION ?= 1.12.12
59-
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)-stretch
65+
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)
6066
CHART_TEST_IMAGE ?= quay.io/helmpack/chart-testing:v2.4.0
6167

6268
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
@@ -73,6 +79,8 @@ BUILD_DIRS := bin/$(OS)_$(ARCH) \
7379
$(HOME)/.kube \
7480
$(HOME)/.minikube
7581

82+
DOCKER_REPO_ROOT := /go/src/$(GO_PKG)/$(REPO)
83+
7684
# If you want to build all binaries, see the 'all-build' rule.
7785
# If you want to build all containers, see the 'all-container' rule.
7886
# If you want to build AND push all containers, see the 'all-push' rule.
@@ -97,11 +105,107 @@ version:
97105
@echo commit_hash=$(commit_hash)
98106
@echo commit_timestamp=$(commit_timestamp)
99107

100-
DOCKER_REPO_ROOT := /go/src/$(GO_PKG)/$(REPO)
108+
.PHONY: clientset
109+
clientset:
110+
@docker run --rm \
111+
-u $$(id -u):$$(id -g) \
112+
-v /tmp:/.cache \
113+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
114+
-w $(DOCKER_REPO_ROOT) \
115+
--env HTTP_PROXY=$(HTTP_PROXY) \
116+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
117+
$(CODE_GENERATOR_IMAGE) \
118+
/go/src/k8s.io/code-generator/generate-groups.sh \
119+
"deepcopy" \
120+
$(GO_PKG)/$(REPO)/client \
121+
$(GO_PKG)/$(REPO)/apis \
122+
"$(API_GROUPS)" \
123+
--go-header-file "./hack/license/go.txt"
124+
125+
# Generate openapi schema
126+
.PHONY: openapi
127+
openapi: $(addprefix openapi-, $(subst :,_, $(API_GROUPS)))
128+
@echo "Generating api/openapi-spec/swagger.json"
129+
@docker run --rm \
130+
-u $$(id -u):$$(id -g) \
131+
-v /tmp:/.cache \
132+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
133+
-w $(DOCKER_REPO_ROOT) \
134+
--env HTTP_PROXY=$(HTTP_PROXY) \
135+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
136+
$(BUILD_IMAGE) \
137+
go run hack/gencrd/main.go
138+
139+
openapi-%:
140+
@echo "Generating openapi schema for $(subst _,/,$*)"
141+
@docker run --rm \
142+
-u $$(id -u):$$(id -g) \
143+
-v /tmp:/.cache \
144+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
145+
-w $(DOCKER_REPO_ROOT) \
146+
--env HTTP_PROXY=$(HTTP_PROXY) \
147+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
148+
$(CODE_GENERATOR_IMAGE) \
149+
openapi-gen \
150+
--v 1 --logtostderr \
151+
--go-header-file "./hack/license/go.txt" \
152+
--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" \
153+
--output-package "$(GO_PKG)/$(REPO)/apis/$(subst _,/,$*)" \
154+
--report-filename /tmp/violation_exceptions.list
155+
156+
# Generate CRD manifests
157+
.PHONY: gen-crds
158+
gen-crds:
159+
@echo "Generating CRD manifests"
160+
@docker run --rm \
161+
-u $$(id -u):$$(id -g) \
162+
-v /tmp:/.cache \
163+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
164+
-w $(DOCKER_REPO_ROOT) \
165+
--env HTTP_PROXY=$(HTTP_PROXY) \
166+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
167+
$(CODE_GENERATOR_IMAGE) \
168+
controller-gen \
169+
$(CRD_OPTIONS) \
170+
paths="./apis/..." \
171+
output:crd:artifacts:config=api/crds
172+
173+
crds_to_patch := installer.stash.appscode.com_stashoperators.yaml
174+
175+
.PHONY: patch-crds
176+
patch-crds: $(addprefix patch-crd-, $(crds_to_patch))
177+
patch-crd-%: $(BUILD_DIRS)
178+
@echo "patching $*"
179+
@kubectl patch -f api/crds/$* -p "$$(cat hack/crd-patch.json)" --type=json --local=true -o yaml > bin/$*
180+
@mv bin/$* api/crds/$*
181+
182+
.PHONY: label-crds
183+
label-crds: $(BUILD_DIRS)
184+
@for f in api/crds/*.yaml; do \
185+
echo "applying app=stash label to $$f"; \
186+
kubectl label --overwrite -f $$f --local=true -o yaml app=stash > bin/crd.yaml; \
187+
mv bin/crd.yaml $$f; \
188+
done
189+
190+
.PHONY: gen-bindata
191+
gen-bindata:
192+
@docker run \
193+
-i \
194+
--rm \
195+
-u $$(id -u):$$(id -g) \
196+
-v $$(pwd):/src \
197+
-w /src/api/crds \
198+
-v /tmp:/.cache \
199+
--env HTTP_PROXY=$(HTTP_PROXY) \
200+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
201+
$(BUILD_IMAGE) \
202+
go-bindata -ignore=\\.go -ignore=\\.DS_Store -mode=0644 -modtime=1573722179 -o bindata.go -pkg crds ./...
203+
204+
.PHONY: manifests
205+
manifests: gen-crds patch-crds label-crds gen-bindata
101206

102207
.PHONY: gen
103-
gen:
104-
@true
208+
gen: clientset openapi manifests
105209

106210
fmt: $(BUILD_DIRS)
107211
@docker run \
@@ -121,9 +225,61 @@ fmt: $(BUILD_DIRS)
121225
./hack/fmt.sh $(SRC_DIRS) \
122226
"
123227

228+
build: $(OUTBIN)
229+
230+
.PHONY: .go/$(OUTBIN)
231+
$(OUTBIN): $(BUILD_DIRS)
232+
@echo "making $(OUTBIN)"
233+
@docker run \
234+
-i \
235+
--rm \
236+
-u $$(id -u):$$(id -g) \
237+
-v $$(pwd):/src \
238+
-w /src \
239+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
240+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
241+
-v $$(pwd)/.go/cache:/.cache \
242+
--env HTTP_PROXY=$(HTTP_PROXY) \
243+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
244+
$(BUILD_IMAGE) \
245+
/bin/bash -c " \
246+
ARCH=$(ARCH) \
247+
OS=$(OS) \
248+
VERSION=$(VERSION) \
249+
version_strategy=$(version_strategy) \
250+
git_branch=$(git_branch) \
251+
git_tag=$(git_tag) \
252+
commit_hash=$(commit_hash) \
253+
commit_timestamp=$(commit_timestamp) \
254+
./hack/build.sh \
255+
"
256+
@echo
257+
258+
.PHONY: test
259+
test: unit-tests
260+
261+
unit-tests: $(BUILD_DIRS)
262+
@docker run \
263+
-i \
264+
--rm \
265+
-u $$(id -u):$$(id -g) \
266+
-v $$(pwd):/src \
267+
-w /src \
268+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
269+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
270+
-v $$(pwd)/.go/cache:/.cache \
271+
--env HTTP_PROXY=$(HTTP_PROXY) \
272+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
273+
$(BUILD_IMAGE) \
274+
/bin/bash -c " \
275+
ARCH=$(ARCH) \
276+
OS=$(OS) \
277+
VERSION=$(VERSION) \
278+
./hack/test.sh $(SRC_DIRS) \
279+
"
280+
124281
.PHONY: ct
125282
ct: $(BUILD_DIRS)
126-
@echo $(XYZ)
127283
@docker run \
128284
-i \
129285
--rm \
@@ -148,14 +304,43 @@ ct: $(BUILD_DIRS)
148304
ct lint-and-install --all; \
149305
"
150306

307+
ADDTL_LINTERS := goconst,gofmt,goimports,unparam
308+
309+
.PHONY: lint
310+
lint: $(BUILD_DIRS)
311+
@echo "running linter"
312+
@docker run \
313+
-i \
314+
--rm \
315+
-u $$(id -u):$$(id -g) \
316+
-v $$(pwd):/src \
317+
-w /src \
318+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
319+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
320+
-v $$(pwd)/.go/cache:/.cache \
321+
--env HTTP_PROXY=$(HTTP_PROXY) \
322+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
323+
--env GO111MODULE=on \
324+
--env GOFLAGS="-mod=vendor" \
325+
$(BUILD_IMAGE) \
326+
golangci-lint run --enable $(ADDTL_LINTERS) --timeout=10m --skip-files="generated.*\.go$\" --skip-dirs-use-default --skip-dirs=client,vendor
327+
151328
$(BUILD_DIRS):
152329
@mkdir -p $@
153330

154331
.PHONY: dev
155332
dev: gen fmt
156333

157334
.PHONY: verify
158-
verify: verify-gen
335+
verify: verify-modules verify-gen
336+
337+
.PHONY: verify-modules
338+
verify-modules:
339+
GO111MODULE=on go mod tidy
340+
GO111MODULE=on go mod vendor
341+
@if !(git diff --exit-code HEAD); then \
342+
echo "go module files are out of date"; exit 1; \
343+
fi
159344

160345
.PHONY: verify-gen
161346
verify-gen: gen fmt
@@ -190,7 +375,7 @@ check-license:
190375
ltag -t "./hack/license" --excludes "vendor contrib libbuild" --check -v
191376

192377
.PHONY: ci
193-
ci: verify check-license
378+
ci: verify check-license lint build unit-tests #cover
194379

195380
.PHONY: clean
196381
clean:

api/crds/bindata.go

Lines changed: 244 additions & 0 deletions
Large diffs are not rendered by default.

api/crds/doc.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright The Stash Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package crds

0 commit comments

Comments
 (0)