Skip to content

Commit

Permalink
wip: add config
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Feb 23, 2024
1 parent 62c10c0 commit 0ad8f76
Show file tree
Hide file tree
Showing 28 changed files with 6,550 additions and 25 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.DEFAULT_GOAL := build

GO ?= go
GO_RUN_TOOLS ?= $(GO) run -modfile ./tools/go.mod
GO_TEST = $(GO_RUN_TOOLS) gotest.tools/gotestsum --format pkgname
GO_RELEASER ?= $(GO_RUN_TOOLS) github.com/goreleaser/goreleaser
GO_MOD ?= $(shell ${GO} list -m)
GO_RUN_TOOLS ?= $(GO) run -modfile ./tools/go.mod
GO_TEST ?= $(GO_RUN_TOOLS) gotest.tools/gotestsum --format pkgname
GO_RELEASER ?= $(GO_RUN_TOOLS) github.com/goreleaser/goreleaser
GO_KO ?= $(GO_RUN_TOOLS) github.com/google/ko
GO_MOD ?= $(shell ${GO} list -m)
BASE_DIR ?= $(CURDIR)

.PHONY: build
build: ## Build the binary file.
Expand Down Expand Up @@ -40,6 +42,10 @@ clean: ## Remove previous build.
find . -type f -name '*.gen.go' -exec rm {} +
git checkout go.mod

.PHONY: deploy
deploy: ## Deploy the application.
$(GO_KO) resolve -f $(BASE_DIR)/config > $(BASE_DIR)/typhoon.yaml

.PHONY: help
help: ## Display this help screen.
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
11 changes: 11 additions & 0 deletions cmd/cloudeventssource-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/sources/adapter/cloudeventssource"
)

func main() {
adapter.Main("cloudevents", cloudeventssource.NewEnvConfig, cloudeventssource.NewAdapter)
}
11 changes: 11 additions & 0 deletions cmd/cloudeventstarget-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
pkgadapter "knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/targets/adapter/cloudeventstarget"
)

func main() {
pkgadapter.Main("cloudeventstarget", cloudeventstarget.EnvAccessorCtor, cloudeventstarget.NewTarget)
}
10 changes: 10 additions & 0 deletions cmd/filter-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"github.com/zeiss/typhoon/pkg/routing/adapter/common/sharedmain"
"github.com/zeiss/typhoon/pkg/routing/adapter/filter"
)

func main() {
sharedmain.MainWithController(filter.NewEnvConfig, filter.NewController, filter.NewAdapter)
}
11 changes: 11 additions & 0 deletions cmd/httppollersource-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/sources/adapter/httppollersource"
)

func main() {
adapter.Main("httppoller", httppollersource.NewEnvConfig, httppollersource.NewAdapter)
}
11 changes: 11 additions & 0 deletions cmd/httptarget-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
pkgadapter "knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/targets/adapter/httptarget"
)

func main() {
pkgadapter.Main("httptarget", httptarget.EnvAccessorCtor, httptarget.NewTarget)
}
11 changes: 11 additions & 0 deletions cmd/jqtransformation-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
pkgadapter "knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/flow/adapter/jqtransformation"
)

func main() {
pkgadapter.Main("jqtransformation", jqtransformation.EnvAccessorCtor, jqtransformation.NewAdapter)
}
11 changes: 11 additions & 0 deletions cmd/kafkasource-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/sources/adapter/kafkasource"
)

func main() {
adapter.Main("kafkasource", kafkasource.NewEnvConfig, kafkasource.NewAdapter)
}
11 changes: 11 additions & 0 deletions cmd/logztarget-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
pkgadapter "knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/targets/adapter/logztarget"
)

func main() {
pkgadapter.Main("logztarget", logztarget.EnvAccessorCtor, logztarget.NewTarget)
}
10 changes: 10 additions & 0 deletions cmd/splitter-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"github.com/zeiss/typhoon/pkg/routing/adapter/common/sharedmain"
"github.com/zeiss/typhoon/pkg/routing/adapter/splitter"
)

func main() {
sharedmain.MainWithController(splitter.NewEnvConfig, splitter.NewController, splitter.NewAdapter)
}
10 changes: 10 additions & 0 deletions cmd/synchronizer-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"github.com/zeiss/typhoon/pkg/flow/adapter/synchronizer"
pkgadapter "knative.dev/eventing/pkg/adapter/v2"
)

func main() {
pkgadapter.Main("synchronizer", synchronizer.EnvAccessorCtor, synchronizer.NewAdapter)
}
10 changes: 10 additions & 0 deletions cmd/transformation-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"github.com/zeiss/typhoon/pkg/flow/adapter/transformation"
pkgadapter "knative.dev/eventing/pkg/adapter/v2"
)

func main() {
pkgadapter.Main("transformation", transformation.NewEnvConfig, transformation.NewAdapter)
}
110 changes: 110 additions & 0 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package main

import (
"context"
"reflect"

"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/signals"
"knative.dev/pkg/webhook"
"knative.dev/pkg/webhook/certificates"
"knative.dev/pkg/webhook/resourcesemantics"
"knative.dev/pkg/webhook/resourcesemantics/defaulting"
"knative.dev/pkg/webhook/resourcesemantics/validation"

"github.com/zeiss/typhoon/pkg/apis/common/v1alpha1"
extensionsv1alpha1 "github.com/zeiss/typhoon/pkg/apis/extensions/v1alpha1"
flowv1alpha1 "github.com/zeiss/typhoon/pkg/apis/flow/v1alpha1"
routingv1alpha1 "github.com/zeiss/typhoon/pkg/apis/routing/v1alpha1"
sourcesv1alpha1 "github.com/zeiss/typhoon/pkg/apis/sources/v1alpha1"
targetsv1alpha1 "github.com/zeiss/typhoon/pkg/apis/targets/v1alpha1"
)

var (
validationTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{}
defaultingTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
sourcesv1alpha1.SchemeGroupVersion.WithKind("CloudEventsSource"): &sourcesv1alpha1.CloudEventsSource{},
routingv1alpha1.SchemeGroupVersion.WithKind("Filter"): &routingv1alpha1.Filter{},
flowv1alpha1.SchemeGroupVersion.WithKind("XSLTTransformation"): &flowv1alpha1.XSLTTransformation{},
}
)

// NewDefaultingAdmissionController returns defaulting webhook controller implementation.
func NewDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return defaulting.NewAdmissionController(ctx,
// Name of the resource webhook.
"defaulting.webhook.typhoon.zeiss.com",

// The path on which to serve the webhook.
"/defaulting",

// The resources to default.
defaultingTypes,

// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
func(ctx context.Context) context.Context {
return ctx
},

// Whether to disallow unknown fields.
true,
)
}

// NewValidationAdmissionController returns validation webhook controller implementation.
func NewValidationAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return validation.NewAdmissionController(ctx,
// Name of the resource webhook.
"validation.webhook.typhoon.zeiss.com",

// The path on which to serve the webhook.
"/validation",

// The resources to validate.
validationTypes,

// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
func(ctx context.Context) context.Context {
return ctx
},

// Whether to disallow unknown fields.
true,
)
}

func main() {
webhookName := webhook.NameFromEnv()

// Set up a signal context with our webhook options
ctx := webhook.WithOptions(signals.NewContext(), webhook.Options{
ServiceName: webhookName,
Port: webhook.PortFromEnv(8443),
SecretName: webhookName + "-certs",
})

registerValidationType(sourcesv1alpha1.SchemeGroupVersion, sourcesv1alpha1.AllTypes)
registerValidationType(targetsv1alpha1.SchemeGroupVersion, targetsv1alpha1.AllTypes)
registerValidationType(flowv1alpha1.SchemeGroupVersion, flowv1alpha1.AllTypes)
registerValidationType(extensionsv1alpha1.SchemeGroupVersion, extensionsv1alpha1.AllTypes)
registerValidationType(routingv1alpha1.SchemeGroupVersion, routingv1alpha1.AllTypes)

sharedmain.MainWithContext(ctx, webhookName,
certificates.NewController,
NewDefaultingAdmissionController,
NewValidationAdmissionController,
)
}

// registerValidationType registers components in the validation controller.
func registerValidationType(gv schema.GroupVersion, objects []v1alpha1.GroupObject) {
for _, object := range objects {
t := reflect.TypeOf(object.Single)
if admissible, ok := object.Single.(resourcesemantics.GenericCRD); ok {
validationTypes[gv.WithKind(t.Elem().Name())] = admissible
}
}
}
11 changes: 11 additions & 0 deletions cmd/webhooksource-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/sources/adapter/webhooksource"
)

func main() {
adapter.Main("webhook", webhooksource.NewEnvConfig, webhooksource.NewAdapter)
}
11 changes: 11 additions & 0 deletions cmd/xmltojsontransformation-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
pkgadapter "knative.dev/eventing/pkg/adapter/v2"

"github.com/zeiss/typhoon/pkg/flow/adapter/xmltojsontransformation"
)

func main() {
pkgadapter.Main("xmltojsontransformation", xmltojsontransformation.EnvAccessorCtor, xmltojsontransformation.NewAdapter)
}
59 changes: 59 additions & 0 deletions cmd/xslttransformation-adapter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# (!) Debian 11 'bullseye' must be used in both the builder and final image to
# ensure the compatibility of the GNU libc.
FROM golang:1.20-bullseye as builder

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends libxml2-dev libxslt1-dev liblzma-dev zlib1g-dev


WORKDIR /go/triggermesh

COPY . .
RUN go build -o /xslttransformation-adapter ./cmd/xslttransformation-adapter
# ldd /xslttransformation-adapter
# (i) Entries marked with a '*' are not included in the 'distroless:base' image.
# linux-vdso.so.1
# * libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2
# * libxslt.so.1 => /usr/lib/x86_64-linux-gnu/libxslt.so.1
# * libexslt.so.0 => /usr/lib/x86_64-linux-gnu/libexslt.so.0
# libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
# libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
# * libicuuc.so.67 => /usr/lib/x86_64-linux-gnu/libicuuc.so.67
# * libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
# * liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5
# libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
# * libgcrypt.so.20 => /usr/lib/x86_64-linux-gnu/libgcrypt.so.20
# /lib64/ld-linux-x86-64.so.2
# * libicudata.so.67 => /usr/lib/x86_64-linux-gnu/libicudata.so.67
# * libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
# * libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
# * libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0


FROM gcr.io/distroless/base-debian11:nonroot

# Ensure the /kodata entries used by Knative to augment the logger with the
# current VCS revision are present.
COPY --from=builder /go/triggermesh/.git/HEAD /go/triggermesh/.git/refs/ /kodata/
ENV KO_DATA_PATH=/kodata

# (!) COPY follows symlinks
COPY --from=builder \
/usr/lib/x86_64-linux-gnu/libxml2.so.2 \
/usr/lib/x86_64-linux-gnu/libxslt.so.1 \
/usr/lib/x86_64-linux-gnu/libexslt.so.0 \
/usr/lib/x86_64-linux-gnu/libicuuc.so.67 \
/lib/x86_64-linux-gnu/libz.so.1 \
/lib/x86_64-linux-gnu/liblzma.so.5 \
/usr/lib/x86_64-linux-gnu/libgcrypt.so.20 \
/usr/lib/x86_64-linux-gnu/libicudata.so.67 \
/usr/lib/x86_64-linux-gnu/libstdc++.so.6 \
/lib/x86_64-linux-gnu/libgcc_s.so.1 \
/lib/x86_64-linux-gnu/libgpg-error.so.0 \
/usr/lib/x86_64-linux-gnu/

COPY --from=builder /xslttransformation-adapter /

ENTRYPOINT ["/xslttransformation-adapter"]
18 changes: 18 additions & 0 deletions cmd/xslttransformation-adapter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
DOCKER ?= docker
PLATFORM ?= linux/amd64
GOALS := build tag push test

.PHONY: $(GOALS)

build:
$(DOCKER) build -t $(IMAGE_TAG) -f Dockerfile $(CONTEXT) --platform $(PLATFORM)

tag:
$(DOCKER) tag $(IMAGE_TAG) $(TAGS)

push:
$(DOCKER) push --all-tags $(IMAGE_TAG)

test:

.SILENT:
12 changes: 12 additions & 0 deletions cmd/xslttransformation-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !noclibs

package main

import (
"github.com/zeiss/typhoon/pkg/flow/adapter/xslttransformation"
pkgadapter "knative.dev/eventing/pkg/adapter/v2"
)

func main() {
pkgadapter.Main("xslttransformation", xslttransformation.EnvAccessorCtor, xslttransformation.NewTarget)
}
2 changes: 1 addition & 1 deletion config/300-ocimetricssource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
[
{
"type": "com.oracle.cloud.monitoring",
"schema": "https://raw.githubusercontent.com/typhoon/typhoon/main/schemas/com.oracle.cloud.monitoring.json",
"schema": "https://raw.githubusercontent.com/zeiss/typhoon/main/schemas/com.oracle.cloud.monitoring.json",
"description": ""
}
]
Expand Down
Loading

0 comments on commit 0ad8f76

Please sign in to comment.