-
Notifications
You must be signed in to change notification settings - Fork 1.8k
pkg/helm: install resources in same namespace as CR #2414
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
cbc56d9
2506b43
f995a8b
ef30a50
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 |
|---|---|---|
|
|
@@ -28,25 +28,17 @@ import ( | |
| cached "k8s.io/client-go/discovery/cached" | ||
| "k8s.io/client-go/rest" | ||
| "k8s.io/client-go/tools/clientcmd" | ||
| clientcmdapi "k8s.io/client-go/tools/clientcmd/api" | ||
| "sigs.k8s.io/controller-runtime/pkg/manager" | ||
| ) | ||
|
|
||
| // NewFromManager returns a Kubernetes client that can be used with | ||
| // a Tiller server. | ||
| func NewFromManager(mgr manager.Manager) (*kube.Client, error) { | ||
| c, err := NewRESTClientGetter(mgr) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return kube.New(c), nil | ||
| } | ||
|
|
||
|
Contributor
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. It as unused before. 👍 |
||
| var _ genericclioptions.RESTClientGetter = &restClientGetter{} | ||
|
|
||
| type restClientGetter struct { | ||
| restConfig *rest.Config | ||
| discoveryClient discovery.CachedDiscoveryInterface | ||
| restMapper meta.RESTMapper | ||
| namespaceConfig clientcmd.ClientConfig | ||
| } | ||
|
|
||
| func (c *restClientGetter) ToRESTConfig() (*rest.Config, error) { | ||
|
|
@@ -62,10 +54,32 @@ func (c *restClientGetter) ToRESTMapper() (meta.RESTMapper, error) { | |
| } | ||
|
|
||
| func (c *restClientGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig { | ||
| return c.namespaceConfig | ||
| } | ||
|
|
||
| var _ clientcmd.ClientConfig = &namespaceClientConfig{} | ||
|
|
||
| type namespaceClientConfig struct { | ||
| namespace string | ||
| } | ||
|
|
||
| func (c namespaceClientConfig) RawConfig() (clientcmdapi.Config, error) { | ||
| return clientcmdapi.Config{}, nil | ||
| } | ||
|
|
||
| func (c namespaceClientConfig) ClientConfig() (*rest.Config, error) { | ||
| return nil, nil | ||
|
Contributor
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. Why it is required since always return nil and nil?
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. These functions are required because As far as I can tell, Helm only uses
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. Just following up on the question of how $ grep -r ToRaw *
pkg/kube/factory.go: // ToRawKubeConfigLoader return kubeconfig loader as-is
pkg/kube/factory.go: ToRawKubeConfigLoader() clientcmd.ClientConfig
pkg/kube/client.go: if ns, _, err := c.Factory.ToRawKubeConfigLoader().Namespace(); err == nil {
pkg/cli/environment.go: if ns, _, err := s.RESTClientGetter().ToRawKubeConfigLoader().Namespace(); err == nil {So yeah, only |
||
| } | ||
|
|
||
| func (c namespaceClientConfig) Namespace() (string, bool, error) { | ||
| return c.namespace, false, nil | ||
| } | ||
|
|
||
| func (c namespaceClientConfig) ConfigAccess() clientcmd.ConfigAccess { | ||
| return nil | ||
|
Contributor
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. same here |
||
| } | ||
|
|
||
| func NewRESTClientGetter(mgr manager.Manager) (genericclioptions.RESTClientGetter, error) { | ||
| func NewRESTClientGetter(mgr manager.Manager, ns string) (genericclioptions.RESTClientGetter, error) { | ||
| cfg := mgr.GetConfig() | ||
| dc, err := discovery.NewDiscoveryClientForConfig(cfg) | ||
| if err != nil { | ||
|
|
@@ -78,6 +92,7 @@ func NewRESTClientGetter(mgr manager.Manager) (genericclioptions.RESTClientGette | |
| restConfig: cfg, | ||
| discoveryClient: cdc, | ||
| restMapper: rm, | ||
| namespaceConfig: &namespaceClientConfig{ns}, | ||
| }, 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.
The addition of
--namespacebelow makes sense, but why is the test operator now cluster-scoped? Shouldn't its manifests just have a different namespace?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.
The change to the
operator.yamlis to make it watch all namespaces so that it can see CRs outside of its own namespace. Not sure if that answers your question...