Skip to content

Commit 27ae4cc

Browse files
committed
Update license verifier
/cherry-pick Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 0cd2fb7 commit 27ae4cc

File tree

17 files changed

+568
-101
lines changed

17 files changed

+568
-101
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/pkg/errors v0.9.1
1010
github.com/sergi/go-diff v1.1.0 // indirect
1111
github.com/spf13/cobra v1.1.1
12-
go.bytebuilders.dev/license-verifier/kubernetes v0.6.1
12+
go.bytebuilders.dev/license-verifier/kubernetes v0.7.1
1313
gomodules.xyz/pointer v0.0.0-20201105071923-daf60fa55209
1414
gomodules.xyz/x v0.0.0-20201105065653-91c568df6331
1515
k8s.io/api v0.18.9

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,10 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3Ifn
775775
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
776776
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
777777
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
778-
go.bytebuilders.dev/license-verifier v0.6.1 h1:HhtVt+K4TBlOwUNhE4HJWBm5S7nsAizOLuirLmIz2ZA=
779-
go.bytebuilders.dev/license-verifier v0.6.1/go.mod h1:SNXpEKh3gg2ljHzh6Dxa7qMZS6hM6L9eQ+U0vaGyfFQ=
780-
go.bytebuilders.dev/license-verifier/kubernetes v0.6.1 h1:WTT81asc7ykKI6E9BzeV0EFkaTniqaghKsybvHQlaGc=
781-
go.bytebuilders.dev/license-verifier/kubernetes v0.6.1/go.mod h1:YyvxUrqALordUC9554S2J93ozJ6PK4GVEyUCmUgUSbo=
778+
go.bytebuilders.dev/license-verifier v0.7.1 h1:ea2HO0Qfu/Li6lR5ZFs0E0uPDwFW4NZGszX5NSRhLio=
779+
go.bytebuilders.dev/license-verifier v0.7.1/go.mod h1:N7fJxdaBJQ9seOGFg+trJQ3eWwy/ga6YZi0wlvdDQi0=
780+
go.bytebuilders.dev/license-verifier/kubernetes v0.7.1 h1:JogI0Y+MQRIdQd0fH9uFtJuimrOgwThAbl9mfxyF0DM=
781+
go.bytebuilders.dev/license-verifier/kubernetes v0.7.1/go.mod h1:92LIvidYIGntnkUJJKjRH3s6qdgyiHRZFeBd14Efl3c=
782782
go.elastic.co/apm v1.5.0/go.mod h1:OdB9sPtM6Vt7oz3VXt7+KR96i9li74qrxBGHTQygFvk=
783783
go.elastic.co/apm/module/apmhttp v1.5.0/go.mod h1:1FbmNuyD3ddauwzgVwFB0fqY6KbZt3JkV187tGCYYhY=
784784
go.elastic.co/apm/module/apmot v1.5.0/go.mod h1:d2KYwhJParTpyw2WnTNy8geNlHKKFX+4oK3YLlsesWE=
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
# Copyright AppsCode Inc. and Contributors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
SHELL=/bin/bash -o pipefail
16+
17+
GO_PKG := go.bytebuilders.dev
18+
REPO := $(notdir $(shell pwd))
19+
BIN := license-verifier
20+
COMPRESS ?= no
21+
22+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
23+
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false,crdVersions={v1beta1,v1}"
24+
CODE_GENERATOR_IMAGE ?= appscode/gengo:release-1.18
25+
API_GROUPS ?= licenses:v1alpha1
26+
27+
# Where to push the docker image.
28+
REGISTRY ?= bytebuilders
29+
30+
# This version-strategy uses git tags to set the version string
31+
git_branch := $(shell git rev-parse --abbrev-ref HEAD)
32+
git_tag := $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "")
33+
commit_hash := $(shell git rev-parse --verify HEAD)
34+
commit_timestamp := $(shell date --date="@$$(git show -s --format=%ct)" --utc +%FT%T)
35+
36+
VERSION := $(shell git describe --tags --always --dirty)
37+
version_strategy := commit_hash
38+
ifdef git_tag
39+
VERSION := $(git_tag)
40+
version_strategy := tag
41+
else
42+
ifeq (,$(findstring $(git_branch),master HEAD))
43+
ifneq (,$(patsubst release-%,,$(git_branch)))
44+
VERSION := $(git_branch)
45+
version_strategy := branch
46+
endif
47+
endif
48+
endif
49+
50+
###
51+
### These variables should not need tweaking.
52+
###
53+
54+
SRC_PKGS := apis # directories which hold app source excluding tests (not vendored)
55+
SRC_DIRS := $(SRC_PKGS) *.go # directories which hold app source (not vendored)
56+
57+
DOCKER_PLATFORMS := linux/amd64 linux/arm linux/arm64
58+
BIN_PLATFORMS := $(DOCKER_PLATFORMS) windows/amd64 darwin/amd64
59+
60+
# Used internally. Users should pass GOOS and/or GOARCH.
61+
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
62+
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
63+
64+
BASEIMAGE_PROD ?= gcr.io/distroless/static-debian10
65+
BASEIMAGE_DBG ?= debian:buster
66+
67+
GO_VERSION ?= 1.16
68+
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)
69+
70+
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
71+
ifeq ($(OS),windows)
72+
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN).exe
73+
endif
74+
75+
# Directories that we need created to build/test.
76+
BUILD_DIRS := bin/$(OS)_$(ARCH) \
77+
.go/bin/$(OS)_$(ARCH) \
78+
.go/cache \
79+
hack/config \
80+
$(HOME)/.credentials \
81+
$(HOME)/.kube \
82+
$(HOME)/.minikube
83+
84+
DOCKERFILE_TEST = Dockerfile.test
85+
86+
DOCKER_REPO_ROOT := /go/src/$(GO_PKG)/$(REPO)
87+
88+
# If you want to build all binaries, see the 'all-build' rule.
89+
# If you want to build all containers, see the 'all-container' rule.
90+
# If you want to build AND push all containers, see the 'all-push' rule.
91+
all: fmt build
92+
93+
# For the following OS/ARCH expansions, we transform OS/ARCH into OS_ARCH
94+
# because make pattern rules don't match with embedded '/' characters.
95+
96+
build-%:
97+
@$(MAKE) build \
98+
--no-print-directory \
99+
GOOS=$(firstword $(subst _, ,$*)) \
100+
GOARCH=$(lastword $(subst _, ,$*))
101+
102+
all-build: $(addprefix build-, $(subst /,_, $(BIN_PLATFORMS)))
103+
104+
version:
105+
@echo ::set-output name=version::$(VERSION)
106+
@echo ::set-output name=version_strategy::$(version_strategy)
107+
@echo ::set-output name=git_tag::$(git_tag)
108+
@echo ::set-output name=git_branch::$(git_branch)
109+
@echo ::set-output name=commit_hash::$(commit_hash)
110+
@echo ::set-output name=commit_timestamp::$(commit_timestamp)
111+
112+
# Generate a typed clientset
113+
.PHONY: clientset
114+
clientset:
115+
@docker run --rm \
116+
-u $$(id -u):$$(id -g) \
117+
-v /tmp:/.cache \
118+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
119+
-w $(DOCKER_REPO_ROOT) \
120+
--env HTTP_PROXY=$(HTTP_PROXY) \
121+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
122+
$(CODE_GENERATOR_IMAGE) \
123+
/go/src/k8s.io/code-generator/generate-groups.sh \
124+
deepcopy-gen \
125+
$(GO_PKG)/$(REPO)/client \
126+
$(GO_PKG)/$(REPO)/apis \
127+
"$(API_GROUPS)" \
128+
--go-header-file "./hack/license/go.txt"
129+
130+
.PHONY: gen
131+
gen: clientset
132+
133+
fmt: $(BUILD_DIRS)
134+
@docker run \
135+
-i \
136+
--rm \
137+
-u $$(id -u):$$(id -g) \
138+
-v $$(pwd):/src \
139+
-w /src \
140+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
141+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
142+
-v $$(pwd)/.go/cache:/.cache \
143+
--env HTTP_PROXY=$(HTTP_PROXY) \
144+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
145+
$(BUILD_IMAGE) \
146+
/bin/bash -c " \
147+
REPO_PKG=$(GO_PKG) \
148+
./hack/fmt.sh $(SRC_DIRS) \
149+
"
150+
151+
build: $(OUTBIN)
152+
153+
.PHONY: .go/$(OUTBIN)
154+
$(OUTBIN): $(BUILD_DIRS)
155+
@echo "making $(OUTBIN)"
156+
@docker run \
157+
-i \
158+
--rm \
159+
-u $$(id -u):$$(id -g) \
160+
-v $$(pwd):/src \
161+
-w /src \
162+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
163+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
164+
-v $$(pwd)/.go/cache:/.cache \
165+
--env HTTP_PROXY=$(HTTP_PROXY) \
166+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
167+
$(BUILD_IMAGE) \
168+
/bin/bash -c " \
169+
ARCH=$(ARCH) \
170+
OS=$(OS) \
171+
VERSION=$(VERSION) \
172+
version_strategy=$(version_strategy) \
173+
git_branch=$(git_branch) \
174+
git_tag=$(git_tag) \
175+
commit_hash=$(commit_hash) \
176+
commit_timestamp=$(commit_timestamp) \
177+
./hack/build.sh \
178+
"
179+
@echo
180+
181+
.PHONY: test
182+
test: unit-tests
183+
184+
unit-tests: $(BUILD_DIRS)
185+
@docker run \
186+
-i \
187+
--rm \
188+
-u $$(id -u):$$(id -g) \
189+
-v $$(pwd):/src \
190+
-w /src \
191+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
192+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
193+
-v $$(pwd)/.go/cache:/.cache \
194+
--env HTTP_PROXY=$(HTTP_PROXY) \
195+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
196+
$(BUILD_IMAGE) \
197+
/bin/bash -c " \
198+
ARCH=$(ARCH) \
199+
OS=$(OS) \
200+
VERSION=$(VERSION) \
201+
./hack/test.sh $(SRC_PKGS) \
202+
"
203+
204+
ADDTL_LINTERS := goconst,gofmt,goimports,unparam
205+
206+
.PHONY: lint
207+
lint: $(BUILD_DIRS)
208+
@echo "running linter"
209+
@docker run \
210+
-i \
211+
--rm \
212+
-u $$(id -u):$$(id -g) \
213+
-v $$(pwd):/src \
214+
-w /src \
215+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
216+
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
217+
-v $$(pwd)/.go/cache:/.cache \
218+
--env HTTP_PROXY=$(HTTP_PROXY) \
219+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
220+
--env GO111MODULE=on \
221+
--env GOFLAGS="-mod=vendor" \
222+
$(BUILD_IMAGE) \
223+
golangci-lint run --enable $(ADDTL_LINTERS) --deadline=10m --skip-files="generated.*\.go$\" --skip-dirs-use-default --skip-dirs=client,vendor
224+
225+
$(BUILD_DIRS):
226+
@mkdir -p $@
227+
228+
.PHONY: dev
229+
dev: gen fmt push
230+
231+
.PHONY: verify
232+
verify: verify-gen verify-modules
233+
234+
.PHONY: verify-modules
235+
verify-modules:
236+
GO111MODULE=on go mod tidy
237+
GO111MODULE=on go mod vendor
238+
@if !(git diff --exit-code HEAD); then \
239+
echo "go module files are out of date"; exit 1; \
240+
fi
241+
242+
.PHONY: verify-gen
243+
verify-gen: gen fmt
244+
@if !(git diff --exit-code HEAD); then \
245+
echo "generated files are out of date, run make gen"; exit 1; \
246+
fi
247+
248+
.PHONY: add-license
249+
add-license:
250+
@echo "Adding license header"
251+
@docker run --rm \
252+
-u $$(id -u):$$(id -g) \
253+
-v /tmp:/.cache \
254+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
255+
-w $(DOCKER_REPO_ROOT) \
256+
--env HTTP_PROXY=$(HTTP_PROXY) \
257+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
258+
$(BUILD_IMAGE) \
259+
ltag -t "./hack/license" --excludes "vendor contrib libbuild" -v
260+
261+
.PHONY: check-license
262+
check-license:
263+
@echo "Checking files for license header"
264+
@docker run --rm \
265+
-u $$(id -u):$$(id -g) \
266+
-v /tmp:/.cache \
267+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
268+
-w $(DOCKER_REPO_ROOT) \
269+
--env HTTP_PROXY=$(HTTP_PROXY) \
270+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
271+
$(BUILD_IMAGE) \
272+
ltag -t "./hack/license" --excludes "vendor contrib libbuild" --check -v
273+
274+
.PHONY: ci
275+
ci: verify check-license lint build unit-tests #cover
276+
277+
.PHONY: clean
278+
clean:
279+
rm -rf .go bin

vendor/go.bytebuilders.dev/license-verifier/kubernetes/apis/licenses/v1alpha1/doc.go renamed to vendor/go.bytebuilders.dev/license-verifier/apis/licenses/v1alpha1/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
// Package v1alpha1 is the v1alpha1 version of the API.
1818

1919
// +k8s:deepcopy-gen=package,register
20-
// +k8s:conversion-gen=go.bytebuilders.dev/license-verifier/kubernetes/apis/licenses
20+
// +k8s:conversion-gen=go.bytebuilders.dev/license-verifier/apis/licenses
2121
// +k8s:openapi-gen=true
2222
// +k8s:defaulter-gen=TypeMeta
2323

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20-
"go.bytebuilders.dev/license-verifier/kubernetes/apis/licenses"
20+
"go.bytebuilders.dev/license-verifier/apis/licenses"
2121

2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/apimachinery/pkg/runtime"

vendor/go.bytebuilders.dev/license-verifier/kubernetes/apis/licenses/v1alpha1/types.go renamed to vendor/go.bytebuilders.dev/license-verifier/apis/licenses/v1alpha1/types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ type License struct {
2828

2929
Issuer string `json:"issuer,omitempty"` // byte.builders
3030
Products []string `json:"products,omitempty"`
31-
Clusters []string `json:"clusters,omitempty"` // cluster_id ?
31+
Clusters []string `json:"clusters,omitempty"` // cluster_id ?
32+
User *User `json:"user,omitempty"`
3233
NotBefore *metav1.Time `json:"notBefore,omitempty"` // start of subscription start
3334
NotAfter *metav1.Time `json:"notAfter,omitempty"` // if set, use this
3435
ID string `json:"id,omitempty"` // license ID
3536
Status LicenseStatus `json:"status"`
3637
Reason string `json:"reason"`
3738
}
3839

40+
type User struct {
41+
Name string `json:"name"`
42+
Email string `json:"email"`
43+
}
44+
3945
type LicenseStatus string
4046

4147
const (
Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.bytebuilders.dev/license-verifier/go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ module go.bytebuilders.dev/license-verifier
33
go 1.14
44

55
require (
6+
github.com/gogo/protobuf v1.3.1
7+
github.com/golang/protobuf v1.4.3 // indirect
8+
github.com/json-iterator/go v1.1.10 // indirect
69
github.com/pkg/errors v0.9.1
10+
github.com/stretchr/testify v1.5.1 // indirect
11+
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
712
gomodules.xyz/sets v0.0.0-20200930152147-4f4543544799
13+
k8s.io/apimachinery v0.18.9
814
)

0 commit comments

Comments
 (0)