|
|
@@ -1,14 +1,12 @@
|
|
|
package stack
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
-
|
|
|
"github.com/porter-dev/porter/api/server/shared/config"
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
- "github.com/porter-dev/porter/internal/encryption"
|
|
|
"github.com/porter-dev/porter/internal/helm"
|
|
|
"github.com/porter-dev/porter/internal/helm/loader"
|
|
|
"github.com/porter-dev/porter/internal/models"
|
|
|
+ "helm.sh/helm/v3/pkg/release"
|
|
|
)
|
|
|
|
|
|
type applyAppResourceOpts struct {
|
|
|
@@ -21,7 +19,7 @@ type applyAppResourceOpts struct {
|
|
|
registries []*models.Registry
|
|
|
}
|
|
|
|
|
|
-func applyAppResource(opts *applyAppResourceOpts) error {
|
|
|
+func applyAppResource(opts *applyAppResourceOpts) (*release.Release, error) {
|
|
|
if opts.request.TemplateVersion == "latest" {
|
|
|
opts.request.TemplateVersion = ""
|
|
|
}
|
|
|
@@ -29,7 +27,7 @@ func applyAppResource(opts *applyAppResourceOpts) error {
|
|
|
chart, err := loader.LoadChartPublic(opts.request.TemplateRepoURL, opts.request.TemplateName, opts.request.TemplateVersion)
|
|
|
|
|
|
if err != nil {
|
|
|
- return err
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
conf := &helm.InstallChartConfig{
|
|
|
@@ -42,13 +40,7 @@ func applyAppResource(opts *applyAppResourceOpts) error {
|
|
|
Registries: opts.registries,
|
|
|
}
|
|
|
|
|
|
- _, err = opts.helmAgent.InstallChart(conf, opts.config.DOConf)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
+ return opts.helmAgent.InstallChart(conf, opts.config.DOConf)
|
|
|
}
|
|
|
|
|
|
type rollbackAppResourceOpts struct {
|
|
|
@@ -108,74 +100,4 @@ func deleteAppResource(opts *deleteAppResourceOpts) error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
-func cloneSourceConfigs(sourceConfigs []models.StackSourceConfig) ([]models.StackSourceConfig, error) {
|
|
|
- res := make([]models.StackSourceConfig, 0)
|
|
|
-
|
|
|
- // for now, only write source configs which are deployed as a docker image
|
|
|
- // TODO: add parsing/writes for git-based sources
|
|
|
- for _, sourceConfig := range sourceConfigs {
|
|
|
- uid, err := encryption.GenerateRandomBytes(16)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- res = append(res, models.StackSourceConfig{
|
|
|
- UID: uid,
|
|
|
- Name: sourceConfig.Name,
|
|
|
- ImageRepoURI: sourceConfig.ImageRepoURI,
|
|
|
- ImageTag: sourceConfig.ImageTag,
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- return res, nil
|
|
|
-}
|
|
|
-
|
|
|
-func cloneAppResources(
|
|
|
- appResources []models.StackResource,
|
|
|
- prevSourceConfigs []models.StackSourceConfig,
|
|
|
- newSourceConfigs []models.StackSourceConfig,
|
|
|
-) ([]models.StackResource, error) {
|
|
|
- res := make([]models.StackResource, 0)
|
|
|
-
|
|
|
- // for now, only write source configs which are deployed as a docker image
|
|
|
- // TODO: add parsing/writes for git-based sources
|
|
|
- for _, appResource := range appResources {
|
|
|
- uid, err := encryption.GenerateRandomBytes(16)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- var linkedSourceConfigUID string
|
|
|
-
|
|
|
- for _, prevSourceConfig := range prevSourceConfigs {
|
|
|
- if prevSourceConfig.UID == appResource.StackSourceConfigUID {
|
|
|
- // find the corresponding new source config
|
|
|
- for _, newSourceConfig := range newSourceConfigs {
|
|
|
- if newSourceConfig.Name == prevSourceConfig.Name {
|
|
|
- linkedSourceConfigUID = newSourceConfig.UID
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if linkedSourceConfigUID == "" {
|
|
|
- return nil, fmt.Errorf("source config does not exist in source config list")
|
|
|
- }
|
|
|
-
|
|
|
- res = append(res, models.StackResource{
|
|
|
- Name: appResource.Name,
|
|
|
- UID: uid,
|
|
|
- StackSourceConfigUID: linkedSourceConfigUID,
|
|
|
- TemplateRepoURL: appResource.TemplateRepoURL,
|
|
|
- TemplateName: appResource.TemplateName,
|
|
|
- TemplateVersion: appResource.TemplateVersion,
|
|
|
- HelmRevisionID: appResource.HelmRevisionID,
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- return res, nil
|
|
|
-}
|
|
|
-
|
|
|
// func setValuesWithSourceConfig(values map[string]interface{}, sourceConfig )
|