This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Add core Reconciler testing and fake resolver framework functions #51
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# MacOS file viewer garbage. | ||
.DS_Store | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
||
# Emacs garbage | ||
*~ | ||
|
||
# Vim garbage | ||
*.swp | ||
|
||
# VSCode config | ||
.vscode | ||
|
||
# JetBrains IDE config | ||
.idea | ||
|
||
# Python | ||
*.pyc | ||
|
||
# Release-generated source archives, just in case they get committed | ||
# accidentally. | ||
cmd/*/kodata/source.tar.gz | ||
|
||
# binaries | ||
test/pullrequest/pullrequest-init | ||
/.bin/ | ||
/bin/ | ||
|
||
# Temporary GOPATH used during code gen if user's Tekton checkout is | ||
# not already in GOPATH. | ||
.gopath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
MODULE = $(shell env GO111MODULE=on $(GO) list -m) | ||
DATE ?= $(shell date +%FT%T%z) | ||
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \ | ||
cat $(CURDIR)/.version 2> /dev/null || echo v0) | ||
PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./... | grep -v 'github\.com\/tektoncd\/resolution\/third_party\/')) | ||
TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \ | ||
'{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \ | ||
$(PKGS)) | ||
BIN = $(CURDIR)/.bin | ||
|
||
GOLANGCI_VERSION = v1.42.0 | ||
|
||
GO = go | ||
TIMEOUT_UNIT = 5m | ||
TIMEOUT_E2E = 20m | ||
V = 0 | ||
Q = $(if $(filter 1,$V),,@) | ||
M = $(shell printf "\033[34;1m🐱\033[0m") | ||
|
||
export GO111MODULE=on | ||
|
||
COMMANDS=$(patsubst cmd/%,%,$(wildcard cmd/*)) | ||
BINARIES=$(addprefix bin/,$(COMMANDS)) | ||
|
||
.PHONY: all | ||
all: fmt $(BINARIES) | $(BIN) ; $(info $(M) building executable…) @ ## Build program binary | ||
|
||
$(BIN): | ||
@mkdir -p $@ | ||
$(BIN)/%: | $(BIN) ; $(info $(M) building $(PACKAGE)…) | ||
$Q tmp=$$(mktemp -d); \ | ||
env GO111MODULE=off GOPATH=$$tmp GOBIN=$(BIN) $(GO) get $(PACKAGE) \ | ||
|| ret=$$?; \ | ||
rm -rf $$tmp ; exit $$ret | ||
|
||
FORCE: | ||
|
||
bin/%: cmd/% FORCE | ||
$Q $(GO) build -mod=vendor $(LDFLAGS) -v -o $@ ./$< | ||
|
||
.PHONY: cross | ||
cross: amd64 arm arm64 s390x ppc64le ## build cross platform binaries | ||
|
||
.PHONY: amd64 | ||
amd64: | ||
GOOS=linux GOARCH=amd64 go build -mod=vendor $(LDFLAGS) ./cmd/... | ||
|
||
.PHONY: arm | ||
arm: | ||
GOOS=linux GOARCH=arm go build -mod=vendor $(LDFLAGS) ./cmd/... | ||
|
||
.PHONY: arm64 | ||
arm64: | ||
GOOS=linux GOARCH=arm64 go build -mod=vendor $(LDFLAGS) ./cmd/... | ||
|
||
.PHONY: s390x | ||
s390x: | ||
GOOS=linux GOARCH=s390x go build -mod=vendor $(LDFLAGS) ./cmd/... | ||
|
||
.PHONY: ppc64le | ||
ppc64le: | ||
GOOS=linux GOARCH=ppc64le go build -mod=vendor $(LDFLAGS) ./cmd/... | ||
|
||
KO = $(or ${KO_BIN},${KO_BIN},$(BIN)/ko) | ||
$(BIN)/ko: PACKAGE=github.com/google/ko | ||
|
||
.PHONY: apply | ||
apply: | $(KO) ; $(info $(M) ko apply -R -f config/) @ ## Apply config to the current cluster | ||
$Q $(KO) apply -R -f config | ||
|
||
.PHONY: apply-bundleresolver | ||
apply-bundleresolver: | $(KO) ; $(info $(M) ko apply -R -f bundleresolver/config/) @ ## Apply config to the current cluster | ||
$Q $(KO) apply -R -f bundleresolver/config | ||
|
||
.PHONY: apply-gitresolver | ||
apply-gitresolver: | $(KO) ; $(info $(M) ko apply -R -f gitresolver/config/) @ ## Apply config to the current cluster | ||
$Q $(KO) apply -R -f gitresolver/config | ||
|
||
.PHONY: apply-demoresolver | ||
apply-demoresolver: | $(KO) ; $(info $(M) ko apply -R -f docs/resolver-template/config/) @ ## Apply config to the current cluster | ||
$Q $(KO) apply -R -f docs/resolver-template/config | ||
|
||
.PHONY: apply-all-resolvers | ||
apply-all-resolvers: apply-bundleresolver apply-gitresolver apply-demoresolver | ||
|
||
.PHONY: resolve | ||
resolve: | $(KO) ; $(info $(M) ko resolve -R -f config/) @ ## Resolve config to the current cluster | ||
$Q $(KO) resolve --push=false --oci-layout-path=$(BIN)/oci -R -f config | ||
|
||
.PHONY: generated | ||
generated: | vendor ; $(info $(M) update generated files) ## Update generated files | ||
$Q ./hack/update-codegen.sh | ||
|
||
.PHONY: vendor | ||
vendor: | ||
$Q ./hack/update-deps.sh | ||
|
||
## Tests | ||
TEST_UNIT_TARGETS := test-unit-verbose test-unit-race | ||
test-unit-verbose: ARGS=-v | ||
test-unit-race: ARGS=-race | ||
$(TEST_UNIT_TARGETS): test-unit | ||
.PHONY: $(TEST_UNIT_TARGETS) test-unit | ||
test-unit: ## Run unit tests | ||
$(GO) test -timeout $(TIMEOUT_UNIT) $(ARGS) ./... | ||
|
||
TEST_E2E_TARGETS := test-e2e-short test-e2e-verbose test-e2e-race | ||
test-e2e-short: ARGS=-short | ||
test-e2e-verbose: ARGS=-v | ||
test-e2e-race: ARGS=-race | ||
$(TEST_E2E_TARGETS): test-e2e | ||
.PHONY: $(TEST_E2E_TARGETS) test-e2e | ||
test-e2e: ## Run end-to-end tests | ||
$(GO) test -timeout $(TIMEOUT_E2E) -tags e2e $(ARGS) ./test/... | ||
|
||
.PHONY: test-yamls | ||
test-yamls: ## Run yaml tests | ||
./test/e2e-tests-yaml.sh --run-tests | ||
|
||
.PHONY: check tests | ||
check tests: test-unit test-e2e test-yamls | ||
|
||
RAM = $(BIN)/ram | ||
$(BIN)/ram: PACKAGE=go.sbr.pm/ram | ||
|
||
.PHONY: watch-test | ||
watch-test: | $(RAM) ; $(info $(M) watch and run tests) @ ## Watch and run tests | ||
$Q $(RAM) -- -failfast | ||
|
||
.PHONY: watch-resolve | ||
watch-resolve: | $(KO) ; $(info $(M) watch and resolve config) @ ## Watch and build to the current cluster | ||
$Q $(KO) resolve -W --push=false --oci-layout-path=$(BIN)/oci -f config 1>/dev/null | ||
|
||
.PHONY: watch-config | ||
watch-config: | $(KO) ; $(info $(M) watch and apply config) @ ## Watch and apply to the current cluster | ||
$Q $(KO) apply -W -f config | ||
|
||
## Linters configuration and targets | ||
# TODO(vdemeester) gofmt and goimports checks (run them with -w and make a diff) | ||
|
||
GOLINT = $(BIN)/golint | ||
$(BIN)/golint: PACKAGE=golang.org/x/lint/golint | ||
|
||
.PHONY: golint | ||
golint: | $(GOLINT) ; $(info $(M) running golint…) @ ## Run golint | ||
$Q $(GOLINT) -set_exit_status $(PKGS) | ||
|
||
.PHONY: vet | ||
vet: | ; $(info $(M) running go vet…) @ ## Run go vet | ||
$Q go vet ./... | ||
|
||
INEFFASSIGN = $(BIN)/ineffassign | ||
$(BIN)/ineffassign: PACKAGE=github.com/gordonklaus/ineffassign | ||
|
||
.PHONY: ineffassign | ||
ineffassign: | $(INEFFASSIGN) ; $(info $(M) running static ineffassign…) @ ## Run ineffassign | ||
$Q $(INEFFASSIGN) . | ||
|
||
STATICCHECK = $(BIN)/staticcheck | ||
$(BIN)/staticcheck: PACKAGE=honnef.co/go/tools/cmd/staticcheck | ||
|
||
.PHONY: staticcheck | ||
staticcheck: | $(STATICCHECK) ; $(info $(M) running static check…) @ ## Run staticcheck | ||
$Q $(STATICCHECK) ./... | ||
|
||
DUPL = $(BIN)/dupl | ||
$(BIN)/dupl: PACKAGE=github.com/mibk/dupl | ||
|
||
.PHONY: dupl | ||
dupl: | $(DUPL) ; $(info $(M) running dupl…) ## Run dupl | ||
$Q $(DUPL) | ||
|
||
ERRCHECK = $(BIN)/errcheck | ||
$(BIN)/errcheck: PACKAGE=github.com/kisielk/errcheck | ||
|
||
.PHONY: errcheck | ||
errcheck: | $(ERRCHECK) ; $(info $(M) running errcheck…) ## Run errcheck | ||
$Q $(ERRCHECK) ./... | ||
|
||
GOLANGCILINT = $(BIN)/golangci-lint | ||
$(BIN)/golangci-lint: ; $(info $(M) getting golangci-lint $(GOLANGCI_VERSION)) | ||
cd tools; GOBIN=$(BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_VERSION) | ||
|
||
.PHONY: golangci-lint | ||
golangci-lint: | $(GOLANGCILINT) ; $(info $(M) running golangci-lint…) @ ## Run golangci-lint | ||
$Q $(GOLANGCILINT) run --modules-download-mode=vendor --max-issues-per-linter=0 --max-same-issues=0 --deadline 5m | ||
|
||
GOIMPORTS = $(BIN)/goimports | ||
$(BIN)/goimports: PACKAGE=golang.org/x/tools/cmd/goimports | ||
|
||
.PHONY: goimports | ||
goimports: | $(GOIMPORTS) ; $(info $(M) running goimports…) ## Run goimports | ||
$Q $(GOIMPORTS) -l -e -w pkg cmd test bundleresolver gitresolver docs/resolver-template | ||
|
||
.PHONY: fmt | ||
fmt: ; $(info $(M) running gofmt…) @ ## Run gofmt on all source files | ||
$Q $(GO) fmt $(PKGS) | ||
|
||
# Misc | ||
|
||
.PHONY: clean | ||
clean: ; $(info $(M) cleaning…) @ ## Cleanup everything | ||
@rm -rf $(BIN) | ||
@rm -rf bin | ||
@rm -rf test/tests.* test/coverage.* | ||
|
||
.PHONY: help | ||
help: | ||
@grep -hE '^[ a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ | ||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-17s\033[0m %s\n", $$1, $$2}' | ||
|
||
.PHONY: version | ||
version: | ||
|
||
@echo $(VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,69 +15,17 @@ package main | |
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/google/go-containerregistry/pkg/authn/k8schain" | ||
"github.com/tektoncd/resolution/bundleresolver/pkg/bundle" | ||
"github.com/tektoncd/resolution/pkg/common" | ||
"github.com/tektoncd/resolution/pkg/apis/resolution/v1alpha1" | ||
"github.com/tektoncd/resolution/pkg/resolver/framework" | ||
"k8s.io/client-go/kubernetes" | ||
kubeclient "knative.dev/pkg/client/injection/kube/client" | ||
filteredinformerfactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered" | ||
"knative.dev/pkg/injection/sharedmain" | ||
) | ||
|
||
// TODO(sbwsg): This should be exposed as a configurable option for | ||
// admins (e.g. via ConfigMap) | ||
const timeoutDuration = time.Minute | ||
|
||
func main() { | ||
sharedmain.Main("controller", | ||
framework.NewController(context.Background(), &resolver{}), | ||
ctx := filteredinformerfactory.WithSelectors(context.Background(), v1alpha1.ManagedByLabelKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why this didn't barf with |
||
sharedmain.MainWithContext(ctx, "controller", | ||
framework.NewController(ctx, &bundle.Resolver{}), | ||
) | ||
} | ||
|
||
type resolver struct { | ||
kubeClientSet kubernetes.Interface | ||
} | ||
|
||
// Initialize sets up any dependencies needed by the resolver. None atm. | ||
func (r *resolver) Initialize(ctx context.Context) error { | ||
r.kubeClientSet = kubeclient.Get(ctx) | ||
return nil | ||
} | ||
|
||
// GetName returns a string name to refer to this resolver by. | ||
func (r *resolver) GetName(context.Context) string { | ||
return "bundleresolver" | ||
} | ||
|
||
// GetSelector returns a map of labels to match requests to this resolver. | ||
func (r *resolver) GetSelector(context.Context) map[string]string { | ||
return map[string]string{ | ||
common.LabelKeyResolverType: "bundles", | ||
} | ||
} | ||
|
||
// ValidateParams ensures parameters from a request are as expected. | ||
func (r *resolver) ValidateParams(ctx context.Context, params map[string]string) error { | ||
if _, err := bundle.OptionsFromParams(params); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Resolve uses the given params to resolve the requested file or resource. | ||
func (r *resolver) Resolve(ctx context.Context, params map[string]string) (framework.ResolvedResource, error) { | ||
opts, err := bundle.OptionsFromParams(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
namespace := common.RequestNamespace(ctx) | ||
kc, err := k8schain.New(ctx, r.kubeClientSet, k8schain.Options{ | ||
Namespace: namespace, | ||
ServiceAccountName: opts.ServiceAccount, | ||
}) | ||
ctx, cancelFn := context.WithTimeout(ctx, timeoutDuration) | ||
defer cancelFn() | ||
return bundle.GetEntry(ctx, kc, opts) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What can I say, I like consistent
Makefile
s across projects I'm working on. =) This, like a number of other things I've called out, will go away once we merge Resolution into Pipeline.