Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
upgrade to latest dependencies
Browse files Browse the repository at this point in the history
bumping knative.dev/eventing 71d5d5f...36e0721:
  > 36e0721 Broker class based defaults (# 7631)
  > e4b6d68 [main] Upgrade to latest dependencies (# 8172)
  > 24a43e8 chore: refactor cross namespace test to make it reusable (# 8157)
  > da10b71 Support dispatcher format for triggers (# 8151)
  > 477588c JobSink: Reject unauthorized requests (# 8169)
  > 5fc4c0f Fix JobSink to have ObservedGeneration in status (# 8168)
  > ed71838 Fix: Use correct readyness check in AuthZ conformance tests (# 8167)
  > bf945f9 Support authorization in Channel ingress (# 8162)
  > b57ac3a Fix: propagate EventPolicy filter to underlying Channels EventPolicy (# 8163)
  > 2b92299 Add filters to event policy (# 8122)
  > 90a88fc [main] Upgrade to latest dependencies (# 8159)
  > 1123cfa feat: reduced unnecessary creation of filters (# 8118)
bumping knative.dev/pkg cd3311c...89743d9:
  > 89743d9 upgrade to latest dependencies (# 3085)

Signed-off-by: Knative Automation <automation@knative.team>
  • Loading branch information
knative-automation committed Aug 23, 2024
1 parent 6758ac2 commit 2e44bb7
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 65 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
k8s.io/api v0.30.3
k8s.io/apimachinery v0.30.3
k8s.io/client-go v0.30.3
knative.dev/eventing v0.42.1-0.20240813160331-71d5d5f0bb73
knative.dev/eventing v0.42.1-0.20240822171311-36e0721b3852
knative.dev/hack v0.0.0-20240814130635-06f7aff93954
knative.dev/pkg v0.0.0-20240812053209-cd3311cbab65
knative.dev/pkg v0.0.0-20240815051656-89743d9bbf7c
)

require (
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
Expand Down Expand Up @@ -646,12 +648,12 @@ k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8 h1:1Wof1cGQgA5pqgo8MxKPtf
k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8/go.mod h1:Os6V6dZwLNii3vxFpxcNaTmH8LJJBkOTg1N0tOA0fvA=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/eventing v0.42.1-0.20240813160331-71d5d5f0bb73 h1:ZJDXuggkeiK0n2fCzBabFRI2TIWKy+BtfNgH4Eb8xEo=
knative.dev/eventing v0.42.1-0.20240813160331-71d5d5f0bb73/go.mod h1:4ToBaBVKcH7wYrTebJ0bgIePYb9o7QVOoP5KP4s1L9w=
knative.dev/eventing v0.42.1-0.20240822171311-36e0721b3852 h1:Ulgi6VO5b0/VAvSNvHIgls0GBiXlb9+S51KbtOzO4LU=
knative.dev/eventing v0.42.1-0.20240822171311-36e0721b3852/go.mod h1:Clx8z37Nwg321H9+vGNxp5C6bVdo4l4XM5g6T5CgZVI=
knative.dev/hack v0.0.0-20240814130635-06f7aff93954 h1:dGMK5VoL75szvrYQTL9NqhPYHu1f5dGaXx1hJI8fAFM=
knative.dev/hack v0.0.0-20240814130635-06f7aff93954/go.mod h1:R0ritgYtjLDO9527h5vb5X6gfvt5LCrJ55BNbVDsWiY=
knative.dev/pkg v0.0.0-20240812053209-cd3311cbab65 h1:9r795uNPp2f/dIUzHlJW4Prz3U+8+1ZpW4z6EBUxpwc=
knative.dev/pkg v0.0.0-20240812053209-cd3311cbab65/go.mod h1:2kizutszzGp+EcVXivdigNd6dUM7O77QaLUTZeKaN5s=
knative.dev/pkg v0.0.0-20240815051656-89743d9bbf7c h1:2crXVk4FG0dSG6WHaIT+WKbUzn7qG2wn0AfYmvA22zs=
knative.dev/pkg v0.0.0-20240815051656-89743d9bbf7c/go.mod h1:cI2RPEEHZk+/dBpfHobs0aBdPA1mMZVUVWnGAc8NSzM=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
199 changes: 169 additions & 30 deletions vendor/knative.dev/eventing/pkg/apis/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,65 +68,204 @@ func NewDefaultsConfigFromConfigMap(config *corev1.ConfigMap) (*Defaults, error)
return NewDefaultsConfigFromMap(config.Data)
}

/*
The priority precedence for determining the broker class and configuration is as follows:
1. If a specific broker class is provided:
a. Check namespace-specific configuration for the given broker class
b. If not found, check cluster-wide configuration for the given broker class
c. If still not found, use the cluster-wide default configuration
2. If no specific broker class is provided:
a. Check namespace-specific default broker class
b. If found, use its configuration (following step 1)
c. If not found, use cluster-wide default broker class and configuration
3. If no default cluster configuration is set, return an error
4. If no default namespace configuration is set, will use the cluster-wide default configuration.
This can be represented as a flow chart:
Start
|
v
Is broker class provided?
/ \
Yes No
/ \
Check namespace config Check namespace
for provided class default class
| |
v v
Found? Found?
/ \ / \
Yes No Yes No
| | | |
| | | |
| v | v
| Check cluster | Use cluster
| config for class | default class
| | | and config
| v |
| Found? |
| / \ |
| Yes No |
| | | |
| | v |
| | Use cluster |
| | default config |
v v v
Use found configuration
The system prioritizes namespace-specific configurations over cluster-wide defaults,
and explicitly provided broker classes over default classes.
*/

// Defaults includes the default values to be populated by the webhook.
type Defaults struct {
// NamespaceDefaultsConfig are the default Broker Configs for each namespace.
// Namespace is the key, the value is the KReference to the config.
NamespaceDefaultsConfig map[string]*ClassAndBrokerConfig `json:"namespaceDefaults,omitempty"`
// Namespace is the key, the value is the NamespaceDefaultConfig
NamespaceDefaultsConfig map[string]*DefaultConfig `json:"namespaceDefaults,omitempty"`

// ClusterDefaultBrokerConfig is the default broker config for all the namespaces that
// are not in NamespaceDefaultBrokerConfigs.
ClusterDefault *ClassAndBrokerConfig `json:"clusterDefault,omitempty"`
// ClusterDefaultConfig is the default broker config for all the namespaces that
// are not in NamespaceDefaultBrokerConfigs. Different broker class could have
// different default config.
ClusterDefaultConfig *DefaultConfig `json:"clusterDefault,omitempty"`
}

// ClassAndBrokerConfig contains configuration for a given namespace for broker. Allows
// configuring the Class of the Broker, the reference to the
// config it should use and it's delivery.
type ClassAndBrokerConfig struct {
BrokerClass string `json:"brokerClass,omitempty"`
// DefaultConfig struct contains the default configuration for the cluster and namespace.
type DefaultConfig struct {
// DefaultBrokerClass and DefaultBrokerClassConfig are the default broker class for the whole cluster/namespace.
// Users have to specify both of them
DefaultBrokerClass string `json:"brokerClass,omitempty"`

//Deprecated: Use the config in BrokerClasses instead
*BrokerConfig `json:",inline"`

// Optional: BrokerClasses are the default broker classes' config. The key is the broker class name, and the value is the config for that broker class.
BrokerClasses map[string]*BrokerConfig `json:"brokerClasses,omitempty"`

DisallowDifferentNamespaceConfig *bool `json:"disallowDifferentNamespaceConfig,omitempty"`
}

// BrokerConfig contains configuration for a given namespace for broker. Allows
// BrokerConfig contains configuration for a given broker. Allows
// configuring the reference to the
// config it should use and it's delivery.
type BrokerConfig struct {
*duckv1.KReference `json:",inline"`
Delivery *eventingduckv1.DeliverySpec `json:"delivery,omitempty"`
}

// GetBrokerConfig returns a namespace specific Broker Configuration, and if
// that doesn't exist, return a Cluster Default and if that doesn't exist
// return an error.
func (d *Defaults) GetBrokerConfig(ns string) (*BrokerConfig, error) {
// GetBrokerConfig returns a namespace specific Broker Config, and if
// that doesn't exist, return a Cluster Default and if that doesn't exist return an error.
func (d *Defaults) GetBrokerConfig(ns string, brokerClassName *string) (*BrokerConfig, error) {
if d == nil {
return nil, errors.New("Defaults are nil")
return nil, errors.New("Defaults for Broker Configurations for cluster have not been set up. You can set them via ConfigMap config-br-defaults.")
}

// Early return if brokerClassName is provided and valid
if brokerClassName != nil && *brokerClassName != "" {
return d.getBrokerConfigByClassName(ns, *brokerClassName)
}

// Handling empty brokerClassName
return d.getBrokerConfigForEmptyClassName(ns)
}

// getBrokerConfigByClassName returns the BrokerConfig for the given brokerClassName.
// It first checks the namespace specific configuration, then the cluster default configuration.
func (d *Defaults) getBrokerConfigByClassName(ns string, brokerClassName string) (*BrokerConfig, error) {
// Check namespace specific configuration
if nsConfig, ok := d.NamespaceDefaultsConfig[ns]; ok && nsConfig != nil {
// check if the brokerClassName is the default broker class for this namespace
if nsConfig.DefaultBrokerClass == brokerClassName {
if nsConfig.BrokerConfig == nil {
// as no default broker class config is set for this namespace, check whether nsconfig's brokerClasses map has the config for this broker class
if config, ok := nsConfig.BrokerClasses[brokerClassName]; ok && config != nil {
return config, nil
}
// if not found, return the cluster default config
return d.getClusterDefaultBrokerConfig(brokerClassName)
} else {
// If the brokerClassName exists in the BrokerClasses, return the config in the BrokerClasses
if config, ok := nsConfig.BrokerClasses[brokerClassName]; ok && config != nil {
return config, nil
} else {
// If the brokerClassName is the default broker class for the namespace, return the BrokerConfig
return nsConfig.BrokerConfig, nil
}
}
} else {
// if the brokerClassName is not the default broker class for the namespace, check whether nsconfig's brokerClasses map has the config for this broker class
if config, ok := nsConfig.BrokerClasses[brokerClassName]; ok && config != nil {
return config, nil
}
}
}
value, present := d.NamespaceDefaultsConfig[ns]
if present && value.BrokerConfig != nil {
return value.BrokerConfig, nil

// Check cluster default configuration
return d.getClusterDefaultBrokerConfig(brokerClassName)
}

// getBrokerConfigForEmptyClassName returns the BrokerConfig for the given namespace when brokerClassName is empty.
// It first checks the namespace specific configuration, then the cluster default configuration.
func (d *Defaults) getBrokerConfigForEmptyClassName(ns string) (*BrokerConfig, error) {
// Check if namespace has a default broker class
if nsConfig, ok := d.NamespaceDefaultsConfig[ns]; ok && nsConfig != nil {
if nsConfig.DefaultBrokerClass != "" {
return d.getBrokerConfigByClassName(ns, nsConfig.DefaultBrokerClass)
}
}
if d.ClusterDefault != nil && d.ClusterDefault.BrokerConfig != nil {
return d.ClusterDefault.BrokerConfig, nil

// Fallback to cluster default configuration
return d.getClusterDefaultBrokerConfig("")
}

// getClusterDefaultBrokerConfig returns the BrokerConfig for the given brokerClassName.
func (d *Defaults) getClusterDefaultBrokerConfig(brokerClassName string) (*BrokerConfig, error) {
if d.ClusterDefaultConfig == nil || d.ClusterDefaultConfig.BrokerConfig == nil {
return nil, errors.New("Defaults for Broker Configurations for cluster have not been set up. You can set them via ConfigMap config-br-defaults.")
}
return nil, errors.New("Defaults for Broker Configurations have not been set up.")

// Check if the brokerClassName is the default broker class for the whole cluster
if brokerClassName == "" || d.ClusterDefaultConfig.DefaultBrokerClass == brokerClassName {
// If the brokerClassName exists in the BrokerClasses, return the config in the BrokerClasses
if config, ok := d.ClusterDefaultConfig.BrokerClasses[brokerClassName]; ok && config != nil {
return config, nil
} else {
// If the brokerClassName is the default broker class for the cluster, return the BrokerConfig
return d.ClusterDefaultConfig.BrokerConfig, nil
}
}

if config, ok := d.ClusterDefaultConfig.BrokerClasses[brokerClassName]; ok && config != nil {
return config, nil
}

return d.ClusterDefaultConfig.BrokerConfig, nil
}

// GetBrokerClass returns a namespace specific Broker Class, and if
// that doesn't exist, return a Cluster Default and if that doesn't exist
// that doesn't exist, return a Cluster Default and if the defaults doesn't exist
// return an error.
func (d *Defaults) GetBrokerClass(ns string) (string, error) {
if d == nil {
return "", errors.New("Defaults are nil")
return "", errors.New("Defaults for Broker Configurations for cluster have not been set up. You can set them via ConfigMap config-br-defaults.")
}
value, present := d.NamespaceDefaultsConfig[ns]
if present && value.BrokerClass != "" {
return value.BrokerClass, nil

// Check if the namespace has a specific configuration
if nsConfig, ok := d.NamespaceDefaultsConfig[ns]; ok && nsConfig != nil {
if nsConfig.DefaultBrokerClass != "" {
return nsConfig.DefaultBrokerClass, nil
}
}
if d.ClusterDefault != nil && d.ClusterDefault.BrokerClass != "" {
return d.ClusterDefault.BrokerClass, nil

// Fallback to cluster default configuration if namespace specific configuration is not set
if d.ClusterDefaultConfig != nil && d.ClusterDefaultConfig.DefaultBrokerClass != "" {
return d.ClusterDefaultConfig.DefaultBrokerClass, nil
}
return "", errors.New("Defaults for Broker Configurations have not been set up.")

// If neither namespace specific nor cluster default broker class is found
return "", fmt.Errorf("Neither namespace specific nor cluster default broker class is found for namespace %q, please set them via ConfigMap config-br-defaults", ns)
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ import (
func (b *Broker) SetDefaults(ctx context.Context) {
// Default Spec fields.
withNS := apis.WithinParent(ctx, b.ObjectMeta)
b.Spec.SetDefaults(withNS)
b.Spec.SetDefaults(withNS, b.Annotations["eventing.knative.dev/broker.class"])
eventing.DefaultBrokerClassIfUnset(withNS, &b.ObjectMeta)
}

func (bs *BrokerSpec) SetDefaults(ctx context.Context) {
func (bs *BrokerSpec) SetDefaults(ctx context.Context, brokerClass string) {
cfg := config.FromContextOrDefaults(ctx)
c, err := cfg.Defaults.GetBrokerConfig(apis.ParentMeta(ctx).Namespace)
c, err := cfg.Defaults.GetBrokerConfig(apis.ParentMeta(ctx).Namespace, &brokerClass)

if bs.Config != nil {
c, err = cfg.Defaults.GetBrokerConfig(apis.ParentMeta(ctx).Namespace, &bs.Config.Kind)
}

if err == nil {
if bs.Config == nil {
bs.Config = c.KReference
Expand All @@ -49,10 +54,14 @@ func (bs *BrokerSpec) SetDefaults(ctx context.Context) {
BackoffDelay: c.Delivery.BackoffDelay,
}
}

}

// Default the namespace if not given
if bs.Config != nil {
bs.Config.SetDefaults(ctx)
}

bs.Delivery.SetDefaults(ctx)

}
Loading

0 comments on commit 2e44bb7

Please sign in to comment.