@@ -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.
8991func (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