Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 804b64e

Browse files
author
odacremolbap
committed
kn style controller
1 parent d84174a commit 804b64e

File tree

93 files changed

+8583
-13
lines changed

Some content is hidden

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

93 files changed

+8583
-13
lines changed

.gitignore

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
# Binaries for programs and plugins
2-
*.exe
3-
*.exe~
4-
*.dll
5-
*.so
6-
*.dylib
7-
8-
# Test binary, built with `go test -c`
9-
*.test
1+
# Local configurations and secrets
2+
/.env/
3+
/.local/
4+
5+
# Editors and IDEs
6+
*.swo
7+
*.swp
8+
*~
9+
/*.sublime-project
10+
/*.sublime-workspace
11+
/.idea/
12+
/.vscode/
13+
14+
# OS Artifacts
15+
.DS_Store
1016

11-
# Output of the go coverage tool, specifically when used with LiteIDE
12-
*.out
17+
# GNU patch
18+
*.orig
19+
*.rej
1320

14-
# Dependency directories (remove the comment below to include it)
15-
# vendor/
21+
# Build artifacts
22+
/_output/
23+
24+
# Test artifacts
25+
*.test

EULA.pdf

134 KB
Binary file not shown.

Makefile

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Copyright 2022 TriggerMesh Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
KREPO = triggermesh-core
5+
KREPO_DESC = TriggerMesh Core Components (broker, triggers)
6+
7+
BASE_DIR ?= $(CURDIR)
8+
OUTPUT_DIR ?= $(BASE_DIR)/_output
9+
10+
# Dynamically generate the list of commands based on the directory name cited in the cmd directory
11+
COMMANDS := $(notdir $(wildcard cmd/*))
12+
13+
# Commands and images that require custom build proccess
14+
CUSTOM_BUILD_BINARIES :=
15+
CUSTOM_BUILD_IMAGES :=
16+
17+
BIN_OUTPUT_DIR ?= $(OUTPUT_DIR)
18+
DOCS_OUTPUT_DIR ?= $(OUTPUT_DIR)
19+
TEST_OUTPUT_DIR ?= $(OUTPUT_DIR)
20+
COVER_OUTPUT_DIR ?= $(OUTPUT_DIR)
21+
DIST_DIR ?= $(OUTPUT_DIR)
22+
23+
# Rely on ko for building/publishing images and generating/deploying manifests
24+
KO ?= ko
25+
KOFLAGS ?=
26+
IMAGE_TAG ?= $(shell git rev-parse HEAD)
27+
28+
# Go build variables
29+
GO ?= go
30+
GOFMT ?= gofmt
31+
GOLINT ?= golangci-lint run --timeout 5m
32+
GOTOOL ?= go tool
33+
GOTEST ?= gotestsum --junitfile $(TEST_OUTPUT_DIR)/$(KREPO)-unit-tests.xml --format pkgname-and-test-fails --
34+
35+
GOMODULE = github.com/triggermesh/triggermesh-core
36+
37+
GOPKGS = ./cmd/... ./pkg/apis/... ./pkg/reconciler/...
38+
GOPKGS_SKIP_TESTS =
39+
40+
# List of packages that expect the environment to have installed
41+
# the dependencies for running tests:
42+
#
43+
# ...
44+
#
45+
GOPKGS_TESTS_WITH_DEPENDENCIES =
46+
47+
# This environment variable should be set when dependencies have been installed
48+
# at the running instance.
49+
WITH_DEPENDENCIES ?=
50+
51+
LDFLAGS = -w -s
52+
LDFLAGS_STATIC = $(LDFLAGS) -extldflags=-static
53+
54+
HAS_GOTESTSUM := $(shell command -v gotestsum;)
55+
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
56+
57+
SED := sed -i
58+
59+
OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
60+
ifeq ($(OS),$(filter $(OS),Darwin FreeBSD NetBSD))
61+
SED += ''
62+
endif
63+
64+
.PHONY: help all build release vm-images test lint fmt fmt-test images clean install-gotestsum install-golangci-lint deploy undeploy
65+
66+
.DEFAULT_GOAL := build
67+
68+
all: codegen build test lint
69+
70+
# Verify lint and tests
71+
install-gotestsum:
72+
ifndef HAS_GOTESTSUM
73+
curl -SL https://github.com/gotestyourself/gotestsum/releases/download/v1.8.0/gotestsum_1.8.0_linux_amd64.tar.gz | tar -C $(shell go env GOPATH)/bin -zxf -
74+
endif
75+
76+
install-golangci-lint:
77+
ifndef HAS_GOLANGCI_LINT
78+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.45.2
79+
endif
80+
81+
help: ## Display this help
82+
@awk 'BEGIN {FS = ":.*?## "; printf "\n$(KREPO_DESC)\n\nUsage:\n make \033[36m<cmd>\033[0m\n"} /^[a-zA-Z0-9._-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
83+
84+
build: $(COMMANDS) ## Build all artifacts
85+
86+
$(filter-out $(CUSTOM_BUILD_BINARIES), $(COMMANDS)): ## Build artifact
87+
$(GO) build -ldflags "$(LDFLAGS_STATIC)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@
88+
89+
confluenttarget-adapter:
90+
CGO_ENABLED=1 $(GO) build -ldflags "$(LDFLAGS_STATIC)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@
91+
92+
dataweavetransformation-adapter: ## Builds DataWeave
93+
$(GO) build -ldflags "$(LDFLAGS)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@
94+
95+
deploy: ## Deploy TriggerMesh stack to default Kubernetes cluster
96+
$(KO) resolve -f $(BASE_DIR)/config > $(BASE_DIR)/triggermesh-$(IMAGE_TAG).yaml
97+
@for component in $(CUSTOM_BUILD_IMAGES); do \
98+
$(MAKE) -C ./cmd/$$component build CONTEXT=$(BASE_DIR) IMAGE_TAG=$(KO_DOCKER_REPO)/$$component-$(IMAGE_TAG) && \
99+
$(MAKE) -C ./cmd/$$component push IMAGE_TAG=$(KO_DOCKER_REPO)/$$component-$(IMAGE_TAG) && \
100+
$(SED) 's|value: .*'$$component'.*|value: $(KO_DOCKER_REPO)/'$$component'-$(IMAGE_TAG)|g' $(BASE_DIR)/triggermesh-$(IMAGE_TAG).yaml || exit 1; \
101+
done
102+
103+
$(KO) apply -f $(BASE_DIR)/triggermesh-$(IMAGE_TAG).yaml
104+
@rm $(BASE_DIR)/triggermesh-$(IMAGE_TAG).yaml
105+
106+
undeploy: ## Remove TriggerMesh stack from default Kubernetes cluster
107+
$(KO) delete -f $(BASE_DIR)/config
108+
109+
vm-images:
110+
@$(MAKE) -C packer/
111+
112+
release: ## Publish container images and generate release manifests
113+
@mkdir -p $(DIST_DIR)
114+
$(KO) resolve -f config/ -l 'triggermesh.io/crd-install' > $(DIST_DIR)/triggermesh-crds.yaml
115+
@cp config/namespace/100-namespace.yaml $(DIST_DIR)/triggermesh.yaml
116+
$(KO) resolve $(KOFLAGS) -B -t latest -f config/ -l '!triggermesh.io/crd-install' > /dev/null
117+
$(KO) resolve $(KOFLAGS) -B -t $(IMAGE_TAG) --tag-only -f config/ -l '!triggermesh.io/crd-install' >> $(DIST_DIR)/triggermesh.yaml
118+
119+
@for component in $(CUSTOM_BUILD_IMAGES); do \
120+
$(MAKE) -C ./cmd/$$component build CONTEXT=$(BASE_DIR) IMAGE_TAG=$(KO_DOCKER_REPO)/$$component:$(IMAGE_TAG) && \
121+
$(MAKE) -C ./cmd/$$component tag IMAGE_TAG=$(KO_DOCKER_REPO)/$$component:$(IMAGE_TAG) TAGS=$(KO_DOCKER_REPO)/$$component:latest && \
122+
$(MAKE) -C ./cmd/$$component push IMAGE_TAG=$(KO_DOCKER_REPO)/$$component && \
123+
$(SED) 's/'$$component':.*/'$$component':$(IMAGE_TAG)/g' $(DIST_DIR)/triggermesh.yaml || exit 1; \
124+
done
125+
126+
gen-apidocs: ## Generate API docs
127+
GOPATH="" OUTPUT_DIR=$(DOCS_OUTPUT_DIR) ./hack/gen-api-reference-docs.sh
128+
129+
130+
GOPKGS_LIST ?= $(filter-out $(GOPKGS_SKIP_TESTS), $(shell go list $(GOPKGS)))
131+
ifdef WITH_DEPENDENCIES
132+
GOPKGS_LIST += $(GOPKGS_TESTS_WITH_DEPENDENCIES)
133+
endif
134+
test: install-gotestsum ## Run unit tests
135+
@mkdir -p $(TEST_OUTPUT_DIR)
136+
137+
$(GOTEST) -p=1 -race -cover -coverprofile=$(TEST_OUTPUT_DIR)/$(KREPO)-c.out $(GOPKGS_LIST)
138+
139+
@for component in $(CUSTOM_BUILD_IMAGES); do \
140+
$(MAKE) -C ./cmd/$$component test || exit 1; \
141+
done
142+
143+
cover: test ## Generate code coverage
144+
@mkdir -p $(COVER_OUTPUT_DIR)
145+
$(GOTOOL) cover -html=$(TEST_OUTPUT_DIR)/$(KREPO)-c.out -o $(COVER_OUTPUT_DIR)/$(KREPO)-coverage.html
146+
147+
lint: install-golangci-lint ## Lint source files
148+
$(GOLINT) $(GOPKGS) ./test/...
149+
150+
fmt: ## Format source files
151+
$(GOFMT) -s -w $(shell $(GO) list -f '{{$$d := .Dir}}{{range .GoFiles}}{{$$d}}/{{.}} {{end}} {{$$d := .Dir}}{{range .TestGoFiles}}{{$$d}}/{{.}} {{end}}' $(GOPKGS))
152+
153+
fmt-test: ## Check source formatting
154+
@test -z $(shell $(GOFMT) -l $(shell $(GO) list -f '{{$$d := .Dir}}{{range .GoFiles}}{{$$d}}/{{.}} {{end}} {{$$d := .Dir}}{{range .TestGoFiles}}{{$$d}}/{{.}} {{end}}' $(GOPKGS)))
155+
156+
KO_PUBLISHABLE = $(filter-out $(CUSTOM_BUILD_IMAGES), $(COMMANDS))
157+
KO_IMAGES = $(foreach cmd,$(KO_PUBLISHABLE),$(cmd).image)
158+
CUSTOM_IMAGES = $(foreach cmd,$(CUSTOM_BUILD_IMAGES),$(cmd).image)
159+
160+
images: $(KO_IMAGES) $(CUSTOM_IMAGES) ## Build container images
161+
$(KO_IMAGES): %.image:
162+
$(KO) publish --push=false -B --tag-only -t $(IMAGE_TAG) ./cmd/$*
163+
164+
$(CUSTOM_IMAGES): %.image:
165+
@$(MAKE) -C ./cmd/$* image CONTEXT=$(BASE_DIR) IMAGE_TAG=$(KO_DOCKER_REPO)/$*:$(IMAGE_TAG)
166+
167+
clean: ## Clean build artifacts
168+
@for bin in $(COMMANDS) ; do \
169+
$(RM) -v $(BIN_OUTPUT_DIR)/$$bin; \
170+
done
171+
@$(RM) -v $(DIST_DIR)/triggermesh-crds.yaml $(DIST_DIR)/triggermesh.yaml
172+
@$(RM) -v $(TEST_OUTPUT_DIR)/$(KREPO)-c.out $(TEST_OUTPUT_DIR)/$(KREPO)-unit-tests.xml
173+
@$(RM) -v $(COVER_OUTPUT_DIR)/$(KREPO)-coverage.html
174+
175+
# Code generation
176+
include $(BASE_DIR)/hack/inc.Codegen.mk

cmd/core-controller/kodata/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../.git/HEAD

cmd/core-controller/kodata/refs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../.git/refs

cmd/core-controller/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"knative.dev/pkg/injection/sharedmain"
5+
6+
"github.com/triggermesh/triggermesh-core/pkg/reconciler/redisbroker"
7+
)
8+
9+
func main() {
10+
sharedmain.Main("core-controller", redisbroker.NewController)
11+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2022 TriggerMesh Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
kind: ClusterRole
5+
apiVersion: rbac.authorization.k8s.io/v1
6+
metadata:
7+
name: triggermesh-core-namespaced-admin
8+
labels:
9+
rbac.authorization.k8s.io/aggregate-to-admin: "true"
10+
app.kubernetes.io/part-of: triggermesh
11+
rules:
12+
- apiGroups:
13+
- eventing.triggermesh.io
14+
resources: ["*"]
15+
verbs: ["*"]
16+
---
17+
kind: ClusterRole
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
metadata:
20+
name: triggermesh-core-namespaced-edit
21+
labels:
22+
rbac.authorization.k8s.io/aggregate-to-edit: "true"
23+
app.kubernetes.io/part-of: triggermesh
24+
rules:
25+
- apiGroups:
26+
- eventing.triggermesh.io
27+
resources: ["*"]
28+
verbs:
29+
- create
30+
- update
31+
- patch
32+
- delete
33+
---
34+
kind: ClusterRole
35+
apiVersion: rbac.authorization.k8s.io/v1
36+
metadata:
37+
name: triggermesh-core-namespaced-view
38+
labels:
39+
rbac.authorization.k8s.io/aggregate-to-view: "true"
40+
app.kubernetes.io/part-of: triggermesh
41+
rules:
42+
- apiGroups:
43+
- eveinting.triggermesh.io
44+
resources: ["*"]
45+
verbs:
46+
- get
47+
- list
48+
- watch

0 commit comments

Comments
 (0)