Skip to content

Commit

Permalink
Respect timeout field for helm extensions in install2 command (#1603)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh authored Dec 10, 2024
1 parent 92666c5 commit 86e6719
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
8 changes: 7 additions & 1 deletion pkg/addons2/adminconsole/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ func (a *AdminConsole) Install(ctx context.Context, kcli client.Client, writer *
return errors.Wrap(err, "create helm client")
}

_, err = hcli.Install(ctx, releaseName, Metadata.Location, Metadata.Version, helmValues, namespace)
_, err = hcli.Install(ctx, helm.InstallOptions{
ReleaseName: releaseName,
ChartPath: Metadata.Location,
ChartVersion: Metadata.Version,
Values: helmValues,
Namespace: namespace,
})
if err != nil {
return errors.Wrap(err, "install admin console")
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/addons2/openebs/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ func (o *OpenEBS) Install(ctx context.Context, kcli client.Client, writer *spinn
return errors.Wrap(err, "create helm client")
}

_, err = hcli.Install(ctx, releaseName, Metadata.Location, Metadata.Version, helmValues, namespace)
_, err = hcli.Install(ctx, helm.InstallOptions{
ReleaseName: releaseName,
ChartPath: Metadata.Location,
ChartVersion: Metadata.Version,
Values: helmValues,
Namespace: namespace,
})
if err != nil {
return errors.Wrap(err, "install openebs")
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/addons2/registry/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ func (r *Registry) Install(ctx context.Context, kcli client.Client, writer *spin
return errors.Wrap(err, "create helm client")
}

_, err = hcli.Install(ctx, releaseName, Metadata.Location, Metadata.Version, helmValues, namespace)
_, err = hcli.Install(ctx, helm.InstallOptions{
ReleaseName: releaseName,
ChartPath: Metadata.Location,
ChartVersion: Metadata.Version,
Values: helmValues,
Namespace: namespace,
})
if err != nil {
return errors.Wrap(err, "install registry")
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/addons2/velero/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ func (v *Velero) Install(ctx context.Context, kcli client.Client, writer *spinne
return errors.Wrap(err, "create helm client")
}

_, err = hcli.Install(ctx, releaseName, Metadata.Location, Metadata.Version, helmValues, namespace)
_, err = hcli.Install(ctx, helm.InstallOptions{
ReleaseName: releaseName,
ChartPath: Metadata.Location,
ChartVersion: Metadata.Version,
Values: helmValues,
Namespace: namespace,
})
if err != nil {
return errors.Wrap(err, "install velero")
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ func Install(ctx context.Context) error {
return errors.Wrap(err, "unmarshal values")
}

_, err = hcli.Install(ctx, ext.Name, ext.ChartName, ext.Version, values, ext.TargetNS)
_, err = hcli.Install(ctx, helm.InstallOptions{
ReleaseName: ext.Name,
ChartPath: ext.ChartName,
ChartVersion: ext.Version,
Values: values,
Namespace: ext.TargetNS,
Timeout: ext.Timeout.Duration,
})
if err != nil {
return errors.Wrap(err, "helm install")
}
Expand Down
28 changes: 21 additions & 7 deletions pkg/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ type HelmOptions struct {
Writer io.Writer
}

type InstallOptions struct {
ReleaseName string
ChartPath string
ChartVersion string
Values map[string]interface{}
Namespace string
Timeout time.Duration
}

type Helm struct {
tmpdir string
kversion *semver.Version
Expand Down Expand Up @@ -248,22 +257,27 @@ func (h *Helm) getActionCfg(namespace string) (*action.Configuration, error) {
return cfg, nil
}

func (h *Helm) Install(ctx context.Context, releaseName string, chartPath string, chartVersion string, values map[string]interface{}, namespace string) (*release.Release, error) {
cfg, err := h.getActionCfg(namespace)
func (h *Helm) Install(ctx context.Context, opts InstallOptions) (*release.Release, error) {
cfg, err := h.getActionCfg(opts.Namespace)
if err != nil {
return nil, fmt.Errorf("get action configuration: %w", err)
}

client := action.NewInstall(cfg)
client.ReleaseName = releaseName
client.Namespace = namespace
client.ReleaseName = opts.ReleaseName
client.Namespace = opts.Namespace
client.Replace = true
client.CreateNamespace = true
client.WaitForJobs = true
client.Wait = true
client.Timeout = 5 * time.Minute

localPath, err := h.PullOCI(chartPath, chartVersion)
if opts.Timeout != 0 {
client.Timeout = opts.Timeout
} else {
client.Timeout = 5 * time.Minute
}

localPath, err := h.PullOCI(opts.ChartPath, opts.ChartVersion)
if err != nil {
return nil, fmt.Errorf("pull oci: %w", err)
}
Expand All @@ -280,7 +294,7 @@ func (h *Helm) Install(ctx context.Context, releaseName string, chartPath string
}
}

cleanVals := cleanUpGenericMap(values)
cleanVals := cleanUpGenericMap(opts.Values)

release, err := client.RunWithContext(ctx, chartRequested, cleanVals)
if err != nil {
Expand Down

0 comments on commit 86e6719

Please sign in to comment.