<p>Im using the helm <a href="https://pkg.go.dev/helm.sh/helm/v3" rel="nofollow noreferrer">SDK</a> and it works great, for my testing using the fake option which works(for kubeconfig),</p>
<p>Now when I update the <code>kubeconfig</code> to my cluster I notice that during installation the chart is <strong>stuck</strong> on <strong>status pending</strong>,
and it <strong>stuck forever</strong> in this state until I'm deleting &amp; installing it again,(manually)
My question is how to solve this issue with the
<strong>Helm SDK</strong> (via code only) <a href="https://pkg.go.dev/helm.sh/helm/v3" rel="nofollow noreferrer">https://pkg.go.dev/helm.sh/helm/v3</a>,</p>
<p>I mean wait for a while and if the status is pending after 3 min delete and reinstall it again... or try upgrade before</p>
<p>This is the code</p>
<pre><code>    kubeConfigPath, err := findKubeConfig()
    if err != nil {
        fmt.Println()
    }

    actionConfig := &amp;action.Configuration{
    }

    cfg := cli.New()
    clientGetter := genericclioptions.NewConfigFlags(false)
    clientGetter.KubeConfig = &amp;kubeConfigPath

    actionConfig.Init(clientGetter, &quot;def&quot;, &quot;memory&quot;, log.Printf)
    if err != nil {
        fmt.Println(err)
    }

    chart, err := installation.InstallChart(cfg, &quot;test&quot;, &quot;chart1&quot;, &quot;./charts/dns&quot;, nil, actionConfig)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(chart)
}

func findKubeConfig() (string, error) {
    env := os.Getenv(&quot;KUBECONFIG&quot;)
    if env != &quot;&quot; {
        return env, nil
    }
    path, err := homedir.Expand(&quot;~/.kube/config&quot;)
    if err != nil {
        return &quot;&quot;, err
    }
    return path, nil
}
</code></pre>

Jenney
<p>Looking at the example, I don't know what the <code>installation</code> package is but I feel like you would need to use a <code>Loader</code> (maybe you are using it in that pkg)</p>
<p>from a quick search over the <a href="https://github.com/helm/helm/issues/6910#issuecomment-557106092" rel="nofollow noreferrer">github issues</a> I found someone with a similar problem - and they got the same suggestion. here is a derived example:</p>
<pre class="lang-golang prettyprint-override"><code>package main

import (
    &quot;fmt&quot;
    &quot;os&quot;

    &quot;helm.sh/helm/v3/pkg/action&quot;
    &quot;helm.sh/helm/v3/pkg/chart/loader&quot;
    &quot;helm.sh/helm/v3/pkg/kube&quot;
    &quot;helm.sh/helm/v3/pkg/release&quot;
    _ &quot;k8s.io/client-go/plugin/pkg/client/auth&quot;
)

func main() {
    chartPath := &quot;./charts/dns&quot;
    chart, err := loader.Load(chartPath)
    if err != nil {
        panic(err)
    }

    kubeconfigPath := findKubeConfig()
    releaseName := &quot;test&quot;
    releaseNamespace := &quot;default&quot;
    actionConfig := new(action.Configuration)
    if err := actionConfig.Init(kube.GetConfig(kubeconfigPath, &quot;&quot;, releaseNamespace), releaseNamespace, os.Getenv(&quot;HELM_DRIVER&quot;), func(format string, v ...interface{}) {
        fmt.Sprintf(format, v)
    }); err != nil {
        panic(err)
    }

    iCli := action.NewInstall(actionConfig)
    iCli.Namespace = releaseNamespace
    iCli.ReleaseName = releaseName
    rel, err := iCli.Run(chart, nil)
    if err != nil {
        panic(err)
    }
    fmt.Println(&quot;Successfully installed release: &quot;, rel.Name)
rel.Info.Status
    // check Release Status, feel free to run it in a go routine along the deletetion logic
    upCli := action.NewUpgrade(actionConfig)  
    upgradedRel, err := pollAndUpdate(rel.Info.Status, upCli) // see if its better to just run that code here directly :shrug:

// if we still on pending, then delete it
    if upgradedRel.Info.Status.IsPending() {
      unCli := action.NewUninstall(actionConfig)
      res, err := unCli.Run(rel.Name)
      if err != nil {
          panic(err)
      }
    }
}

func pollAndUpdate(originalRel *release.Release, upgradeCli *action.Upgrade) (*release.Release, error) {
    if !originalRel.Info.Status.IsPending() {
        return originalRel, nil
    }
    c := time.Tick(10 * time.Second) // we gonna time it out besides checking repeatedly
    var rel *release.Release = originalRel
    for _ = range c {
         //check the status and try and upgrade
         for rel.Info.Status.IsPending() { // https://pkg.go.dev/helm.sh/helm/v3@v3.5.4/pkg/release#Status.IsPending
             // run the upgrade command you have
             // its this function: https://github.com/helm/helm/blob/main/pkg/action/upgrade.go#L111
             rel, err := upgradeCli.Run(/*you gotta get all the values this needs*/)
             if err != nil {
                 panic(err)
             }
         }
    }
    return rel, nil
}
</code></pre>
