-
Notifications
You must be signed in to change notification settings - Fork 590
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
Add Broker class spec based default #6621
Add Broker class spec based default #6621
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liuchangyan The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov ReportBase: 81.94% // Head: 80.60% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #6621 +/- ##
==========================================
- Coverage 81.94% 80.60% -1.34%
==========================================
Files 235 236 +1
Lines 11774 12050 +276
==========================================
+ Hits 9648 9713 +65
- Misses 1650 1856 +206
- Partials 476 481 +5
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
pkg/apis/config/defaults.go
Outdated
// BrokerClassSpec set the multiple configurations of different brokerClass. | ||
// Different brokerClass use corresponding brokerConfig for all the namespaces that | ||
// are not in NamespaceDefaultBrokerConfigs. | ||
BrokerClassSpec map[string]*BrokerConfigSpec `json:"brokerClassSpec,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call it brokerClasses
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call it
brokerClasses
?
Sure
Thanks @liuchangyan! Can you please add release note doc in the PR description? |
ok |
pkg/apis/config/defaults.go
Outdated
// BrokerClassSpec set the multiple configurations of different brokerClass. | ||
// Different brokerClass use corresponding brokerConfig for all the namespaces that | ||
// are not in NamespaceDefaultBrokerConfigs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we leaving broker-class based defaults for namespace defaults out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh no, we are not leaving, the annotation description is wrong
ca24516
to
bdce2f4
Compare
28e09ae
to
ca0f0e7
Compare
I will take few days off this week, I will add release note doc next week, Thanks for your review :) ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add additional tests to broker_defaults.go https://github.com/knative/eventing/blob/main/pkg/apis/eventing/v1/broker_defaults_test.go to test the e2e defaulting mechanism ?
For example with scenario like:
- no broker class specified and the defaulted broker class set to point to a broker class based default
- broker class specified that points to a broker class based default (one for each "scope" namespaced and cluster)
- etc
pkg/apis/config/defaults.go
Outdated
for bClass, bCSpec := range brokerClasses { | ||
if bClass == brokerClass { | ||
var bConfig BrokerConfig | ||
bConfig.KReference = bCSpec.Spec.Config | ||
bConfig.Delivery = bCSpec.Spec.Delivery | ||
return &bConfig | ||
} | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use the map access here:
bCSpec, ok := brokerClasses[brokerClass]
Sure |
d22c904
to
2ad62d2
Compare
/retest |
de2f59a
to
2ad62d2
Compare
c481170
to
2ad62d2
Compare
4829d81
to
1fa7225
Compare
/test upgrade-tests |
@@ -461,6 +531,96 @@ func TestBrokerSetDefaults(t *testing.T) { | |||
}, | |||
}, | |||
}, | |||
"no config, uses namespace4's broker class and config": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another interesting use case to test is:
- initial: broker in namespace
namespace4
(without broker class set) namespace4
's class-based default is set for the cluster-level broker class (aka BrokerClass: eventing.MTChannelBrokerClassValue, line 144)
I think, in this case we expect that we use the cluster-level default to default the class and the namespace4 default for that particular class to default the rest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, another interesting tests is when:
- initial: broker in namespace
namespace11
(without broker class set) - cluster-level class-based default is set for the cluster-level broker class (aka BrokerClass: eventing.MTChannelBrokerClassValue, line 144)
I think, in this case we expect that we use the cluster-level default to default the class and cluster-level class-based default to default the rest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got your point
|
||
// Add cluster-level multi-class-based configs to defaultConfig | ||
brokerClasses := make(map[string]*config.BrokerConfigSpec) | ||
brokerSpec1 := &config.BrokerSpec{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call all brokerSpec<X>
variables with the associated class for clarity like brokerSpecMTChannelBasedBroker
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it
@@ -117,6 +142,34 @@ func TestGetBrokerClass(t *testing.T) { | |||
} | |||
|
|||
func TestDefaultsConfiguration(t *testing.T) { | |||
brokerClasses := make(map[string]*BrokerConfigSpec) | |||
brokerSpec1 := &BrokerSpec{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here on the naming
// get namespace default config | ||
if present && value.BrokerConfig != nil { | ||
return value.BrokerConfig, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I specify broker-class based default at the namespace level value.BrokerClasses
I don't think this would work because we returning always the single value.BrokerConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and that makes me think we need a test for this case as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I specify broker-class based default at the namespace level
value.BrokerClasses
I don't think this would work because we returning always the singlevalue.BrokerConfig
I see your point, I think the broker-class based default at the namespace level we may not use it , but once we set the the single value.BrokerConfig we surely want to use it. And is it necessary to set broker-class based default at the namespace level ? Because we already set it at the cluster level, and in namespace we use the config of cluster is ok, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary to set broker-class based default at the namespace level ?
Yes, I think it's a valid use case and also for consistency with the cluster-level defaults
return nil | ||
} | ||
if bCSpec := getBrokerClasses(d); bCSpec != nil { | ||
bConfig := matchBrokerClass(cb.BrokerClass, bCSpec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, we are always using cb.BrokerClass which is equal to ClusterDefault.BrokerClass
but if I create a Broker with an already set Broker class, we won't chose the correct configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the brokerclass we set is in cluster level right? We always need to set a BrokerClass
in ClusterDefault
, and then we choose the corresponding BrokerConfig
What is the status here? |
This Pull Request is stale because it has been open for 90 days with |
Fixes #5992
Signed-off-by: Teresaliu changyan.liu@intel.com
Proposed Changes
Pre-review Checklist
Release Note
Docs
Choosing the Broker Config for the configured Brokerclass in clusterDefault of default-br-config.
You can configure
BrokerClasses
in clusterDefault to set multiple broker.spec. When there are multiple classes in the same cluster, the BrokerClass in clusterDefault or namespaceDefault could find the corresponding Broker Config for the configured BrokerClass.For example,if you wanted to set the
KafkaBroker
Class and its config-kafka-channel ConfigMap for all other Brokers created, but wanted to setMTChannelBasedBroker
Class and its config-br-default-channel ConfigMap fornamespace-1
andnamespace-2
, you would use the following settings: