Skip to content

Commit 7e0c61f

Browse files
authored
Merge pull request #21 from vantagecompute/fix/pre-install-hook-namespace
fix: namespace parsing
2 parents b1a7f0d + 203ed47 commit 7e0c61f

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

go/shim/kubeconfig_string.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,38 @@ return mapper, nil
8686
}
8787

8888
// ToRawKubeConfigLoader returns a clientcmd.ClientConfig.
89+
// This method properly respects the namespace override so that all resources,
90+
// including pre-install hooks, are created in the correct namespace.
8991
func (k *kubeconfigStringGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig {
90-
config, err := clientcmd.NewClientConfigFromBytes([]byte(k.kubeconfigContent))
91-
if err != nil {
92-
// Return a default config on error
93-
return clientcmd.NewDefaultClientConfig(clientcmdapi.Config{}, &clientcmd.ConfigOverrides{})
94-
}
95-
return config
92+
config, err := clientcmd.NewClientConfigFromBytes([]byte(k.kubeconfigContent))
93+
if err != nil {
94+
// Return a default config on error
95+
return clientcmd.NewDefaultClientConfig(clientcmdapi.Config{}, &clientcmd.ConfigOverrides{})
96+
}
97+
98+
// If a namespace override was specified, wrap the config to return it
99+
if k.namespace != "" {
100+
rawConfig, err := config.RawConfig()
101+
if err != nil {
102+
return config
103+
}
104+
105+
// Build config overrides with namespace
106+
overrides := &clientcmd.ConfigOverrides{
107+
Context: clientcmdapi.Context{
108+
Namespace: k.namespace,
109+
},
110+
}
111+
112+
// If a context was specified, use it
113+
if k.context != "" {
114+
overrides.CurrentContext = k.context
115+
}
116+
117+
return clientcmd.NewDefaultClientConfig(rawConfig, overrides)
118+
}
119+
120+
return config
96121
}
97122

98123
// isKubeconfigYAMLContent checks if the string is YAML content rather than a file path.

0 commit comments

Comments
 (0)