diff --git a/pkg/base/helm_v2.go b/pkg/base/helm_v2.go index 2a18b93c55..a898383fd0 100644 --- a/pkg/base/helm_v2.go +++ b/pkg/base/helm_v2.go @@ -1,7 +1,6 @@ package base import ( - "fmt" "io/ioutil" golog "log" "os" @@ -9,7 +8,6 @@ import ( "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" @@ -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{} diff --git a/pkg/base/helm_v3.go b/pkg/base/helm_v3.go index 6bc6eeace7..b14df7a661 100644 --- a/pkg/base/helm_v3.go +++ b/pkg/base/helm_v3.go @@ -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) diff --git a/pkg/handlers/config.go b/pkg/handlers/config.go index 007898b5fb..583424ce49 100644 --- a/pkg/handlers/config.go +++ b/pkg/handlers/config.go @@ -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)) @@ -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)) @@ -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)) @@ -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 } @@ -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 } diff --git a/pkg/kotsadmupstream/upstream.go b/pkg/kotsadmupstream/upstream.go index a391b2b1ee..9c07d60e4d 100644 --- a/pkg/kotsadmupstream/upstream.go +++ b/pkg/kotsadmupstream/upstream.go @@ -4,7 +4,6 @@ import ( "bufio" "fmt" "io" - "io/ioutil" "os" "path/filepath" "time" @@ -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, @@ -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 { @@ -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 -} diff --git a/pkg/online/online.go b/pkg/online/online.go index f835fdad37..ca165a8cd7 100644 --- a/pkg/online/online.go +++ b/pkg/online/online.go @@ -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 diff --git a/pkg/pull/pull.go b/pkg/pull/pull.go index 2e21817145..ac6f5909fd 100644 --- a/pkg/pull/pull.go +++ b/pkg/pull/pull.go @@ -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" @@ -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) { @@ -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) @@ -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, @@ -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, @@ -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, }, diff --git a/pkg/store/kotsstore/version_store.go b/pkg/store/kotsstore/version_store.go index 90e5ba565c..7189e68bb6 100644 --- a/pkg/store/kotsstore/version_store.go +++ b/pkg/store/kotsstore/version_store.go @@ -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")