1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

feat(helm): helm actions [r8s-259] (#715)

Co-authored-by: James Player <james.player@portainer.io>
Co-authored-by: Cara Ryan <cara.ryan@portainer.io>
Co-authored-by: stevensbkang <skan070@gmail.com>
This commit is contained in:
Ali 2025-05-13 22:15:04 +12:00 committed by GitHub
parent dfa32b6755
commit 4ee349bd6b
117 changed files with 4161 additions and 696 deletions

View file

@ -5,6 +5,7 @@ import "time"
type InstallOptions struct {
Name string
Chart string
Version string
Namespace string
Repo string
Wait bool

View file

@ -15,9 +15,10 @@ import (
// loadAndValidateChartWithPathOptions locates and loads the chart, and validates it.
// it also checks for chart dependencies and updates them if necessary.
// it returns the chart information.
func (hspm *HelmSDKPackageManager) loadAndValidateChartWithPathOptions(chartPathOptions *action.ChartPathOptions, chartName, repoURL string, dependencyUpdate bool, operation string) (*chart.Chart, error) {
func (hspm *HelmSDKPackageManager) loadAndValidateChartWithPathOptions(chartPathOptions *action.ChartPathOptions, chartName, version string, repoURL string, dependencyUpdate bool, operation string) (*chart.Chart, error) {
// Locate and load the chart
chartPathOptions.RepoURL = repoURL
chartPathOptions.Version = version
chartPath, err := chartPathOptions.LocateChart(chartName, hspm.settings)
if err != nil {
log.Error().

View file

@ -3,6 +3,7 @@ package sdk
import (
"github.com/portainer/portainer/pkg/libhelm/options"
"github.com/portainer/portainer/pkg/libhelm/release"
"github.com/portainer/portainer/pkg/libhelm/time"
"github.com/rs/zerolog/log"
"helm.sh/helm/v3/pkg/action"
sdkrelease "helm.sh/helm/v3/pkg/release"
@ -82,10 +83,11 @@ func convert(sdkRelease *sdkrelease.Release, values release.Values) *release.Rel
Namespace: sdkRelease.Namespace,
Version: sdkRelease.Version,
Info: &release.Info{
Status: release.Status(sdkRelease.Info.Status),
Notes: sdkRelease.Info.Notes,
Resources: resources,
Description: sdkRelease.Info.Description,
Status: release.Status(sdkRelease.Info.Status),
Notes: sdkRelease.Info.Notes,
Resources: resources,
Description: sdkRelease.Info.Description,
LastDeployed: time.Time(sdkRelease.Info.LastDeployed),
},
Manifest: sdkRelease.Manifest,
Chart: release.Chart{

View file

@ -1,6 +1,8 @@
package sdk
import (
"sort"
"github.com/portainer/portainer/pkg/libhelm/options"
"github.com/portainer/portainer/pkg/libhelm/release"
"github.com/portainer/portainer/pkg/libhelm/time"
@ -44,6 +46,11 @@ func (hspm *HelmSDKPackageManager) GetHistory(historyOptions options.HistoryOpti
result = append(result, convertHistory(r))
}
// sort the result by version (latest first)
sort.Slice(result, func(i, j int) bool {
return result[i].Version > result[j].Version
})
return result, nil
}

View file

@ -60,7 +60,7 @@ func (hspm *HelmSDKPackageManager) install(installOpts options.InstallOptions) (
return nil, errors.Wrap(err, "failed to get Helm values from file for helm release installation")
}
chart, err := hspm.loadAndValidateChartWithPathOptions(&installClient.ChartPathOptions, installOpts.Chart, installOpts.Repo, installClient.DependencyUpdate, "release installation")
chart, err := hspm.loadAndValidateChartWithPathOptions(&installClient.ChartPathOptions, installOpts.Chart, installOpts.Version, installOpts.Repo, installClient.DependencyUpdate, "release installation")
if err != nil {
log.Error().
Str("context", "HelmClient").
@ -109,7 +109,6 @@ func (hspm *HelmSDKPackageManager) install(installOpts options.InstallOptions) (
// and return the install client.
func initInstallClient(actionConfig *action.Configuration, installOpts options.InstallOptions) (*action.Install, error) {
installClient := action.NewInstall(actionConfig)
installClient.CreateNamespace = true
installClient.DependencyUpdate = true
installClient.ReleaseName = installOpts.Name
installClient.ChartPathOptions.RepoURL = installOpts.Repo

View file

@ -84,7 +84,7 @@ func (hspm *HelmSDKPackageManager) Upgrade(upgradeOpts options.InstallOptions) (
return nil, errors.Wrap(err, "failed to get Helm values from file for helm release upgrade")
}
chart, err := hspm.loadAndValidateChartWithPathOptions(&upgradeClient.ChartPathOptions, upgradeOpts.Chart, upgradeOpts.Repo, upgradeClient.DependencyUpdate, "release upgrade")
chart, err := hspm.loadAndValidateChartWithPathOptions(&upgradeClient.ChartPathOptions, upgradeOpts.Chart, upgradeOpts.Version, upgradeOpts.Repo, upgradeClient.DependencyUpdate, "release upgrade")
if err != nil {
log.Error().
Str("context", "HelmClient").

View file

@ -62,8 +62,7 @@ func (hspm *HelmSDKPackageManager) getValues(getOpts options.GetOptions) (releas
return release.Values{}, err
}
// Create client for user supplied values
userValuesClient := action.NewGetValues(actionConfig)
userValuesClient := hspm.initValuesClient(actionConfig, getOpts)
userSuppliedValues, err := userValuesClient.Run(getOpts.Name)
if err != nil {
log.Error().
@ -116,3 +115,11 @@ func (hspm *HelmSDKPackageManager) getValues(getOpts options.GetOptions) (releas
ComputedValues: computedValuesString,
}, nil
}
func (hspm *HelmSDKPackageManager) initValuesClient(actionConfig *action.Configuration, getOpts options.GetOptions) *action.GetValues {
valuesClient := action.NewGetValues(actionConfig)
if getOpts.Revision > 0 {
valuesClient.Version = getOpts.Revision
}
return valuesClient
}