From becf764e0659e82f8f8eb2a4a598f211a6287bc2 Mon Sep 17 00:00:00 2001 From: Salah Al Saleh Date: Fri, 16 Feb 2024 15:23:47 +0000 Subject: [PATCH 1/4] Do not process online images in airgap mode for v1beta2 Helm charts --- pkg/airgap/airgap.go | 1 + pkg/airgap/update.go | 1 + pkg/apparchive/helm-v1beta2.go | 2 +- pkg/image/airgap.go | 2 +- pkg/pull/pull.go | 9 +++++---- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/airgap/airgap.go b/pkg/airgap/airgap.go index f8fedba44a..c8dbbe3704 100644 --- a/pkg/airgap/airgap.go +++ b/pkg/airgap/airgap.go @@ -212,6 +212,7 @@ func CreateAppFromAirgap(opts CreateAirgapAppOpts) (finalError error) { LicenseFile: licenseFile.Name(), ConfigFile: configFile, IdentityConfigFile: identityConfigFile, + IsAirgap: true, AirgapRoot: archiveDir, AirgapBundle: airgapBundle, Silent: !opts.IsAutomated, diff --git a/pkg/airgap/update.go b/pkg/airgap/update.go index 0e0b1e1349..b34cc56977 100644 --- a/pkg/airgap/update.go +++ b/pkg/airgap/update.go @@ -161,6 +161,7 @@ func UpdateAppFromPath(a *apptypes.App, airgapRoot string, airgapBundlePath stri Namespace: appNamespace, ConfigFile: filepath.Join(archiveDir, "upstream", "userdata", "config.yaml"), IdentityConfigFile: identityConfigFile, + IsAirgap: true, AirgapRoot: airgapRoot, AirgapBundle: airgapBundlePath, InstallationFile: filepath.Join(archiveDir, "upstream", "userdata", "installation.yaml"), diff --git a/pkg/apparchive/helm-v1beta2.go b/pkg/apparchive/helm-v1beta2.go index ab6bbde1f9..60ef747efe 100644 --- a/pkg/apparchive/helm-v1beta2.go +++ b/pkg/apparchive/helm-v1beta2.go @@ -146,7 +146,7 @@ func WriteV1Beta2HelmCharts(opts WriteV1Beta2HelmChartsOptions) error { return errors.Wrap(err, "failed to write values file") } - if !opts.ProcessImageOptions.RewriteImages || opts.ProcessImageOptions.AirgapRoot != "" { + if !opts.ProcessImageOptions.RewriteImages || opts.ProcessImageOptions.IsAirgap { // if an on-prem registry is not configured (which means it's an online installation) // there's no need to process/copy the images as they will be pulled from their original registries or through the replicated proxy. // if an on-prem registry is configured, but it's an airgap installation, we also don't need to process/copy the images diff --git a/pkg/image/airgap.go b/pkg/image/airgap.go index afa59d6b0f..aaed2989e1 100644 --- a/pkg/image/airgap.go +++ b/pkg/image/airgap.go @@ -114,7 +114,7 @@ func CopyAirgapImages(opts imagetypes.ProcessImageOptions, log *logger.CLILogger if err != nil { return errors.Wrap(err, "failed to push images from bundle") } - } else { + } else if opts.AirgapRoot != "" { err := TagAndPushImagesFromPath(opts.AirgapRoot, pushOpts) if err != nil { return errors.Wrap(err, "failed to push images from dir") diff --git a/pkg/pull/pull.go b/pkg/pull/pull.go index 8efa3df09a..3404a084b6 100644 --- a/pkg/pull/pull.go +++ b/pkg/pull/pull.go @@ -48,6 +48,7 @@ type PullOptions struct { LicenseFile string LicenseEndpointOverride string // only used for testing InstallationFile string + IsAirgap bool AirgapRoot string AirgapBundle string ConfigFile string @@ -295,7 +296,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) { IsOpenShift: k8sutil.IsOpenShift(clientset), IsGKEAutopilot: k8sutil.IsGKEAutopilot(clientset), IncludeMinio: pullOptions.IncludeMinio, - IsAirgap: pullOptions.AirgapRoot != "", + IsAirgap: pullOptions.IsAirgap, KotsadmID: k8sutil.GetKotsadmID(clientset), AppID: pullOptions.AppID, } @@ -321,7 +322,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) { Log: log, AppSlug: pullOptions.AppSlug, Sequence: pullOptions.AppSequence, - IsAirgap: pullOptions.AirgapRoot != "", + IsAirgap: pullOptions.IsAirgap, } log.ActionWithSpinner("Rendering KOTS custom resources") io.WriteString(pullOptions.ReportWriter, "Rendering KOTS custom resources\n") @@ -339,7 +340,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) { } log.FinishSpinner() - needsConfig, err := kotsadmconfig.NeedsConfiguration(pullOptions.AppSlug, pullOptions.AppSequence, pullOptions.AirgapRoot != "", renderedKotsKinds, registrySettings) + needsConfig, err := kotsadmconfig.NeedsConfiguration(pullOptions.AppSlug, pullOptions.AppSequence, pullOptions.IsAirgap, renderedKotsKinds, registrySettings) if err != nil { return "", errors.Wrap(err, "failed to check if version needs configuration") } @@ -351,7 +352,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) { RegistrySettings: pullOptions.RewriteImageOptions, CopyImages: !pullOptions.RewriteImageOptions.IsReadOnly, RootDir: pullOptions.RootDir, - IsAirgap: pullOptions.AirgapRoot != "", + IsAirgap: pullOptions.IsAirgap, AirgapRoot: pullOptions.AirgapRoot, AirgapBundle: pullOptions.AirgapBundle, CreateAppDir: pullOptions.CreateAppDir, From e304f6a2f0a755cdf92ec722158ff8acf88dd163 Mon Sep 17 00:00:00 2001 From: Salah Al Saleh Date: Fri, 16 Feb 2024 16:25:17 +0000 Subject: [PATCH 2/4] updates --- pkg/midstream/write.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/midstream/write.go b/pkg/midstream/write.go index 6e5598a8c0..173539e53f 100644 --- a/pkg/midstream/write.go +++ b/pkg/midstream/write.go @@ -111,15 +111,15 @@ func WriteMidstream(opts WriteOptions) (*Midstream, error) { opts.Log.ActionWithSpinner("Copying images") io.WriteString(opts.ProcessImageOptions.ReportWriter, "Copying images\n") - if opts.ProcessImageOptions.AirgapRoot == "" { - err := image.CopyOnlineImages(opts.ProcessImageOptions, allImages, opts.KotsKinds, opts.License, dockerHubRegistryCreds, opts.Log) + if opts.ProcessImageOptions.IsAirgap { + err := image.CopyAirgapImages(opts.ProcessImageOptions, opts.Log) if err != nil { - return nil, errors.Wrap(err, "failed to copy online images") + return nil, errors.Wrap(err, "failed to copy airgap images") } } else { - err := image.CopyAirgapImages(opts.ProcessImageOptions, opts.Log) + err := image.CopyOnlineImages(opts.ProcessImageOptions, allImages, opts.KotsKinds, opts.License, dockerHubRegistryCreds, opts.Log) if err != nil { - return nil, errors.Wrap(err, "failed to copy airgap images") + return nil, errors.Wrap(err, "failed to copy online images") } } } From 0aeca3b3eedd094bbfd5dd4cccb7f628ad849980 Mon Sep 17 00:00:00 2001 From: Salah Al Saleh Date: Fri, 16 Feb 2024 16:31:41 +0000 Subject: [PATCH 3/4] updates --- pkg/pull/pull.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pull/pull.go b/pkg/pull/pull.go index 3404a084b6..586fda7c67 100644 --- a/pkg/pull/pull.go +++ b/pkg/pull/pull.go @@ -363,7 +363,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) { if err := kotsutil.WriteKotsKinds(renderedKotsKindsMap, u.GetKotsKindsDir(writeUpstreamOptions)); err != nil { return "", errors.Wrap(err, "failed to write the rendered kots kinds") } - if processImageOptions.RewriteImages && processImageOptions.AirgapRoot != "" { + if processImageOptions.RewriteImages && processImageOptions.IsAirgap { // if this is an airgap install, we still need to process the images if err := image.CopyAirgapImages(processImageOptions, log); err != nil { return "", errors.Wrap(err, "failed to copy airgap images") From 1f76ccf7fb7ed65f1a8e8f10d6fbf5cd67443619 Mon Sep 17 00:00:00 2001 From: Salah Al Saleh Date: Fri, 16 Feb 2024 17:29:46 +0000 Subject: [PATCH 4/4] fix pull tests --- pkg/tests/pull/cases/configcontext/testcase.yaml | 1 - pkg/tests/pull/cases/customhostnames/testcase.yaml | 1 - pkg/tests/pull/cases/kotskinds/testcase.yaml | 1 - pkg/tests/pull/cases/multidoc/testcase.yaml | 1 - pkg/tests/pull/cases/needsconfig/testcase.yaml | 1 - pkg/tests/pull/cases/replicatedhelm/testcase.yaml | 1 - pkg/tests/pull/cases/samechartvariations/testcase.yaml | 1 - pkg/tests/pull/cases/simple/testcase.yaml | 1 - pkg/tests/pull/cases/subchart-alias/testcase.yaml | 1 - pkg/tests/pull/cases/subchart-crds/testcase.yaml | 1 - pkg/tests/pull/cases/subcharts/testcase.yaml | 1 - pkg/tests/pull/cases/taganddigest-norewrite/testcase.yaml | 1 - pkg/tests/pull/cases/taganddigest-rewrite/testcase.yaml | 1 - pkg/tests/pull/cases/v1beta2-charts/testcase.yaml | 1 - 14 files changed, 14 deletions(-) diff --git a/pkg/tests/pull/cases/configcontext/testcase.yaml b/pkg/tests/pull/cases/configcontext/testcase.yaml index 24c36a6eb6..a2dc01e2cb 100644 --- a/pkg/tests/pull/cases/configcontext/testcase.yaml +++ b/pkg/tests/pull/cases/configcontext/testcase.yaml @@ -2,7 +2,6 @@ Name: test helm pull PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/configcontext/upstream RootDir: cases/configcontext/results diff --git a/pkg/tests/pull/cases/customhostnames/testcase.yaml b/pkg/tests/pull/cases/customhostnames/testcase.yaml index b829aec2cc..05385c5044 100644 --- a/pkg/tests/pull/cases/customhostnames/testcase.yaml +++ b/pkg/tests/pull/cases/customhostnames/testcase.yaml @@ -2,7 +2,6 @@ Name: test custom hostnames PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/customhostnames/upstream RootDir: cases/customhostnames/results diff --git a/pkg/tests/pull/cases/kotskinds/testcase.yaml b/pkg/tests/pull/cases/kotskinds/testcase.yaml index 5b0fcd75a1..080188080e 100644 --- a/pkg/tests/pull/cases/kotskinds/testcase.yaml +++ b/pkg/tests/pull/cases/kotskinds/testcase.yaml @@ -2,7 +2,6 @@ Name: test templating kots kinds PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/kotskinds/upstream RootDir: cases/kotskinds/results diff --git a/pkg/tests/pull/cases/multidoc/testcase.yaml b/pkg/tests/pull/cases/multidoc/testcase.yaml index 9a92730878..fae3553d4c 100644 --- a/pkg/tests/pull/cases/multidoc/testcase.yaml +++ b/pkg/tests/pull/cases/multidoc/testcase.yaml @@ -2,7 +2,6 @@ Name: test multiple docs in a single file PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/multidoc/upstream RootDir: cases/multidoc/results diff --git a/pkg/tests/pull/cases/needsconfig/testcase.yaml b/pkg/tests/pull/cases/needsconfig/testcase.yaml index 0b819838e6..82693ef8fe 100644 --- a/pkg/tests/pull/cases/needsconfig/testcase.yaml +++ b/pkg/tests/pull/cases/needsconfig/testcase.yaml @@ -2,7 +2,6 @@ Name: test pulling with unset required config items PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/needsconfig/upstream RootDir: cases/needsconfig/results diff --git a/pkg/tests/pull/cases/replicatedhelm/testcase.yaml b/pkg/tests/pull/cases/replicatedhelm/testcase.yaml index 69bc1b5b28..8ba924c060 100644 --- a/pkg/tests/pull/cases/replicatedhelm/testcase.yaml +++ b/pkg/tests/pull/cases/replicatedhelm/testcase.yaml @@ -2,7 +2,6 @@ Name: test replicated helm pull without rewrite PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/replicatedhelm/upstream RootDir: cases/replicatedhelm/results diff --git a/pkg/tests/pull/cases/samechartvariations/testcase.yaml b/pkg/tests/pull/cases/samechartvariations/testcase.yaml index 34e1e6d034..0bce10bb5a 100644 --- a/pkg/tests/pull/cases/samechartvariations/testcase.yaml +++ b/pkg/tests/pull/cases/samechartvariations/testcase.yaml @@ -4,7 +4,6 @@ Name: test deploying variations of same helm chart PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/samechartvariations/upstream RootDir: cases/samechartvariations/results diff --git a/pkg/tests/pull/cases/simple/testcase.yaml b/pkg/tests/pull/cases/simple/testcase.yaml index 86aacc9a78..ad55b19a33 100644 --- a/pkg/tests/pull/cases/simple/testcase.yaml +++ b/pkg/tests/pull/cases/simple/testcase.yaml @@ -2,7 +2,6 @@ Name: test simple pull PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/simple/upstream RootDir: cases/simple/results diff --git a/pkg/tests/pull/cases/subchart-alias/testcase.yaml b/pkg/tests/pull/cases/subchart-alias/testcase.yaml index 493fd6c8be..8e34a604d2 100644 --- a/pkg/tests/pull/cases/subchart-alias/testcase.yaml +++ b/pkg/tests/pull/cases/subchart-alias/testcase.yaml @@ -2,7 +2,6 @@ Name: subchart alias PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/subchart-alias/upstream RootDir: cases/subchart-alias/results diff --git a/pkg/tests/pull/cases/subchart-crds/testcase.yaml b/pkg/tests/pull/cases/subchart-crds/testcase.yaml index 07a5e5526f..348f723ac5 100644 --- a/pkg/tests/pull/cases/subchart-crds/testcase.yaml +++ b/pkg/tests/pull/cases/subchart-crds/testcase.yaml @@ -2,7 +2,6 @@ Name: test subchart crds PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/subchart-crds/upstream RootDir: cases/subchart-crds/results diff --git a/pkg/tests/pull/cases/subcharts/testcase.yaml b/pkg/tests/pull/cases/subcharts/testcase.yaml index 62499369d6..34e8fb76ed 100644 --- a/pkg/tests/pull/cases/subcharts/testcase.yaml +++ b/pkg/tests/pull/cases/subcharts/testcase.yaml @@ -2,7 +2,6 @@ Name: test subcharts pull PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/subcharts/upstream RootDir: cases/subcharts/results diff --git a/pkg/tests/pull/cases/taganddigest-norewrite/testcase.yaml b/pkg/tests/pull/cases/taganddigest-norewrite/testcase.yaml index 7efe2feaa0..96cad188f6 100644 --- a/pkg/tests/pull/cases/taganddigest-norewrite/testcase.yaml +++ b/pkg/tests/pull/cases/taganddigest-norewrite/testcase.yaml @@ -2,7 +2,6 @@ Name: test tag and digest no rewrite PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/taganddigest-norewrite/upstream RootDir: cases/taganddigest-norewrite/results diff --git a/pkg/tests/pull/cases/taganddigest-rewrite/testcase.yaml b/pkg/tests/pull/cases/taganddigest-rewrite/testcase.yaml index b7647615f2..ca965930fa 100644 --- a/pkg/tests/pull/cases/taganddigest-rewrite/testcase.yaml +++ b/pkg/tests/pull/cases/taganddigest-rewrite/testcase.yaml @@ -2,7 +2,6 @@ Name: test tag and digest with rewrite PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/taganddigest-rewrite/upstream RootDir: cases/taganddigest-rewrite/results diff --git a/pkg/tests/pull/cases/v1beta2-charts/testcase.yaml b/pkg/tests/pull/cases/v1beta2-charts/testcase.yaml index 6caf793c02..d0bc3fb357 100644 --- a/pkg/tests/pull/cases/v1beta2-charts/testcase.yaml +++ b/pkg/tests/pull/cases/v1beta2-charts/testcase.yaml @@ -2,7 +2,6 @@ Name: test v1beta2 charts PullOptions: Namespace: app-namespace ExcludeAdminConsole: true - IsAirgap: true Silent: true LocalPath: cases/v1beta2-charts/upstream RootDir: cases/v1beta2-charts/results