Skip to content

Commit

Permalink
feat: Add HorizonSource (#416)
Browse files Browse the repository at this point in the history
Closes: #392
Signed-off-by: Michael Gasch <mgasch@vmware.com>
Signed-off-by: Michael Gasch <15986659+embano1@users.noreply.github.com>
  • Loading branch information
embano1 committed Jul 6, 2022
1 parent a9e79f6 commit f02e412
Show file tree
Hide file tree
Showing 112 changed files with 21,120 additions and 53 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ vSphere API from Kubernetes objects, e.g. a `Job`.

- `VSphereSource` to create VMware vSphere (vCenter) event sources
- `VSphereBinding` to inject VMware vSphere (vCenter) credentials
- `HorizonSource` to create VMware Horizon event sources

## Install Tanzu Sources for Knative
## Install Tanzu Sources CRDs for Knative

### Install via Release (`latest`)

Expand All @@ -38,15 +39,15 @@ Install the CRD providing the control / dataplane for the various `Sources` and

```shell
# define environment variables accordingly, e.g. when using kind
# export KIND_CLUSTER_NAME=horizon
# export KO_DOCKER_REPO=kind.local
export KIND_CLUSTER_NAME=vmware
export KO_DOCKER_REPO=kind.local

ko apply -BRf config
```

## Examples

To see examples of the Source and Binding in action, check out our
To see examples of the `Sources` and `Bindings` in action, check out our
[samples](./samples/README.md) directory.

## Basic `VSphereSource` Example
Expand Down Expand Up @@ -587,8 +588,8 @@ kubectl get vspheresource
NAME SOURCE SINK READY REASON
example-vc-source https://my-vc.corp.local http://broker-ingress.knative-eventing.svc.cluster.local/default/example-broker True
kubectl rollout restart deployment/example-vc-source-deployment
deployment.apps/example-vc-source-deployment restarted
kubectl rollout restart deployment/example-vc-source-adapter
deployment.apps/example-vc-source-adapter restarted
```

⚠️ **Note:** To avoid losing events due to this (brief) downtime, consider
Expand Down
1 change: 1 addition & 0 deletions cmd/horizon-adapter/kodata/HEAD
1 change: 1 addition & 0 deletions cmd/horizon-adapter/kodata/LICENSE
1 change: 1 addition & 0 deletions cmd/horizon-adapter/kodata/refs
20 changes: 20 additions & 0 deletions cmd/horizon-adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2022 VMware, Inc.
SPDX-License-Identifier: Apache-2.0
*/

package main

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

myadapter "github.com/vmware-tanzu/sources-for-knative/pkg/horizon"
)

const (
adapterName = "horizon-source-adapter"
)

func main() {
adapter.Main(adapterName, myadapter.NewEnv, myadapter.NewAdapter)
}
1 change: 1 addition & 0 deletions cmd/horizon-controller/kodata/HEAD
1 change: 1 addition & 0 deletions cmd/horizon-controller/kodata/LICENSE
1 change: 1 addition & 0 deletions cmd/horizon-controller/kodata/refs
22 changes: 22 additions & 0 deletions cmd/horizon-controller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2022 VMware, Inc.
SPDX-License-Identifier: Apache-2.0
*/

package main

import (
// The set of controllers this controller process runs.
"github.com/vmware-tanzu/sources-for-knative/pkg/reconciler/horizonsource"

// This defines the shared main for injected controllers.
"knative.dev/pkg/injection/sharedmain"
)

const (
controllerName = "horizon-source-controller"
)

func main() {
sharedmain.Main(controllerName, horizonsource.NewController)
}
1 change: 1 addition & 0 deletions cmd/horizon-webhook/kodata/HEAD
1 change: 1 addition & 0 deletions cmd/horizon-webhook/kodata/LICENSE
1 change: 1 addition & 0 deletions cmd/horizon-webhook/kodata/refs
122 changes: 122 additions & 0 deletions cmd/horizon-webhook/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
Copyright 2022 VMware, Inc.
SPDX-License-Identifier: Apache-2.0
*/

package main

import (
"context"

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

"github.com/vmware-tanzu/sources-for-knative/pkg/apis/sources/v1alpha1"
)

var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
// List the types to validate
v1alpha1.SchemeGroupVersion.WithKind("HorizonSource"): &v1alpha1.HorizonSource{},
}

var callbacks = map[schema.GroupVersionKind]validation.Callback{}

const admissionWebhookName = "horizon-source-webhook"

// NewDefaultingAdmissionController sets up mutating webhook.
func NewDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return defaulting.NewAdmissionController(ctx,

// Name of the resource webhook.
"defaulting.webhook.horizon.sources.tanzu.vmware.com",

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

// The resource to default.
types,

// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
func(ctx context.Context) context.Context {
// Here is where you would infuse the context with state
// (e.g. attach a store with configmap data)
return ctx
},

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

// NewValidationAdmissionController sets up validation webhook.
func NewValidationAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return validation.NewAdmissionController(ctx,

// Name of the resource webhook.
"validation.webhook.horizon.sources.tanzu.vmware.com",

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

// The resources to validate.
types,

// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
func(ctx context.Context) context.Context {
// Here is where you would infuse the context with state
// (e.g. attach a store with configmap data)
return ctx
},

// Whether to disallow unknown fields.
true,

// Extra validating callbacks to be applied to resources.
callbacks,
)
}

// NewConfigValidationController sets up ConfigMap validation webhook.
func NewConfigValidationController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return configmaps.NewAdmissionController(ctx,

// Name of the configmap webhook.
"config.webhook.horizon.sources.tanzu.vmware.com",

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

// The configmaps to validate.
configmap.Constructors{
logging.ConfigMapName(): logging.NewConfigFromConfigMap,
metrics.ConfigMapName(): metrics.NewObservabilityConfigFromConfigMap,
},
)
}

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

sharedmain.WebhookMainWithContext(ctx, admissionWebhookName,
certificates.NewController,
NewDefaultingAdmissionController,
NewValidationAdmissionController,
NewConfigValidationController,
)
}
6 changes: 5 additions & 1 deletion cmd/vsphere-adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import (
"github.com/vmware-tanzu/sources-for-knative/pkg/vsphere"
)

const (
adapterName = "vsphere-source-adapter"
)

func main() {
ctx := signals.NewContext()
kc := kubernetes.NewForConfigOrDie(injection.ParseAndGetRESTConfigOrDie())
ctx = context.WithValue(ctx, kubeclient.Key{}, kc)
adapter.MainWithContext(ctx, "vspheresource", vsphere.NewEnvConfig, vsphere.NewAdapter)
adapter.MainWithContext(ctx, adapterName, vsphere.NewEnvConfig, vsphere.NewAdapter)
}
4 changes: 3 additions & 1 deletion cmd/vsphere-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
v1alpha1.SchemeGroupVersion.WithKind("VSphereBinding"): &v1alpha1.VSphereBinding{},
}

const admissionWebhookName = "vsphere-source-webhook"
const (
admissionWebhookName = "vsphere-source-webhook"
)

func NewDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return defaulting.NewAdmissionController(ctx,
Expand Down
20 changes: 20 additions & 0 deletions config/200-horizon-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

apiVersion: v1
kind: ServiceAccount
metadata:
name: horizon-source-controller
namespace: vmware-sources
labels:
sources.tanzu.vmware.com/release: devel

---

apiVersion: v1
kind: ServiceAccount
metadata:
name: horizon-source-webhook
namespace: vmware-sources
labels:
sources.tanzu.vmware.com/release: devel
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 VMware, Inc.
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

kind: ClusterRole
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 VMware, Inc.
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

# Use this aggregated ClusterRole when you need readonly access to "podspecables
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 VMware, Inc.
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

apiVersion: v1
Expand Down
96 changes: 96 additions & 0 deletions config/201-horizon-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: horizon-source-controller
labels:
sources.tanzu.vmware.com/release: devel
rules:
- apiGroups:
- apps
resources:
- deployments
verbs: &everything
- get
- list
- watch
- create
- update
- patch
- delete

- apiGroups:
- rbac.authorization.k8s.io
resources:
- clusterroles
verbs:
- list

- apiGroups:
- ""
resources:
- events
verbs: *everything

- apiGroups:
- sources.tanzu.vmware.com
resources:
- horizonsources
verbs: *everything

- apiGroups:
- sources.tanzu.vmware.com
resources:
- horizonsources/status
- horizonsources/finalizers
verbs:
- get
- update
- patch

- apiGroups:
- ""
resources:
- configmaps
- secrets
verbs:
- get
- list
- watch

# manage adapter SAs
- apiGroups:
- ""
resources:
- serviceaccounts
verbs: *everything


# For Leader Election
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs: *everything

---
# The role is needed for the aggregated role source-observer in knative-eventing to provide readonly access to "Sources".
# See https://github.com/knative/eventing/blob/master/config/200-source-observer-clusterrole.yaml.
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: horizon-source-observer
labels:
sources.tanzu.vmware.com/release: devel
duck.knative.dev/source: "true"
rules:
- apiGroups:
- "sources.eventing.knative.dev"
resources:
- "horizonsources"
verbs:
- get
- list
- watch

0 comments on commit f02e412

Please sign in to comment.