-
Notifications
You must be signed in to change notification settings - Fork 604
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
knative-prow-robot
merged 6 commits into
knative:master
from
vaikas:default-v1beta1-broker
Feb 26, 2020
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7d55058
create v1beta1 brokers, use context for defaulting
vaikas 41562ab
add debug stuff
vaikas 5288149
OMG... really???
vaikas 57cd630
add default imc channel configmap for backwards compatibility
vaikas a048c4b
cleanup + unit tests
vaikas 10a4a2b
fix year
vaikas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1 @@ | ||||||||
core/configmaps/default-imc.yaml | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add trailing newline:
Suggested change
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1 @@ | ||||||||
core/configmaps/default-broker.yaml | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add trailing newline:
Suggested change
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2020 The Knative Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: config-br-defaults | ||
namespace: knative-eventing | ||
data: | ||
# Configuration for defaulting channels that do not specify CRD implementations. | ||
default-br-config: | | ||
clusterDefault: | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
name: config-br-default-channel | ||
namespace: knative-eventing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2020 The Knative Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: config-br-default-channel | ||
namespace: knative-eventing | ||
data: | ||
channelTemplateSpec.apiVersion: messaging.knative.dev/v1alpha1 | ||
channelTemplateSpec.kind: InMemoryChannel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ghodss/yaml" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
duckv1 "knative.dev/pkg/apis/duck/v1" | ||
) | ||
|
||
const ( | ||
// DefaultConfigName is the name of config map for the default | ||
// configs that brokers should use | ||
DefaultsConfigName = "config-br-defaults" | ||
|
||
// BrokerDefaultsKey is the name of the key that's used for finding | ||
// defaults for broker configs. | ||
BrokerDefaultsKey = "default-br-config" | ||
) | ||
|
||
// NewDefaultsConfigFromMap creates a Defaults from the supplied Map | ||
func NewDefaultsConfigFromMap(data map[string]string) (*Defaults, error) { | ||
nc := &Defaults{} | ||
|
||
// Parse out the Broker Configuration Cluster default section | ||
value, present := data[BrokerDefaultsKey] | ||
if !present || value == "" { | ||
return nil, fmt.Errorf("ConfigMap is missing (or empty) key: %q : %v", BrokerDefaultsKey, data) | ||
} | ||
if err := parseEntry(value, nc); err != nil { | ||
return nil, fmt.Errorf("Failed to parse the entry: %s", err) | ||
} | ||
return nc, nil | ||
} | ||
|
||
func parseEntry(entry string, out interface{}) error { | ||
j, err := yaml.YAMLToJSON([]byte(entry)) | ||
if err != nil { | ||
return fmt.Errorf("ConfigMap's value could not be converted to JSON: %s : %v", err, entry) | ||
} | ||
return json.Unmarshal([]byte(j), &out) | ||
} | ||
|
||
// NewDefaultsConfigFromConfigMap creates a Defaults from the supplied configMap | ||
func NewDefaultsConfigFromConfigMap(config *corev1.ConfigMap) (*Defaults, error) { | ||
return NewDefaultsConfigFromMap(config.Data) | ||
} | ||
|
||
// 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]*duckv1.KReference `json:"namespaceDefaults,omitempty"` | ||
|
||
// ClusterDefaultBrokerConfig is the default broker config for all the namespaces that | ||
// are not in NamespaceDefaultBrokerConfigs. | ||
ClusterDefault *duckv1.KReference `json:"clusterDefault,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) (*duckv1.KReference, error) { | ||
if d == nil { | ||
return nil, errors.New("Defaults are nil") | ||
} | ||
value, present := d.NamespaceDefaultsConfig[ns] | ||
if present { | ||
return value, nil | ||
} | ||
if d.ClusterDefault != nil { | ||
return d.ClusterDefault, nil | ||
} | ||
return nil, errors.New("Defaults for Broker Configurations have not been set up.") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 your APIs defaulting is now dependent on the store/config in the context - you'll need to update the conversion webhook context decorator - it will invoke defaulting on the way 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.
that is good to know!
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.
done: https://github.com/knative/eventing/pull/2651/files#diff-58de452513b7e8d8d3cfea23eb4ae6a8R340