-
Notifications
You must be signed in to change notification settings - Fork 829
fix: alway include the controller namespace in the watched namespaces #9100
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
Changes from all commits
ab2e913
3fa5267
6cc684c
5420f3f
ba6c957
80bb4b9
3a39632
4e833ad
8d00aba
5303fc2
2fcc0fb
91fc395
c3a4e19
3a4d8e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,12 +46,6 @@ func (cli *InfraClient) DeleteAllExcept(ctx context.Context, objList client.Obje | |
| v := reflect.ValueOf(objList).Elem() | ||
| items := v.FieldByName("Items") | ||
|
|
||
| // If there is only one item, we don't need to delete it, | ||
| // because it normally means custom resource name is not enabled. | ||
| if items.Len() <= 1 { | ||
|
Member
Author
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. This is not safe since now we use the cached kube client. |
||
| return nil | ||
| } | ||
|
|
||
| for i := range items.Len() { | ||
| item := items.Index(i) | ||
| name := item.FieldByName("Name") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,10 +270,81 @@ func newProvider(ctx context.Context, restCfg *rest.Config, svrCfg *ec.Server, | |
|
|
||
| mgrOpts.Cache.DefaultTransform = cache.TransformStripManagedFields() | ||
|
|
||
| if svrCfg.EnvoyGateway.NamespaceMode() { | ||
| mgrOpts.Cache.DefaultNamespaces = make(map[string]cache.Config) | ||
| // When configured with an explicit namespace watch list, scope the default | ||
| // cache to those namespaces and add type-specific controller namespace | ||
| // exceptions below. | ||
| if svrCfg.EnvoyGateway.WatchesNamespaces() { | ||
|
Member
Author
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. This and the above |
||
| watchedNamespaces := map[string]cache.Config{} | ||
| for _, watchNS := range svrCfg.EnvoyGateway.Provider.Kubernetes.Watch.Namespaces { | ||
| mgrOpts.Cache.DefaultNamespaces[watchNS] = cache.Config{} | ||
| watchedNamespaces[watchNS] = cache.Config{} | ||
| } | ||
|
zhaohuabing marked this conversation as resolved.
|
||
|
|
||
| watchedAndControllerNamespaces := make(map[string]cache.Config, len(watchedNamespaces)+1) | ||
| for ns, cfg := range watchedNamespaces { | ||
| watchedAndControllerNamespaces[ns] = cfg | ||
| } | ||
| watchedAndControllerNamespaces[svrCfg.ControllerNamespace] = cache.Config{} | ||
|
|
||
| // DefaultNamespaces applies to every namespaced informer without a | ||
| // ByObject namespace override, including Gateway API informers | ||
| // registered later. Since Gateway API resources do not get controller | ||
| // namespace overrides below, they only watch these configured namespaces. | ||
| mgrOpts.Cache.DefaultNamespaces = watchedNamespaces | ||
|
|
||
| // ConfigMaps and Services must cover both scopes: watched namespaces for | ||
| // user refs such as policy/filter ConfigMaps and Route backend Services, | ||
| // and the controller namespace for EG-owned proxy/ratelimit infra | ||
| // ConfigMaps and Services. | ||
| mgrOpts.Cache.ByObject[&corev1.ConfigMap{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Transform: composeTransforms(cache.TransformStripManagedFields(), transformConfigMapData), | ||
| Namespaces: watchedAndControllerNamespaces, | ||
| } | ||
| mgrOpts.Cache.ByObject[&corev1.Service{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Namespaces: watchedAndControllerNamespaces, | ||
| } | ||
| mgrOpts.Cache.ByObject[&discoveryv1.EndpointSlice{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Namespaces: watchedAndControllerNamespaces, | ||
| } | ||
| if svrCfg.EnvoyGateway.GatewayNamespaceMode() { | ||
| // GatewayNamespaceMode still needs controller namespace access for | ||
| // EG controller resources and the xDS CA Secret. | ||
| mgrOpts.Cache.ByObject[&corev1.ServiceAccount{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Namespaces: watchedAndControllerNamespaces, | ||
| } | ||
| mgrOpts.Cache.ByObject[&appsv1.Deployment{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Namespaces: watchedAndControllerNamespaces, | ||
| } | ||
| mgrOpts.Cache.ByObject[&corev1.Secret{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Namespaces: watchedAndControllerNamespaces, | ||
| } | ||
| } else { | ||
| // In normal mode, ServiceAccounts and Deployments are controller | ||
| // namespace infra, while Secrets cover watched namespaces for user | ||
| // refs and the controller namespace for EG-managed infra Secrets, | ||
| // including the OIDC HMAC Secret and Envoy's TLS Secret for | ||
| // connections to EG-managed control-plane services. | ||
| mgrOpts.Cache.ByObject[&corev1.ServiceAccount{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Namespaces: map[string]cache.Config{ | ||
| svrCfg.ControllerNamespace: {}, | ||
| }, | ||
| } | ||
| mgrOpts.Cache.ByObject[&appsv1.Deployment{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Namespaces: map[string]cache.Config{ | ||
| svrCfg.ControllerNamespace: {}, | ||
| }, | ||
| } | ||
| mgrOpts.Cache.ByObject[&corev1.Secret{}] = cache.ByObject{ | ||
| UnsafeDisableDeepCopy: new(true), | ||
| Namespaces: watchedAndControllerNamespaces, | ||
| } | ||
|
zhaohuabing marked this conversation as resolved.
|
||
| } | ||
| } | ||
| if svrCfg.EnvoyGateway.Provider.Kubernetes.TopologyInjector == nil || !ptr.Deref(svrCfg.EnvoyGateway.Provider.Kubernetes.TopologyInjector.Disable, false) { | ||
|
|
||
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.
This renames the exported
EnvoyGateway.NamespaceMode()method in the publicapi/v1alpha1package even though the behavior is unchanged. Any downstream Go code that imports Envoy Gateway API types and callsNamespaceMode()will fail to compile on upgrade; keepNamespaceMode()as a wrapper aroundWatchesNamespaces()if the clearer name is needed internally.Useful? React with 👍 / 👎.
Uh oh!
There was an error while loading. Please reload this page.
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.
This is a helper method, and it should not be in the API directory.
The original
NamespaceModemethod name could be easily get confused withGatewayNamespaceMode.