Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 4 additions & 38 deletions Gopkg.lock

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

52 changes: 39 additions & 13 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ import (
"flag"
"log"

"github.com/knative/eventing/pkg/logconfig"
"github.com/knative/eventing/pkg/system"
"github.com/knative/eventing/pkg/webhook"
"github.com/knative/pkg/signals"
"go.uber.org/zap"

"github.com/knative/pkg/configmap"
"github.com/knative/pkg/logging"
"github.com/knative/pkg/logging/logkey"
"github.com/knative/pkg/signals"
"github.com/knative/pkg/webhook"

"go.uber.org/zap"
channelsv1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1"
feedsv1alpha1 "github.com/knative/eventing/pkg/apis/feeds/v1alpha1"
flowsv1alpha1 "github.com/knative/eventing/pkg/apis/flows/v1alpha1"
"github.com/knative/eventing/pkg/logconfig"
"github.com/knative/eventing/pkg/system"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

func main() {
flag.Parse()

// Read the logging config and setup a logger.
cm, err := configmap.Load("/etc/config-logging")
if err != nil {
Expand Down Expand Up @@ -72,15 +77,36 @@ func main() {
logger.Fatalf("failed to start webhook configmap watcher: %v", err)
}

// TODO(n3wscott): Send the logger to the controller.
options := webhook.ControllerOptions{
ServiceName: "eventing-webhook",
ServiceNamespace: system.Namespace,
Port: 443,
SecretName: "eventing-webhook-certs",
WebhookName: "webhook.eventing.knative.dev",
ServiceName: "webhook",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the name of the webhook service is likely to mean that anyone with the existing webhook installed is going to run with two webhooks until they delete the old one by hand.

Put this in "release notes" -- steal the format from knative/serving if we don't have it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, and made a PR to update our template: #357

DeploymentName: "webhook",
Namespace: system.Namespace,
Port: 443,
SecretName: "webhook-certs",
WebhookName: "webhook.eventing.knative.dev",
}
controller := webhook.AdmissionController{
Client: kubeClient,
Options: options,
Handlers: map[schema.GroupVersionKind]runtime.Object{
// For group channels.knative.dev,
channelsv1alpha1.SchemeGroupVersion.WithKind("Bus"): &channelsv1alpha1.Bus{},
channelsv1alpha1.SchemeGroupVersion.WithKind("ClusterBus"): &channelsv1alpha1.ClusterBus{},
channelsv1alpha1.SchemeGroupVersion.WithKind("Channel"): &channelsv1alpha1.Channel{},
channelsv1alpha1.SchemeGroupVersion.WithKind("Subscription"): &channelsv1alpha1.Subscription{},

// For group feeds.knative.dev,
feedsv1alpha1.SchemeGroupVersion.WithKind("EventSource"): &feedsv1alpha1.EventSource{},
feedsv1alpha1.SchemeGroupVersion.WithKind("ClusterEventSource"): &feedsv1alpha1.ClusterEventSource{},
feedsv1alpha1.SchemeGroupVersion.WithKind("EventType"): &feedsv1alpha1.EventType{},
feedsv1alpha1.SchemeGroupVersion.WithKind("ClusterEventType"): &feedsv1alpha1.ClusterEventType{},
feedsv1alpha1.SchemeGroupVersion.WithKind("Feed"): &feedsv1alpha1.Feed{},

// For group flows.knative.dev,
flowsv1alpha1.SchemeGroupVersion.WithKind("Flow"): &flowsv1alpha1.Flow{},
},
Logger: logger,
}
controller, err := webhook.NewAdmissionController(kubeClient, options)
if err != nil {
logger.Fatal("Failed to create the admission controller", zap.Error(err))
}
Expand Down
6 changes: 3 additions & 3 deletions config/400-webhook-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ apiVersion: v1
kind: Service
metadata:
labels:
role: eventing-webhook
name: eventing-webhook
role: webhook
name: webhook
namespace: knative-eventing
spec:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the Service and the Deployment for the webhook in separate files?

Can we combine these at the 400 level?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(But don't do this in this PR)

ports:
- port: 443
targetPort: 443
selector:
role: eventing-webhook
role: webhook
16 changes: 9 additions & 7 deletions config/500-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: eventing-webhook
name: webhook
namespace: knative-eventing
spec:
replicas: 1
template:
metadata:
annotations:
sidecar.istio.io/inject: "false"
labels:
app: eventing-webhook
role: eventing-webhook
app: webhook
role: webhook
spec:
serviceAccountName: eventing-controller
containers:
- name: eventing-webhook
- name: webhook
terminationMessagePolicy: FallbackToLogsOnError
# This is the Go import path for the binary that is containerized
# and substituted here.
image: github.com/knative/eventing/cmd/webhook
volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
- name: config-logging
mountPath: /etc/config-logging
volumes:
- name: config-logging
configMap:
name: config-logging
name: config-logging
15 changes: 15 additions & 0 deletions pkg/apis/channels/v1alpha1/bus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"

"github.com/knative/pkg/apis"
"github.com/knative/pkg/webhook"
kapi "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -40,10 +41,24 @@ type Bus struct {
Status BusStatus `json:"status,omitempty"`
}

// Check that Bus can be validated, can be defaulted, and has immutable fields.
var _ apis.Validatable = (*Bus)(nil)
var _ apis.Defaultable = (*Bus)(nil)
var _ apis.Immutable = (*Bus)(nil)
var _ runtime.Object = (*Bus)(nil)
var _ webhook.GenericCRD = (*Bus)(nil)

// BusSpec specifies the Bus' parameters for Channels and Subscriptions, how the
// provisioner and dispatcher for a bus should be run, and which volumes should
// be mounted into them.
type BusSpec struct {
// TODO: Generation does not work correctly with CRD. They are scrubbed
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
// So, we add Generation here. Once that gets fixed, remove this and use
// ObjectMeta.Generation instead.
// +optional
Generation int64 `json:"generation,omitempty"`

// Parameters defines the parameters that must be passed by this Bus'
// Channels and their Subscriptions. Channels and Subscriptions fulfill
// these parameters with Arguments.
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/channels/v1alpha1/channel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"encoding/json"

"github.com/knative/pkg/apis"
"github.com/knative/pkg/webhook"
"k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// +genclient
Expand All @@ -44,10 +46,19 @@ type Channel struct {
var _ apis.Validatable = (*Channel)(nil)
var _ apis.Defaultable = (*Channel)(nil)
var _ apis.Immutable = (*Channel)(nil)
var _ runtime.Object = (*Channel)(nil)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like you don't need this anymore?

var _ webhook.GenericCRD = (*Channel)(nil)

// ChannelSpec specifies the Bus backing a channel and the configuration
// arguments for the channel.
type ChannelSpec struct {
// TODO: Generation does not work correctly with CRD. They are scrubbed
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
// So, we add Generation here. Once that gets fixed, remove this and use
// ObjectMeta.Generation instead.
// +optional
Generation int64 `json:"generation,omitempty"`

// Name of the bus backing this channel (optional)
Bus string `json:"bus,omitempty"`

Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/channels/v1alpha1/clusterbus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ package v1alpha1
import (
"encoding/json"

"github.com/knative/pkg/apis"
"github.com/knative/pkg/webhook"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// +genclient
Expand All @@ -36,6 +39,13 @@ type ClusterBus struct {
Status ClusterBusStatus `json:"status,omitempty"`
}

// Check that Bus can be validated, can be defaulted, and has immutable fields.
var _ apis.Validatable = (*ClusterBus)(nil)
var _ apis.Defaultable = (*ClusterBus)(nil)
var _ apis.Immutable = (*ClusterBus)(nil)
var _ runtime.Object = (*ClusterBus)(nil)
var _ webhook.GenericCRD = (*ClusterBus)(nil)

// ClusterBusSpec (what the user wants) for a clusterbus
type ClusterBusSpec = BusSpec

Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/channels/v1alpha1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"encoding/json"

"github.com/knative/pkg/apis"
"github.com/knative/pkg/webhook"
"k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// +genclient
Expand All @@ -42,10 +44,19 @@ type Subscription struct {
var _ apis.Validatable = (*Subscription)(nil)
var _ apis.Defaultable = (*Subscription)(nil)
var _ apis.Immutable = (*Subscription)(nil)
var _ runtime.Object = (*Subscription)(nil)
var _ webhook.GenericCRD = (*ClusterBus)(nil)

// SubscriptionSpec specifies the Channel and Subscriber and the configuration
// arguments for the Subscription.
type SubscriptionSpec struct {
// TODO: Generation does not work correctly with CRD. They are scrubbed
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
// So, we add Generation here. Once that gets fixed, remove this and use
// ObjectMeta.Generation instead.
// +optional
Generation int64 `json:"generation,omitempty"`

// Channel is the name of the channel to subscribe to.
Channel string `json:"channel"`

Expand Down
Loading