Skip to content

Commit

Permalink
Merge pull request #3490 from replicatedhq/revert-3452-divolgin/sc-55…
Browse files Browse the repository at this point in the history
…103/cannot-deploy-a-helm-chart-using-kots-install

Revert "Allow required values in helm charts"
  • Loading branch information
divolgin committed Dec 10, 2022
2 parents 41b8d05 + f9429bd commit e3f18d1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 131 deletions.
7 changes: 1 addition & 6 deletions pkg/base/helm_v2.go
@@ -1,15 +1,13 @@
package base

import (
"fmt"
"io/ioutil"
golog "log"
"os"
"strings"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/util"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/renderutil"
Expand Down Expand Up @@ -60,10 +58,7 @@ func renderHelmV2(chartName string, chartPath string, vals map[string]interface{

rendered, err := renderutil.Render(c, config, renderOpts)
if err != nil {
return nil, nil, util.ActionableError{
NoRetry: true,
Message: fmt.Sprintf("helm v2 render failed with error: %v", err),
}
return nil, nil, errors.Wrap(err, "failed to render chart")
}

baseFiles := []BaseFile{}
Expand Down
5 changes: 1 addition & 4 deletions pkg/base/helm_v3.go
Expand Up @@ -54,10 +54,7 @@ func renderHelmV3(chartName string, chartPath string, vals map[string]interface{

rel, err := client.Run(chartRequested, vals)
if err != nil {
return nil, nil, util.ActionableError{
NoRetry: true,
Message: fmt.Sprintf("helm v3 render failed with error: %v", err),
}
return nil, nil, errors.Wrap(err, "failed to render chart")
}

coalescedValues, err := chartutil.CoalesceValues(rel.Chart, rel.Config)
Expand Down
43 changes: 6 additions & 37 deletions pkg/handlers/config.go
Expand Up @@ -190,24 +190,7 @@ func (h *Handler) UpdateAppConfig(w http.ResponseWriter, r *http.Request) {
return
}

archiveDir, err := ioutil.TempDir("", "kotsadm")
if err != nil {
updateAppConfigResponse.Error = "failed to create temp dir"
logger.Error(errors.Wrap(err, updateAppConfigResponse.Error))
JSON(w, http.StatusInternalServerError, updateAppConfigResponse)
return
}
defer os.RemoveAll(archiveDir)

err = store.GetStore().GetAppVersionArchive(foundApp.ID, updateAppConfigRequest.Sequence, archiveDir)
if err != nil {
updateAppConfigResponse.Error = "failed to get app version archive"
logger.Error(errors.Wrap(err, updateAppConfigResponse.Error))
JSON(w, http.StatusInternalServerError, updateAppConfigResponse)
return
}

createNewVersion, err := shouldCreateNewAppVersion(archiveDir, foundApp.ID, updateAppConfigRequest.Sequence)
createNewVersion, err := shouldCreateNewAppVersion(foundApp.ID, updateAppConfigRequest.Sequence)
if err != nil {
updateAppConfigResponse.Error = "failed to check if version should be created"
logger.Error(errors.Wrap(err, updateAppConfigResponse.Error))
Expand Down Expand Up @@ -360,7 +343,7 @@ func (h *Handler) LiveAppConfig(w http.ResponseWriter, r *http.Request) {
ReadOnly: registryInfo.IsReadOnly,
}

createNewVersion, err = shouldCreateNewAppVersion(archiveDir, foundApp.GetID(), liveAppConfigRequest.Sequence)
createNewVersion, err = shouldCreateNewAppVersion(foundApp.GetID(), liveAppConfigRequest.Sequence)
if err != nil {
liveAppConfigResponse.Error = "failed to check new version"
logger.Error(errors.Wrap(err, liveAppConfigResponse.Error))
Expand Down Expand Up @@ -606,7 +589,7 @@ func (h *Handler) CurrentAppConfig(w http.ResponseWriter, r *http.Request) {
ReadOnly: registryInfo.IsReadOnly,
}

createNewVersion, err = shouldCreateNewAppVersion(archiveDir, foundApp.GetID(), sequence)
createNewVersion, err = shouldCreateNewAppVersion(foundApp.GetID(), sequence)
if err != nil {
currentAppConfigResponse.Error = "failed to check new version"
logger.Error(errors.Wrap(err, currentAppConfigResponse.Error))
Expand Down Expand Up @@ -691,17 +674,8 @@ func isVersionConfigEditable(app *apptypes.App, sequence int64) (bool, error) {
return false, nil
}

func shouldCreateNewAppVersion(archiveDir string, appID string, sequence int64) (bool, error) {
// Updates are allowed for any version that does not have base rendered.
if _, err := os.Stat(filepath.Join(archiveDir, "base")); err != nil {
if os.IsNotExist(err) {
return false, nil
} else {
return false, errors.Wrap(err, "failed to stat base dir")
}
}

// If base is rendered, updates are allowed only for sequence 0 and only when it's pending config.
func shouldCreateNewAppVersion(appID string, sequence int64) (bool, error) {
// Updates are allowed only for sequence 0 and only when it's pending config.
if sequence > 0 {
return true, nil
}
Expand Down Expand Up @@ -852,12 +826,7 @@ func updateAppConfig(updateApp *apptypes.App, sequence int64, configGroups []kot

err = render.RenderDir(archiveDir, app, downstreams, registrySettings, renderSequence)
if err != nil {
cause := errors.Cause(err)
if _, ok := cause.(util.ActionableError); ok {
updateAppConfigResponse.Error = cause.Error()
} else {
updateAppConfigResponse.Error = "failed to render archive directory"
}
updateAppConfigResponse.Error = "failed to render archive directory"
return updateAppConfigResponse, err
}

Expand Down
39 changes: 3 additions & 36 deletions pkg/kotsadmupstream/upstream.go
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -205,11 +204,6 @@ func DownloadUpdate(appID string, update types.Update, skipPreflights bool, skip
return
}

if err := cleanBaseArchive(archiveDir); err != nil {
finalError = errors.Wrap(err, "failed to clean base archive")
return
}

pullOptions := kotspull.PullOptions{
LicenseObj: latestLicense,
Namespace: appNamespace,
Expand Down Expand Up @@ -238,12 +232,9 @@ func DownloadUpdate(appID string, update types.Update, skipPreflights bool, skip
SkipCompatibilityCheck: skipCompatibilityCheck,
}

_, err = kotspull.Pull(fmt.Sprintf("replicated://%s", beforeKotsKinds.License.Spec.AppSlug), pullOptions)
if err != nil {
if errors.Cause(err) != kotspull.ErrConfigNeeded {
finalError = errors.Wrap(err, "failed to pull")
return
}
if _, err := kotspull.Pull(fmt.Sprintf("replicated://%s", beforeKotsKinds.License.Spec.AppSlug), pullOptions); err != nil {
finalError = errors.Wrap(err, "failed to pull")
return
}

if update.AppSequence == nil {
Expand Down Expand Up @@ -289,27 +280,3 @@ func DownloadUpdate(appID string, update types.Update, skipPreflights bool, skip

return
}

func cleanBaseArchive(path string) error {
files, err := ioutil.ReadDir(path)
if err != nil {
return errors.Wrap(err, "failed to read dir")
}

// "overlays" contains manual kustomizations.
// "upstream" contains config values, known images, and other important installation info
// everything else should be deleted and generated again
for _, file := range files {
switch file.Name() {
case "overlays", "upstream":
continue
default:
err := os.RemoveAll(filepath.Join(path, file.Name()))
if err != nil {
return errors.Wrapf(err, "failed to delete %s", file.Name())
}
}
}

return nil
}
4 changes: 1 addition & 3 deletions pkg/online/online.go
Expand Up @@ -158,9 +158,7 @@ func CreateAppFromOnline(opts CreateOnlineAppOpts) (_ *kotsutil.KotsKinds, final
}

if _, err := pull.Pull(opts.UpstreamURI, pullOptions); err != nil {
if errors.Cause(err) != pull.ErrConfigNeeded {
return nil, errors.Wrap(err, "failed to pull")
}
return nil, errors.Wrap(err, "failed to pull")
}

// Create the downstream
Expand Down
43 changes: 8 additions & 35 deletions pkg/pull/pull.go
Expand Up @@ -17,16 +17,14 @@ import (
"github.com/replicatedhq/kots/pkg/base"
"github.com/replicatedhq/kots/pkg/crypto"
"github.com/replicatedhq/kots/pkg/docker/registry"
dockerregistrytypes "github.com/replicatedhq/kots/pkg/docker/registry/types"
registrytypes "github.com/replicatedhq/kots/pkg/docker/registry/types"
"github.com/replicatedhq/kots/pkg/downstream"
"github.com/replicatedhq/kots/pkg/k8sdoc"
"github.com/replicatedhq/kots/pkg/k8sutil"
"github.com/replicatedhq/kots/pkg/kotsadmconfig"
"github.com/replicatedhq/kots/pkg/kotsutil"
kotslicense "github.com/replicatedhq/kots/pkg/license"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/midstream"
registrytypes "github.com/replicatedhq/kots/pkg/registry/types"
"github.com/replicatedhq/kots/pkg/replicatedapp"
"github.com/replicatedhq/kots/pkg/upstream"
upstreamtypes "github.com/replicatedhq/kots/pkg/upstream/types"
Expand Down Expand Up @@ -79,10 +77,6 @@ type RewriteImageOptions struct {
IsReadOnly bool
}

var (
ErrConfigNeeded = errors.New("version needs config")
)

// PullApplicationMetadata will return the application metadata yaml, if one is
// available for the upstream
func PullApplicationMetadata(upstreamURI string, versionLabel string) (*replicatedapp.ApplicationMetadata, error) {
Expand Down Expand Up @@ -299,27 +293,6 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) {
}
log.FinishSpinner()

kotsKinds, err := kotsutil.LoadKotsKindsFromPath(u.GetUpstreamDir(writeUpstreamOptions))
if err != nil {
return "", errors.Wrap(err, "failed to load kotskinds")
}

registrySettings := registrytypes.RegistrySettings{
Hostname: pullOptions.RewriteImageOptions.Host,
Namespace: pullOptions.RewriteImageOptions.Namespace,
Username: pullOptions.RewriteImageOptions.Username,
Password: pullOptions.RewriteImageOptions.Password,
IsReadOnly: pullOptions.RewriteImageOptions.IsReadOnly,
}

needsConfig, err := kotsadmconfig.NeedsConfiguration(pullOptions.AppSlug, pullOptions.AppSequence, pullOptions.AirgapRoot != "", kotsKinds, registrySettings)
if err != nil {
return "", errors.Wrap(err, "failed to check if version needs configuration")
}
if needsConfig {
return "", ErrConfigNeeded
}

renderDir := pullOptions.RootDir
if pullOptions.CreateAppDir {
renderDir = filepath.Join(pullOptions.RootDir, u.Name)
Expand Down Expand Up @@ -683,15 +656,15 @@ func rewriteBaseImages(pullOptions PullOptions, baseDir string, kotsKinds *kotsu
rewriteImageOptions := base.RewriteImageOptions{
BaseDir: baseDir,
Log: log,
SourceRegistry: dockerregistrytypes.RegistryOptions{
SourceRegistry: registrytypes.RegistryOptions{
Endpoint: replicatedRegistryInfo.Registry,
ProxyEndpoint: replicatedRegistryInfo.Proxy,
},
DockerHubRegistry: dockerregistrytypes.RegistryOptions{
DockerHubRegistry: registrytypes.RegistryOptions{
Username: dockerHubRegistryCreds.Username,
Password: dockerHubRegistryCreds.Password,
},
DestRegistry: dockerregistrytypes.RegistryOptions{
DestRegistry: registrytypes.RegistryOptions{
Endpoint: pullOptions.RewriteImageOptions.Host,
Namespace: pullOptions.RewriteImageOptions.Namespace,
Username: pullOptions.RewriteImageOptions.Username,
Expand Down Expand Up @@ -726,12 +699,12 @@ func processAirgapImages(pullOptions PullOptions, pushImages bool, kotsKinds *ko
CreateAppDir: pullOptions.CreateAppDir,
PushImages: !pullOptions.RewriteImageOptions.IsReadOnly && pushImages,
Log: log,
ReplicatedRegistry: dockerregistrytypes.RegistryOptions{
ReplicatedRegistry: registrytypes.RegistryOptions{
Endpoint: replicatedRegistryInfo.Registry,
ProxyEndpoint: replicatedRegistryInfo.Proxy,
},
ReportWriter: pullOptions.ReportWriter,
DestinationRegistry: dockerregistrytypes.RegistryOptions{
DestinationRegistry: registrytypes.RegistryOptions{
Endpoint: pullOptions.RewriteImageOptions.Host,
Namespace: pullOptions.RewriteImageOptions.Namespace,
Username: pullOptions.RewriteImageOptions.Username,
Expand Down Expand Up @@ -773,11 +746,11 @@ func findPrivateImages(writeMidstreamOptions midstream.WriteOptions, b *base.Bas
findPrivateImagesOptions := base.FindPrivateImagesOptions{
BaseDir: writeMidstreamOptions.BaseDir,
AppSlug: license.Spec.AppSlug,
ReplicatedRegistry: dockerregistrytypes.RegistryOptions{
ReplicatedRegistry: registrytypes.RegistryOptions{
Endpoint: replicatedRegistryInfo.Registry,
ProxyEndpoint: replicatedRegistryInfo.Proxy,
},
DockerHubRegistry: dockerregistrytypes.RegistryOptions{
DockerHubRegistry: registrytypes.RegistryOptions{
Username: dockerHubRegistryCreds.Username,
Password: dockerHubRegistryCreds.Password,
},
Expand Down
12 changes: 2 additions & 10 deletions pkg/store/kotsstore/version_store.go
Expand Up @@ -242,16 +242,8 @@ func (s *KOTSStore) GetTargetKotsVersionForVersion(appID string, sequence int64)
func (s *KOTSStore) CreateAppVersionArchive(appID string, sequence int64, archivePath string) error {
paths := []string{
filepath.Join(archivePath, "upstream"),
}

basePath := filepath.Join(archivePath, "base")
if _, err := os.Stat(basePath); err == nil {
paths = append(paths, basePath)
}

overlaysPath := filepath.Join(archivePath, "overlays")
if _, err := os.Stat(overlaysPath); err == nil {
paths = append(paths, overlaysPath)
filepath.Join(archivePath, "base"),
filepath.Join(archivePath, "overlays"),
}

skippedFilesPath := filepath.Join(archivePath, "skippedFiles")
Expand Down

0 comments on commit e3f18d1

Please sign in to comment.