Skip to content

Commit

Permalink
wip: add nats target
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Feb 28, 2024
1 parent c062a7a commit ae4cc16
Show file tree
Hide file tree
Showing 26 changed files with 1,964 additions and 2 deletions.
11 changes: 11 additions & 0 deletions cmd/natstarget-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/natstarget"
)

func main() {
pkgadapter.Main("natstarget", natstarget.EnvAccessorCtor, natstarget.NewTarget)
}
4 changes: 2 additions & 2 deletions cmd/xslttransformation-adapter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN set -eux; \
apt-get install -y --no-install-recommends libxml2-dev libxslt1-dev liblzma-dev zlib1g-dev


WORKDIR /go/triggermesh
WORKDIR /go/typhoon

COPY . .
RUN go build -o /xslttransformation-adapter ./cmd/xslttransformation-adapter
Expand Down Expand Up @@ -36,7 +36,7 @@ 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/
COPY --from=builder /go/typhoon/.git/HEAD /go/typhoon/.git/refs/ /kodata/
ENV KO_DATA_PATH=/kodata

# (!) COPY follows symlinks
Expand Down
372 changes: 372 additions & 0 deletions config/301-natstarget.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/katallaxie/pkg v0.5.12
github.com/kelseyhightower/envconfig v1.4.0
github.com/logzio/logzio-go v1.0.6
github.com/nats-io/nats.go v1.33.1
github.com/oapi-codegen/fiber-middleware v1.0.1
github.com/oapi-codegen/runtime v1.1.1
github.com/sethvargo/go-limiter v0.7.2
Expand Down Expand Up @@ -206,6 +207,8 @@ require (
github.com/moricho/tparallel v0.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nakabonne/nestif v0.3.1 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/nishanths/exhaustive v0.11.0 // indirect
github.com/nishanths/predeclared v0.2.2 // indirect
github.com/nunnatsa/ginkgolinter v0.14.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,12 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/nakabonne/nestif v0.3.1 h1:wm28nZjhQY5HyYPx+weN3Q65k6ilSBxDb8v5S81B81U=
github.com/nakabonne/nestif v0.3.1/go.mod h1:9EtoZochLn5iUprVDmDjqGKPofoUEBL8U4Ngq6aY7OE=
github.com/nats-io/nats.go v1.33.1 h1:8TxLZZ/seeEfR97qV0/Bl939tpDnt2Z2fK3HkPypj70=
github.com/nats-io/nats.go v1.33.1/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nishanths/exhaustive v0.11.0 h1:T3I8nUGhl/Cwu5Z2hfc92l0e04D2GEW6e0l8pzda2l0=
github.com/nishanths/exhaustive v0.11.0/go.mod h1:RqwDsZ1xY0dNdqHho2z6X+bgzizwbLYOWnZbbl2wLB4=
Expand Down
49 changes: 49 additions & 0 deletions pkg/apis/targets/v1alpha1/nats_lifecycle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package v1alpha1

import (
"context"

"k8s.io/apimachinery/pkg/runtime/schema"

"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"

"github.com/zeiss/typhoon/pkg/apis/common/v1alpha1"
)

// GetGroupVersionKind implements kmeta.OwnerRefable.
func (*NatsTarget) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("KafkaTarget")
}

// GetConditionSet implements duckv1.KRShaped.
func (*NatsTarget) GetConditionSet() apis.ConditionSet {
return v1alpha1.DefaultConditionSet
}

// GetStatus implements duckv1.KRShaped.
func (t *NatsTarget) GetStatus() *duckv1.Status {
return &t.Status.Status
}

// GetStatusManager implements Reconcilable.
func (t *NatsTarget) GetStatusManager() *v1alpha1.StatusManager {
return &v1alpha1.StatusManager{
ConditionSet: t.GetConditionSet(),
Status: &t.Status,
}
}

// GetAdapterOverrides implements AdapterConfigurable.
func (t *NatsTarget) GetAdapterOverrides() *v1alpha1.AdapterOverrides {
return t.Spec.AdapterOverrides
}

// SetDefaults implements apis.Defaultable
func (t *NatsTarget) SetDefaults(ctx context.Context) {
}

// Validate implements apis.Validatable
func (t *NatsTarget) Validate(ctx context.Context) *apis.FieldError {
return nil
}
49 changes: 49 additions & 0 deletions pkg/apis/targets/v1alpha1/nats_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/zeiss/typhoon/pkg/apis/common/v1alpha1"
)

// +genclient
// +genreconciler
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NatsTarget is the Schema for an NatsTarget.
type NatsTarget struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NatsTargetSpec `json:"spec"`
Status v1alpha1.Status `json:"status,omitempty"`
}

// Check the interfaces the event target should be implementing.
var (
_ v1alpha1.Reconcilable = (*NatsTarget)(nil)
_ v1alpha1.AdapterConfigurable = (*NatsTarget)(nil)
)

// NatsTargetSpec defines the desired state of the event target.
type NatsTargetSpec struct {
// Subject where messages are produced.
Subject string `json:"subject"`

// URL of the Nats server.
URL string `json:"url"`

// Adapter spec overrides parameters.
// +optional
AdapterOverrides *v1alpha1.AdapterOverrides `json:"adapterOverrides,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NatsTargetList is a list of event target instances.
type NatsTargetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []NatsTarget `json:"items"`
}
82 changes: 82 additions & 0 deletions pkg/apis/targets/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae4cc16

Please sign in to comment.