@@ -40,6 +40,7 @@ import (
4040 "helm.sh/helm/v4/pkg/kube"
4141 "helm.sh/helm/v4/pkg/registry"
4242 "helm.sh/helm/v4/pkg/repo/v1"
43+ "k8s.io/cli-runtime/pkg/genericclioptions"
4344)
4445
4546// Configuration state
@@ -110,61 +111,75 @@ func helm_sdkpy_version_number() C.int {
110111
111112//export helm_sdkpy_config_create
112113func helm_sdkpy_config_create (namespace * C.char , kubeconfig * C.char , kubecontext * C.char , handle_out * C.helm_sdkpy_handle ) C.int {
113- ns := C .GoString (namespace )
114- kc := C .GoString (kubeconfig )
115- kctx := C .GoString (kubecontext )
116-
117- // Create environment settings
118- envs := cli .New ()
119- if ns != "" {
120- envs .SetNamespace (ns )
121- }
122- if kc != "" {
123- envs .KubeConfig = kc
124- }
125- if kctx != "" {
126- envs .KubeContext = kctx
127- }
114+ ns := C .GoString (namespace )
115+ kc := C .GoString (kubeconfig )
116+ kctx := C .GoString (kubecontext )
117+
118+ var restClientGetter genericclioptions.RESTClientGetter
119+ var envs * cli.EnvSettings
120+
121+ // Check if kubeconfig is YAML content or a file path
122+ if kc != "" && isKubeconfigYAMLContent (kc ) {
123+ // Use custom RESTClientGetter for in-memory kubeconfig
124+ restClientGetter = NewKubeconfigStringGetter (kc , ns , kctx )
125+ envs = cli .New ()
126+ if ns != "" {
127+ envs .SetNamespace (ns )
128+ }
129+ } else {
130+ // Standard file-based kubeconfig
131+ envs = cli .New ()
132+ if ns != "" {
133+ envs .SetNamespace (ns )
134+ }
135+ if kc != "" {
136+ envs .KubeConfig = kc
137+ }
138+ if kctx != "" {
139+ envs .KubeContext = kctx
140+ }
141+ restClientGetter = envs .RESTClientGetter ()
142+ }
128143
129- // Create action configuration
130- cfg := new (action.Configuration )
144+ // Create action configuration
145+ cfg := new (action.Configuration )
131146
132- // Initialize the configuration with Kubernetes settings
133- err := cfg .Init (envs . RESTClientGetter () , envs .Namespace (), os .Getenv ("HELM_DRIVER" ))
134- if err != nil {
135- return setError (fmt .Errorf ("failed to initialize helm config: %w" , err ))
136- }
147+ // Initialize the configuration with Kubernetes settings
148+ err := cfg .Init (restClientGetter , envs .Namespace (), os .Getenv ("HELM_DRIVER" ))
149+ if err != nil {
150+ return setError (fmt .Errorf ("failed to initialize helm config: %w" , err ))
151+ }
137152
138- // Configure the Kubernetes client to use Ignore field validation
139- // This allows charts with managedFields in templates (like rook-ceph v1.18.x)
140- // to install successfully without strict Kubernetes API validation errors
141- if cfg .KubeClient != nil {
142- // Note: In Helm v4, field validation is handled via client options during Create/Update
143- // We'll configure this in the Install action instead
144- }
153+ // Configure the Kubernetes client to use Ignore field validation
154+ // This allows charts with managedFields in templates (like rook-ceph v1.18.x)
155+ // to install successfully without strict Kubernetes API validation errors
156+ if cfg .KubeClient != nil {
157+ // Note: In Helm v4, field validation is handled via client options during Create/Update
158+ // We'll configure this in the Install action instead
159+ }
145160
146- // Initialize registry client for OCI operations
147- registryClient , err := registry .NewClient (
148- registry .ClientOptDebug (false ),
149- registry .ClientOptEnableCache (true ),
150- registry .ClientOptWriter (os .Stdout ),
151- registry .ClientOptCredentialsFile (envs .RegistryConfig ),
152- )
153- if err != nil {
154- return setError (fmt .Errorf ("failed to initialize registry client: %w" , err ))
155- }
156- cfg .RegistryClient = registryClient
161+ // Initialize registry client for OCI operations
162+ registryClient , err := registry .NewClient (
163+ registry .ClientOptDebug (false ),
164+ registry .ClientOptEnableCache (true ),
165+ registry .ClientOptWriter (os .Stdout ),
166+ registry .ClientOptCredentialsFile (envs .RegistryConfig ),
167+ )
168+ if err != nil {
169+ return setError (fmt .Errorf ("failed to initialize registry client: %w" , err ))
170+ }
171+ cfg .RegistryClient = registryClient
157172
158- state := & configState {
159- cfg : cfg ,
160- envs : envs ,
161- }
173+ state := & configState {
174+ cfg : cfg ,
175+ envs : envs ,
176+ }
162177
163- handle := nextHandle ()
164- configs .Store (handle , state )
165- * handle_out = handle
178+ handle := nextHandle ()
179+ configs .Store (handle , state )
180+ * handle_out = handle
166181
167- return 0
182+ return 0
168183}
169184
170185//export helm_sdkpy_config_destroy
0 commit comments