Skip to content

Commit 41a7e67

Browse files
victorvarzaVictor Varza
andauthored
Fix swagger (#39)
* refactor makefile * fix swagger * fix swagger * fix tests * remove swagger doc test * bump to [email protected] * fix tests Co-authored-by: Victor Varza <[email protected]>
1 parent 395ac35 commit 41a7e67

File tree

17 files changed

+629
-504
lines changed

17 files changed

+629
-504
lines changed

.github/env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
golang-version=1.16
1+
golang-version=1.17

Makefile

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ all: format generate build test test-e2e
3636
.PHONY: clean
3737
clean:
3838
# Remove all files and directories ignored by git.
39+
# Stop all local containers.
3940
git clean -Xfd .
41+
./local/cleanup.sh
4042

4143

4244
############
@@ -97,21 +99,23 @@ release-slt:
9799
# Formatting #
98100
##############
99101

102+
.PHONY: format-prereq
103+
format-prereq:
104+
@[ -f $(GOSEC) ] || GOBIN=$(shell pwd)/bin go get "github.com/securego/gosec/v2/cmd/gosec";
105+
100106
.PHONY: format
101-
format: go-fmt go-vet go-lint go-sec check-license
107+
format: format-prereq go-fmt go-vet go-lint go-sec check-license
102108

103109
.PHONY: go-fmt
104110
go-fmt:
105111
@echo 'Formatting go code...'
106112
@gofmt -s -w .
107-
@echo 'Not formatiing issues found in go codebase!'
108-
113+
@echo 'Not formating issues found in go codebase!'
109114

110115
.PHONY: check-license
111116
check-license:
112117
./hack/check_license.sh
113118

114-
115119
.PHONY: go-lint
116120
go-lint: golangci-lint
117121
@echo 'Linting go code...'
@@ -123,21 +127,21 @@ lint-fix: golangci-lint
123127
$(GOLANGCI_LINT) run --fix
124128

125129
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
130+
GOLANGCI_LINT_VERSION = "v1.46.2"
126131
golangci-lint:
127-
@[ -f $(GOLANGCI_LINT) ] || { \
128-
set -e ;\
129-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.41.1 ;\
130-
}
132+
@[ -f $(GOLANGCI_LINT) ] || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION);
131133

132134
GOSEC = $(shell pwd)/bin/gosec
133-
go-sec: ## Inspects source code for security problems
134-
@if ! command -v gosec >/dev/null 2>&1 ; then $(call go-get-tool,$(GOSEC),github.com/securego/gosec/v2/cmd/gosec); fi
135+
.PHONY: go-sec
136+
go-sec:
137+
@[ -f $(GOSEC) ] || GOBIN=$(shell pwd)/bin go get "github.com/securego/gosec/v2/cmd/gosec";
135138
@echo 'Checking source code for security problems...'
136139
$(GOSEC) ./pkg/...
137-
@echo 'No security problems found in go codebase!'
140+
@echo 'No security problems found in go codebase!'
138141

139-
go-vet: ## Identifying subtle source code issues
140-
@echo 'Vetting go code...'
142+
.PHONY: go-vet
143+
go-vet:
144+
@echo 'Vetting go code and identify subtle source code issues...'
141145
@go vet $(shell pwd)/pkg/apiserver/...
142146
@echo 'Not issues found in go codebase!'
143147

@@ -146,19 +150,23 @@ go-vet: ## Identifying subtle source code issues
146150
# Testing #
147151
###########
148152

149-
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
153+
KUBEBUILDER_ASSETS=$(shell pwd)/kubebuilder
154+
K8S_VERSION=1.21.2
150155

151156
.PHONY: test
152157
test:
153-
mkdir -p ${ENVTEST_ASSETS_DIR}
154-
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
155-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test -race $(TEST_RUN_ARGS) -short $(PKGS) -count=1 -cover -v
158+
@[ -d $(KUBEBUILDER_ASSETS) ] || {\
159+
mkdir -p $(KUBEBUILDER_ASSETS);\
160+
curl -sSLo envtest-bins.tar.gz "https://go.kubebuilder.io/test-tools/$(K8S_VERSION)/$(GOOS)/$(GOARCH)";\
161+
tar -C $(KUBEBUILDER_ASSETS) --strip-components=1 -zvxf envtest-bins.tar.gz;\
162+
}
163+
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS)/bin go test -race $(TEST_RUN_ARGS) -short $(PKGS) -count=1 -cover -v
156164

157165
.PHONY: test-e2e
158166
test-e2e:
159167
$(shell pwd)/local/setup.sh
160168
@. local/.env.local && go test -race github.com/adobe/cluster-registry/test/e2e -count=1 -v
161-
$(shell pwd)/local/cleanup.sh
169+
# $(shell pwd)/local/cleanup.sh
162170

163171
## Make sure you have set the APISERVER_AUTH_TOKEN env variable.
164172
## Use PERFORMANCE_TEST_TIME env var to set the benchmark time per endpoint.
@@ -185,33 +193,24 @@ MANAGER_ROLE ?= "cluster-registry"
185193

186194
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
187195
controller-gen: ## Download controller-gen locally if necessary.
188-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
196+
@[ -f $(CONTROLLER_GEN) ] || GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-tools/cmd/[email protected]
189197

190198
KUSTOMIZE = $(shell pwd)/bin/kustomize
191199
kustomize: ## Download kustomize locally if necessary.
192-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
200+
@[ -f $(KUSTOMIZE) ] || GOBIN=$(shell pwd)/bin go install sigs.k8s.io/kustomize/kustomize/[email protected]
193201

194202
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
195203
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=$(MANAGER_ROLE) webhook paths="$(shell pwd)/pkg/api/..." output:crd:artifacts:config=$(shell pwd)/config/crd/bases output:rbac:artifacts:config=$(shell pwd)/config/rbac
196204

197205
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
198206
$(CONTROLLER_GEN) object:headerFile="$(shell pwd)/hack/boilerplate.go.txt" paths="$(shell pwd)/pkg/api/..."
199207

200-
# go-get-tool will 'go get' any package $2 and install it to $1.
201-
define go-get-tool
202-
@[ -f $(1) ] || { \
203-
set -e; \
204-
TMP_DIR=$$(mktemp -d); \
205-
cd $$TMP_DIR; \
206-
go mod init tmp; \
207-
echo "Downloading $(2)"; \
208-
GOBIN=$(shell pwd)/bin go get $(2); \
209-
rm -rf $$TMP_DIR; \
210-
}
211-
endef
212208

213-
# -------------
214-
# DOCUMENTATION
215-
# -------------
209+
#################
210+
# Documentation #
211+
#################
212+
213+
SWAGGER_CLI = $(shell pwd)/bin/swag
216214
swagger:
217-
swag init --parseDependency --parseInternal --parseDepth 2 -g cmd/apiserver/apiserver.go --output pkg/apiserver/docs/
215+
@[ -f $(SWAGGER_CLI) ] || GOBIN=$(shell pwd)/bin go install github.com/swaggo/swag/cmd/[email protected]
216+
$(SWAGGER_CLI) init --parseDependency --parseInternal --parseDepth 2 -g cmd/apiserver/apiserver.go --output pkg/apiserver/docs/

cmd/apiserver/apiserver.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ governing permissions and limitations under the License.
1313
package main
1414

1515
import (
16-
_ "github.com/adobe/cluster-registry/pkg/apiserver/docs"
16+
// docs "github.com/adobe/cluster-registry/pkg/apiserver/docs"
17+
"github.com/adobe/cluster-registry/pkg/apiserver/docs"
1718
"github.com/adobe/cluster-registry/pkg/apiserver/web"
1819
api "github.com/adobe/cluster-registry/pkg/apiserver/web"
1920
apiv1 "github.com/adobe/cluster-registry/pkg/apiserver/web/handler/v1"
@@ -65,6 +66,8 @@ func main() {
6566
AppConfig: appConfig,
6667
}
6768

69+
docs.SwaggerInfo.Host = appConfig.ApiHost
70+
6871
a.GET("/api/swagger/*", echoSwagger.WrapHandler)
6972
a.GET("/livez", web.Livez)
7073
a.GET("/readyz", status.Readyz)

go.mod

Lines changed: 127 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,137 @@
11
module github.com/adobe/cluster-registry
22

3-
go 1.15
3+
go 1.17
44

55
require (
6-
cloud.google.com/go v0.60.0 // indirect
7-
github.com/Azure/go-autorest/autorest v0.11.19 // indirect
8-
github.com/Azure/go-autorest/autorest/azure/auth v0.5.7
9-
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
6+
github.com/Azure/go-autorest/autorest/azure/auth v0.5.11
107
github.com/aws/aws-sdk-go v1.36.30
11-
github.com/coreos/go-oidc/v3 v3.0.0
12-
github.com/go-logr/logr v0.4.0
13-
github.com/go-openapi/jsonreference v0.19.6 // indirect
14-
github.com/go-openapi/spec v0.20.3 // indirect
15-
github.com/go-openapi/swag v0.19.15 // indirect
16-
github.com/go-playground/universal-translator v0.17.0 // indirect
17-
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
18-
github.com/google/uuid v1.3.0 // indirect
8+
github.com/coreos/go-oidc/v3 v3.2.0
9+
github.com/go-logr/logr v1.2.0
10+
github.com/google/uuid v1.3.0
1911
github.com/jinzhu/gorm v1.9.8
20-
github.com/labstack/echo/v4 v4.3.0
21-
github.com/labstack/gommon v0.3.0
22-
github.com/leodido/go-urn v1.2.0 // indirect
23-
github.com/mailru/easyjson v0.7.7 // indirect
12+
github.com/labstack/echo/v4 v4.7.2
13+
github.com/labstack/gommon v0.3.1
2414
github.com/onsi/ginkgo v1.16.5
25-
github.com/onsi/gomega v1.17.0
26-
github.com/prometheus/client_golang v1.11.0
27-
github.com/securego/gosec/v2 v2.9.6 // indirect
28-
github.com/stretchr/testify v1.7.0
29-
github.com/swaggo/echo-swagger v1.0.0
30-
github.com/swaggo/swag v1.7.0
31-
github.com/testcontainers/testcontainers-go v0.12.0 // indirect
32-
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
33-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2
34-
golang.org/x/tools v0.1.8 // indirect
15+
github.com/onsi/gomega v1.19.0
16+
github.com/prometheus/client_golang v1.12.1
17+
github.com/stretchr/testify v1.7.2
18+
github.com/swaggo/echo-swagger v1.3.3
19+
github.com/swaggo/swag v1.8.3
20+
github.com/testcontainers/testcontainers-go v0.13.0
21+
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
3522
gopkg.in/go-playground/validator.v9 v9.28.0
3623
gopkg.in/square/go-jose.v2 v2.5.1
37-
gopkg.in/yaml.v2 v2.4.0 // indirect
38-
k8s.io/api v0.21.2
39-
k8s.io/apimachinery v0.21.2
40-
k8s.io/client-go v0.21.2
41-
sigs.k8s.io/controller-runtime v0.9.2
42-
sigs.k8s.io/kind v0.14.0 // indirect
43-
sigs.k8s.io/yaml v1.3.0 // indirect
24+
gopkg.in/yaml.v2 v2.4.0
25+
k8s.io/api v0.24.2
26+
k8s.io/apimachinery v0.24.2
27+
k8s.io/client-go v0.24.2
28+
sigs.k8s.io/controller-runtime v0.12.3
29+
sigs.k8s.io/yaml v1.3.0
30+
)
31+
32+
require (
33+
cloud.google.com/go v0.81.0 // indirect
34+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
35+
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
36+
github.com/Azure/go-autorest/autorest v0.11.24 // indirect
37+
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
38+
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect
39+
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
40+
github.com/Azure/go-autorest/logger v0.2.1 // indirect
41+
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
42+
github.com/KyleBanks/depth v1.2.1 // indirect
43+
github.com/Microsoft/go-winio v0.4.17 // indirect
44+
github.com/Microsoft/hcsshim v0.8.23 // indirect
45+
github.com/PuerkitoBio/purell v1.1.1 // indirect
46+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
47+
github.com/beorn7/perks v1.0.1 // indirect
48+
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
49+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
50+
github.com/containerd/cgroups v1.0.1 // indirect
51+
github.com/containerd/containerd v1.5.9 // indirect
52+
github.com/davecgh/go-spew v1.1.1 // indirect
53+
github.com/dimchansky/utfbom v1.1.1 // indirect
54+
github.com/docker/distribution v2.7.1+incompatible // indirect
55+
github.com/docker/docker v20.10.11+incompatible // indirect
56+
github.com/docker/go-connections v0.4.0 // indirect
57+
github.com/docker/go-units v0.4.0 // indirect
58+
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
59+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
60+
github.com/fsnotify/fsnotify v1.5.1 // indirect
61+
github.com/go-logr/zapr v1.2.0 // indirect
62+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
63+
github.com/go-openapi/jsonreference v0.19.6 // indirect
64+
github.com/go-openapi/spec v0.20.4 // indirect
65+
github.com/go-openapi/swag v0.19.15 // indirect
66+
github.com/go-playground/locales v0.14.0 // indirect
67+
github.com/go-playground/universal-translator v0.18.0 // indirect
68+
github.com/gogo/protobuf v1.3.2 // indirect
69+
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
70+
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
71+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
72+
github.com/golang/protobuf v1.5.2 // indirect
73+
github.com/google/gnostic v0.5.7-v3refs // indirect
74+
github.com/google/go-cmp v0.5.5 // indirect
75+
github.com/google/gofuzz v1.1.0 // indirect
76+
github.com/imdario/mergo v0.3.12 // indirect
77+
github.com/jmespath/go-jmespath v0.4.0 // indirect
78+
github.com/josharian/intern v1.0.0 // indirect
79+
github.com/json-iterator/go v1.1.12 // indirect
80+
github.com/leodido/go-urn v1.2.1 // indirect
81+
github.com/magiconair/properties v1.8.5 // indirect
82+
github.com/mailru/easyjson v0.7.7 // indirect
83+
github.com/mattn/go-colorable v0.1.11 // indirect
84+
github.com/mattn/go-isatty v0.0.14 // indirect
85+
github.com/mattn/go-sqlite3 v1.10.0 // indirect
86+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
87+
github.com/mitchellh/go-homedir v1.1.0 // indirect
88+
github.com/moby/sys/mount v0.2.0 // indirect
89+
github.com/moby/sys/mountinfo v0.5.0 // indirect
90+
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
91+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
92+
github.com/modern-go/reflect2 v1.0.2 // indirect
93+
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c // indirect
94+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
95+
github.com/nxadm/tail v1.4.8 // indirect
96+
github.com/onsi/ginkgo/v2 v2.1.4 // indirect
97+
github.com/opencontainers/go-digest v1.0.0 // indirect
98+
github.com/opencontainers/image-spec v1.0.2 // indirect
99+
github.com/opencontainers/runc v1.0.2 // indirect
100+
github.com/pkg/errors v0.9.1 // indirect
101+
github.com/pmezard/go-difflib v1.0.0 // indirect
102+
github.com/prometheus/client_model v0.2.0 // indirect
103+
github.com/prometheus/common v0.32.1 // indirect
104+
github.com/prometheus/procfs v0.7.3 // indirect
105+
github.com/sirupsen/logrus v1.8.1 // indirect
106+
github.com/spf13/pflag v1.0.5 // indirect
107+
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect
108+
github.com/valyala/bytebufferpool v1.0.0 // indirect
109+
github.com/valyala/fasttemplate v1.2.1 // indirect
110+
go.opencensus.io v0.23.0 // indirect
111+
go.uber.org/atomic v1.7.0 // indirect
112+
go.uber.org/multierr v1.6.0 // indirect
113+
go.uber.org/zap v1.19.1 // indirect
114+
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
115+
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
116+
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
117+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
118+
golang.org/x/text v0.3.7 // indirect
119+
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
120+
golang.org/x/tools v0.1.11 // indirect
121+
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
122+
google.golang.org/appengine v1.6.7 // indirect
123+
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
124+
google.golang.org/grpc v1.40.0 // indirect
125+
google.golang.org/protobuf v1.27.1 // indirect
126+
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
127+
gopkg.in/inf.v0 v0.9.1 // indirect
128+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
129+
gopkg.in/yaml.v3 v3.0.1 // indirect
130+
k8s.io/apiextensions-apiserver v0.24.2 // indirect
131+
k8s.io/component-base v0.24.2 // indirect
132+
k8s.io/klog/v2 v2.60.1 // indirect
133+
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
134+
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
135+
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
136+
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
44137
)

0 commit comments

Comments
 (0)