Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create v1beta1 brokers, use context for defaulting #2651

Merged
merged 6 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
OMG... really???
  • Loading branch information
vaikas committed Feb 26, 2020
commit 528814977671685f6359ead39cb8b883ee0c137d
14 changes: 9 additions & 5 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ func NewDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher
store.WatchConfigs(cmw)

logger := logging.FromContext(ctx)
logger.Infof("GOT STORE AS: %+v %#v", store, store)

// Decorate contexts with the current state of the config.
ctxFunc := func(ctx context.Context) context.Context {
// return v1beta1.WithDefaultBrokerConfigs(store.ToContext(ctx))
return store.ToContext(ctx)
}

Expand Down Expand Up @@ -227,6 +225,14 @@ func NewLegacySinkBindingWebhook(ctx context.Context, cmw configmap.Watcher) *co
}

func NewConversionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
// Decorate contexts with the current state of the config.
store := defaultconfig.NewStore(logging.FromContext(ctx).Named("config-store"))
store.WatchConfigs(cmw)
// Decorate contexts with the current state of the config.
ctxFunc := func(ctx context.Context) context.Context {
return store.ToContext(ctx)
}

var (
eventingv1alpha1_ = eventingv1alpha1.SchemeGroupVersion.Version
eventingv1beta1_ = eventingv1beta1.SchemeGroupVersion.Version
Expand Down Expand Up @@ -331,9 +337,7 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro
},

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

Expand Down
8 changes: 1 addition & 7 deletions pkg/apis/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ func NewDefaultsConfigFromMap(data map[string]string) (*Defaults, error) {
if !present || value == "" {
return nil, fmt.Errorf("ConfigMap is missing (or empty) key: %q : %v", BrokerDefaultsKey, data)
}
if err := parseEntry(value, &nc); err != nil {
if err := parseEntry(value, nc); err != nil {
return nil, fmt.Errorf("Failed to parse the entry: %s", err)
}
fmt.Printf("GOT DEFAULTS AS: %+v %#v", nc, nc)
fmt.Printf("GOT DEFAULTS AS: %+v %#v", nc.ClusterDefault, nc.ClusterDefault)
return nc, nil
}

Expand Down Expand Up @@ -85,18 +83,14 @@ type Defaults struct {
// return an error.
func (d *Defaults) GetBrokerConfig(ns string) (*duckv1.KReference, error) {
if d == nil {
fmt.Printf("GETBROKERCONFIG DEFAULTS NIL")
return nil, errors.New("Defaults are nil")
}
value, present := d.NamespaceDefaultsConfig[ns]
if present {
fmt.Printf("GETBROKERCONFIG FOUND VALUE: %+v", value)
return value, nil
}
if d.ClusterDefault != nil {
fmt.Printf("GETBROKERCONFIG FOUND CLUSTERDEFAULT: %+v", value)
return d.ClusterDefault, nil
}
fmt.Printf("GETBROKERCONFIG SHIT:")
return nil, errors.New("Defaults for Broker Configurations have not been set up.")
}
6 changes: 1 addition & 5 deletions pkg/apis/eventing/v1beta1/broker_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ package v1beta1

import (
"context"
"fmt"

"knative.dev/eventing/pkg/apis/config"
"knative.dev/pkg/apis"
)

func (b *Broker) SetDefaults(ctx context.Context) {
// TODO(vaikas): Set the default class annotation if not specified
fmt.Printf("GOT CONTEXT AS: %+v %#v", ctx, ctx)
withNS := apis.WithinParent(ctx, b.ObjectMeta)
b.Spec.SetDefaults(withNS)
}
Expand All @@ -37,10 +35,8 @@ func (bs *BrokerSpec) SetDefaults(ctx context.Context) {
}

cfg := config.FromContextOrDefaults(ctx)
fmt.Printf("GOT CONFIG AS: %+v", cfg)
fmt.Printf("GOT CONTEXT AS: %+v %#v", ctx, ctx)
c, err := cfg.Defaults.GetBrokerConfig(apis.ParentMeta(ctx).Namespace)
if err != nil {
if err == nil {
bs.Config = c
}
}
2 changes: 1 addition & 1 deletion pkg/apis/eventing/v1beta1/broker_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
)

func (b *Broker) Validate(ctx context.Context) *apis.FieldError {
withNS := apis.WithinParent(ctx, b.ObjectMeta)
withNS := apis.AllowDifferentNamespace(apis.WithinParent(ctx, b.ObjectMeta))
return b.Spec.Validate(withNS).ViaField("spec")
}

Expand Down