In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to inject default Provisioner into Channel in Knative Eventing. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
When you create a Broker in Knative Eventing, if you do not specify a provisioner, the system automatically creates a default provisioner, so how is this mechanism implemented? This paper introduces this implementation mechanism based on Knative Eventing version 0.5.
Scene
Usually when creating a Broker, we need to specify the use of a specific Channel Provisioner through spec.ChannelTemplate. For example, a Broker like this:
ApiVersion: eventing.knative.dev/v1alpha1kind: Brokermetadata: name: pubsub-channelspec: channelTemplate: provisioner: apiVersion: eventing.knative.dev/v1alpha1kind: ClusterChannelProvisioner name: gcp-pubsub
Here, a provisioner named gcp-pubsub is specified through spec.ChannelTemplate. So we've come across Broker like this:
ApiVersion: eventing.knative.dev/v1alpha1kind: Brokermetadata: name: default
You do not specify a specific channel, but after you create the Broker, you will find that the Channel has been created:
ApiVersion: eventing.knative.dev/v1alpha1kind: Channelmetadata:... Name: default-broker-8ml79 namespace: default ownerReferences:-apiVersion: eventing.knative.dev/v1alpha1 blockOwnerDeletion: true controller: true kind: Broker name: default uid: 2e4c3332-6755-11e9-a81f-00163f005e02spec: provisioner: apiVersion: eventing.knative.dev/v1alpha1 kind: ClusterChannelProvisioner name: in-memory... Analysis.
We know that after the Broker is created, the corresponding Channel will be created through reconcile controller, that is, the following code:
/ / newChannel creates a newChannel for Broker 'b'.func newChannel (b * v1alpha1.Broker, l map [string] string) * v1alpha1.Channel {var spec v1alpha1.ChannelSpec if b.Spec.ChannelTemplate! = nil {spec = * b.Spec.ChannelTemplate} return & v1alpha1.Channel {ObjectMeta: metav1.ObjectMeta {Namespace: b.Namespace, GenerateName: fmt.Sprintf ("% v1alpha1.Channel Broker -", b.Name) Labels: l, OwnerReferences: [] metav1.OwnerReference {* metav1.NewControllerRef (b, schema.GroupVersionKind {Group: v1alpha1.SchemeGroupVersion.Group, Version: v1alpha1.SchemeGroupVersion.Version, Kind: "Broker",}),},} Spec: spec,}}
By analyzing the above code, we can clearly conclude that if Spec.ChannelTemplate is set in Broker, then the provisioner corresponding to ChannelTemplate will be used directly in Channel.
But if it is not set, then spec in Channel should be set to nil. But in-memory provisioner is actually set, so where is this injected?
Injection mechanism
After locating the source code, we found the following code in channel_defaults.go:
Func (c * Channel) SetDefaults (ctx context.Context) {if c! = nil & & c.Spec.Provisioner = = nil {/ / The singleton may not have been set, if so ignore it and validation will reject the / / Channel. If cd: = ChannelDefaulterSingleton; cd! = nil {prov, args: = cd.GetDefault (c.DeepCopy ()) c.Spec.Provisioner = prov c.Spec.Arguments = args}} c.Spec.SetDefaults (ctx)}
After analysis, we can see that when c.Spec.Provisioner==nil, the default Provisioner is set.
Taking a closer look at ChannelDefaulterSingleton, we can give the implementation settings in webhook:
... / / Watch the default-channel-webhook ConfigMap and dynamically update the default// ClusterChannelProvisioner.channelDefaulter: = channeldefaulter.New (logger.Desugar ()) eventingv1alpha1.ChannelDefaulterSingleton = channelDefaulterconfigMapWatcher.Watch (channeldefaulter.ConfigMapName, channelDefaulter.UpdateConfigMap)...
Then it is found that ChannelDefaulter implements the GetDefault method:
/ / GetDefault determines the default provisioner and arguments for the provided channel.func (cd * ChannelDefaulter) GetDefault (c * eventingv1alpha1.Channel) (* corev1.ObjectReference, * runtime.RawExtension) {/ / Because we are treating this as a singleton, be tolerant to it having not been setup at all. If cd = = nil {return nil, nil} if c = = nil {return nil, nil} config: = cd.getConfig () if config = = nil {return nil, nil} / / TODO Don't use a single default, instead use the Channel's arguments to determine the type of / / Channel to use (e.g. It can say whether it needs to be persistent, strictly ordered, etc.) Dp: = getDefaultProvisioner (config, c.Namespace) cd.logger.Info ("Defaulting the ClusterChannelProvisioner", zap.Any ("defaultClusterChannelProvisioner", dp) return dp, nil}
And here is the default provisioner used through a ConfigMap setting, the ConfigMap name is default-channel-webhook, and yes, you can find this resource in the Knative Eventing installation file:
ApiVersion: v1data: default-channel-config: | clusterdefault: apiversion: eventing.knative.dev/v1alpha1 kind: ClusterChannelProvisioner name: in-memory namespacedefaults: some-namespace: apiversion: eventing.knative.dev/v1alpha1 kind: ClusterChannelProvisioner name: some-other-provisionerkind: ConfigMapmetadata: name: default-channel-webhook namespace: knative-eventing
So at this point in the analysis, let's sort out the whole injection process:
From the above analysis, we now understand the injection mechanism of the default provisioner, and we can also modify the default provisioner through webhook.
This is how the default Provisioner is injected into the Knative Eventing shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.