Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rendered kots kinds #4239

Merged
merged 15 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cmd/imagedeps/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func TestFunctional(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
rootDir := path.Join("testdata", tc.name)

expectedConstants, err := ioutil.ReadFile(path.Join(rootDir, "constants.go"))
expectedConstants, err := os.ReadFile(path.Join(rootDir, "constants.go"))
require.Nil(t, err)

expectedEnvs, err := ioutil.ReadFile(path.Join(rootDir, ".image.env"))
expectedEnvs, err := os.ReadFile(path.Join(rootDir, ".image.env"))
require.Nil(t, err)

tempDir := t.TempDir()
Expand Down Expand Up @@ -178,10 +178,10 @@ func TestFunctional(t *testing.T) {

require.Nil(t, err)

actualConstants, err := ioutil.ReadFile(constantFile)
actualConstants, err := os.ReadFile(constantFile)
require.Nil(t, err)

actualEnv, err := ioutil.ReadFile(envFile)
actualEnv, err := os.ReadFile(envFile)
require.Nil(t, err)

require.Equal(t, string(expectedConstants), string(actualConstants))
Expand All @@ -195,10 +195,10 @@ func TestFunctional(t *testing.T) {
require.Nil(t, err)

for _, f := range files {
expectedContent, err := ioutil.ReadFile(path.Join(expectedDir, f.Name()))
expectedContent, err := os.ReadFile(path.Join(expectedDir, f.Name()))
require.Nil(t, err)

actualContent, err := ioutil.ReadFile(path.Join(actualDir, f.Name()))
actualContent, err := os.ReadFile(path.Join(actualDir, f.Name()))
require.Nil(t, err)

require.Equal(t, string(expectedContent), string(actualContent))
Expand All @@ -220,7 +220,7 @@ func copyDirFiles(inputDir string, outputDir string) error {
}

for _, f := range files {
content, err := ioutil.ReadFile(path.Join(inputDir, f.Name()))
content, err := os.ReadFile(path.Join(inputDir, f.Name()))
if err != nil {
return errors.Wrapf(err, "failed to read file %s", path.Join(inputDir, f.Name()))
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/kots/cli/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
import (
"context"
"fmt"
"io/ioutil"
"os"

"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/identity"
Expand Down Expand Up @@ -65,7 +65,7 @@ func IdentityServiceInstallCmd() *cobra.Command {

identityConfig := kotsv1beta1.IdentityConfig{}
if identityConfigPath := v.GetString("identity-config"); identityConfigPath != "" {
content, err := ioutil.ReadFile(identityConfigPath)
content, err := os.ReadFile(identityConfigPath)
if err != nil {
return errors.Wrap(err, "failed to read identity service config file")
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func IdentityServiceConfigureCmd() *cobra.Command {

identityConfig := kotsv1beta1.IdentityConfig{}
if identityConfigPath := v.GetString("identity-config"); identityConfigPath != "" {
content, err := ioutil.ReadFile(identityConfigPath)
content, err := os.ReadFile(identityConfigPath)
if err != nil {
return errors.Wrap(err, "failed to read identity service config file")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/kots/cli/ingress.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cli

import (
"io/ioutil"
"os"

"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/identity"
Expand Down Expand Up @@ -54,7 +54,7 @@ func IngressInstallCmd() *cobra.Command {

ingressConfig := kotsv1beta1.IngressConfig{}
if ingressConfigPath := v.GetString("ingress-config"); ingressConfigPath != "" {
content, err := ioutil.ReadFile(ingressConfigPath)
content, err := os.ReadFile(ingressConfigPath)
if err != nil {
return errors.Wrap(err, "failed to read ingress service config file")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/kots/cli/pull.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -151,7 +150,7 @@ func getAppSlugForPull(uri string, licenseFile string) (string, error) {
return appSlug, nil
}

licenseData, err := ioutil.ReadFile(licenseFile)
licenseData, err := os.ReadFile(licenseFile)
if err != nil {
return "", errors.Wrap(err, "failed to read license file")
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/kots/cli/set-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -176,7 +175,7 @@ func getConfigValuesFromArgs(v *viper.Viper, args []string) ([]byte, error) {
return nil, errors.New("--config-file cannot be used with other key/value arguments")
}

data, err := ioutil.ReadFile(fileName)
data, err := os.ReadFile(fileName)
if err != nil {
return nil, errors.Wrap(err, "failed to load config from file")
}
Expand Down Expand Up @@ -206,7 +205,7 @@ func getConfigValuesFromArgs(v *viper.Viper, args []string) ([]byte, error) {
Value: value,
}
} else if valueFile != "" {
data, err := ioutil.ReadFile(valueFile)
data, err := os.ReadFile(valueFile)
if err != nil {
return nil, errors.Wrap(err, "failed to load value from file")
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/kots/cli/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cli
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -394,7 +393,7 @@ func VeleroConfigureOtherS3Cmd() *cobra.Command {
if err != nil {
return err
}
caCertData, err = ioutil.ReadFile(realPath)
caCertData, err = os.ReadFile(realPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -506,7 +505,7 @@ func VeleroConfigureGCPServiceAccount() *cobra.Command {

jsonFile := ""
if jsonFilePath := v.GetString("json-file"); jsonFilePath != "" {
content, err := ioutil.ReadFile(jsonFilePath)
content, err := os.ReadFile(jsonFilePath)
if err != nil {
return errors.Wrap(err, "failed to read json file")
}
Expand Down
4 changes: 2 additions & 2 deletions integration/docker/registry/temp_registry_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package replicated

import (
"io/ioutil"
"os"
"path"
"reflect"
"testing"
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestTempRegistry_GetImageLayers(t *testing.T) {

req := require.New(t)

manifestsContent, err := ioutil.ReadFile(path.Join("assets", "manifests.yaml"))
manifestsContent, err := os.ReadFile(path.Join("assets", "manifests.yaml"))
req.NoError(err)

var manifests map[string]string
Expand Down
4 changes: 2 additions & 2 deletions integration/replicated/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func generateReplicatedAppArchive(rawArchivePath string) ([]byte, error) {
if err := tarGz.Archive([]string{rawArchivePath}, archiveFile); err != nil {
return nil, errors.Wrap(err, "failed to create archive")
}
b, err := ioutil.ReadFile(archiveFile)
b, err := os.ReadFile(archiveFile)
if err != nil {
return nil, errors.Wrap(err, "failed to read archive file")
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func generateExpectedFilesystem(namespace, rawArchivePath string) ([]byte, error
if err := tarGz.Archive(paths, archiveFile); err != nil {
return nil, errors.Wrap(err, "failed to create archive")
}
b, err := ioutil.ReadFile(archiveFile)
b, err := os.ReadFile(archiveFile)
if err != nil {
return nil, errors.Wrap(err, "failed to read archive file")
}
Expand Down
9 changes: 5 additions & 4 deletions integration/replicated/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package replicated

import (
"io/ioutil"
"os"
"path"
"testing"

Expand Down Expand Up @@ -42,11 +43,11 @@ func Test_PullReplicated(t *testing.T) {
t.Run(testDir.Name(), func(t *testing.T) {
req := require.New(t)

archiveData, err := ioutil.ReadFile(path.Join(testResourcePath, "archive.tar.gz"))
archiveData, err := os.ReadFile(path.Join(testResourcePath, "archive.tar.gz"))
req.NoError(err)

licenseFilepath := path.Join(testResourcePath, "license.yaml")
licenseFile, err := ioutil.ReadFile(licenseFilepath)
licenseFile, err := os.ReadFile(licenseFilepath)
req.NoError(err)

server, err := StartMockServer(archiveData, licenseFile)
Expand Down Expand Up @@ -84,7 +85,7 @@ func Test_PullReplicated(t *testing.T) {
err = tarGz.Archive(paths, path.Join(actualFilesystemDir, "archive.tar.gz"))
req.NoError(err)

actualFilesystemBytes, err := ioutil.ReadFile(path.Join(actualFilesystemDir, "archive.tar.gz"))
actualFilesystemBytes, err := os.ReadFile(path.Join(actualFilesystemDir, "archive.tar.gz"))
req.NoError(err)

// create an archive of the expected
Expand All @@ -98,7 +99,7 @@ func Test_PullReplicated(t *testing.T) {
err = tarGz.Archive(paths, path.Join(expectedFilesystemDir, "archive.tar.gz"))
req.NoError(err)

expectedFilesystemBytes, err := ioutil.ReadFile(path.Join(expectedFilesystemDir, "archive.tar.gz"))
expectedFilesystemBytes, err := os.ReadFile(path.Join(expectedFilesystemDir, "archive.tar.gz"))
req.NoError(err)

compareOptions := util.CompareOptions{
Expand Down
2 changes: 1 addition & 1 deletion kurl_proxy/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ type kotsadmApp struct {
func kotsadmApplication() (kotsadmApp, error) {
app := kotsadmApp{}

data, err := ioutil.ReadFile("/etc/kotsadm/application.yaml")
data, err := os.ReadFile("/etc/kotsadm/application.yaml")
if err != nil {
return app, errors.Wrap(err, "read file /etc/kotsadm/application.yaml")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/airgap/airgap.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func CreateAppFromAirgap(opts CreateAirgapAppOpts) (finalError error) {
return errors.Wrap(err, "failed to create support bundle dependencies")
}

kotsKinds, err := kotsutil.LoadKotsKindsFromPath(filepath.Join(tmpRoot, "upstream"))
kotsKinds, err := kotsutil.LoadKotsKinds(tmpRoot)
if err != nil {
return errors.Wrap(err, "failed to load kotskinds from path")
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/airgap/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func UpdateAppFromPath(a *apptypes.App, airgapRoot string, airgapBundlePath stri
}
defer os.RemoveAll(archiveDir)

beforeKotsKinds, err := kotsutil.LoadKotsKindsFromPath(filepath.Join(archiveDir, "upstream"))
beforeKotsKinds, err := kotsutil.LoadKotsKinds(archiveDir)
if err != nil {
return errors.Wrap(err, "failed to load current kotskinds")
}
Expand Down Expand Up @@ -177,6 +177,7 @@ func UpdateAppFromPath(a *apptypes.App, airgapRoot string, airgapBundlePath stri
AppSlug: a.Slug,
AppSequence: appSequence,
SkipCompatibilityCheck: skipCompatibilityCheck,
KotsKinds: beforeKotsKinds,
}

if _, err := pull.Pull(fmt.Sprintf("replicated://%s", beforeKotsKinds.License.Spec.AppSlug), pullOptions); err != nil {
Expand All @@ -185,7 +186,7 @@ func UpdateAppFromPath(a *apptypes.App, airgapRoot string, airgapBundlePath stri
}
}

afterKotsKinds, err := kotsutil.LoadKotsKindsFromPath(filepath.Join(archiveDir, "upstream"))
afterKotsKinds, err := kotsutil.LoadKotsKinds(archiveDir)
if err != nil {
return errors.Wrap(err, "failed to read after kotskinds")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apparchive/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func GetRenderedApp(versionArchive string, downstreamName, kustomizeBinPath stri
return nil
}

content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return errors.Wrapf(err, "failed to read file %s", path)
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func cleanBaseApp(baseDir string, filter func(path string) (bool, error)) error
}
}

content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return errors.Wrapf(err, "failed to read file %s", path)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apparchive/helm-v1beta1.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func RenderChartsArchive(baseDir string, overlaysDir string, downstreamName stri
}

for _, filename := range metadataFiles {
content, err := ioutil.ReadFile(filepath.Join(sourceChartsDir, relPath, filename))
content, err := os.ReadFile(filepath.Join(sourceChartsDir, relPath, filename))
if err != nil {
if os.IsNotExist(err) {
continue
Expand Down
4 changes: 2 additions & 2 deletions pkg/apparchive/helm-v1beta1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ kind: Kustomization
req.NoError(err)

for wantPath, wantContent := range tt.wantRenderedFilesMap {
gotContent, err := ioutil.ReadFile(filepath.Join(extracted, "charts", wantPath))
gotContent, err := os.ReadFile(filepath.Join(extracted, "charts", wantPath))
require.Nil(t, err)

if !reflect.DeepEqual(gotContent, wantContent) {
Expand Down Expand Up @@ -517,7 +517,7 @@ kind: Kustomization
req.NoError(err)

for wantPath, wantContent := range tt.wantRenderedFilesMap {
gotContent, err := ioutil.ReadFile(filepath.Join(extracted, "charts", wantPath))
gotContent, err := os.ReadFile(filepath.Join(extracted, "charts", wantPath))
require.Nil(t, err)

if !reflect.DeepEqual(gotContent, wantContent) {
Expand Down
20 changes: 10 additions & 10 deletions pkg/apparchive/helm-v1beta2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/replicatedhq/kots/pkg/logger"
upstreamtypes "github.com/replicatedhq/kots/pkg/upstream/types"
"github.com/replicatedhq/kots/pkg/util"
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
kotsv1beta2 "github.com/replicatedhq/kotskinds/apis/kots/v1beta2"
"gopkg.in/yaml.v2"
"helm.sh/helm/v3/pkg/action"
Expand Down Expand Up @@ -81,6 +82,8 @@ func WriteV1Beta2HelmCharts(opts WriteV1Beta2HelmChartsOptions) error {
return nil
}

checkedImages := []kotsv1beta1.InstallationImage{}

for _, v1Beta2Chart := range opts.KotsKinds.V1Beta2HelmCharts.Items {
helmChart := v1Beta2Chart

Expand All @@ -106,7 +109,7 @@ func WriteV1Beta2HelmCharts(opts WriteV1Beta2HelmChartsOptions) error {
}

archivePath := path.Join(chartDir, fmt.Sprintf("%s-%s.tgz", helmChart.Spec.Chart.Name, helmChart.Spec.Chart.ChartVersion))
if err := ioutil.WriteFile(archivePath, archive, 0644); err != nil {
if err := os.WriteFile(archivePath, archive, 0644); err != nil {
return errors.Wrap(err, "failed to write helm chart archive")
}

Expand Down Expand Up @@ -142,7 +145,7 @@ func WriteV1Beta2HelmCharts(opts WriteV1Beta2HelmChartsOptions) error {
}

valuesPath := path.Join(chartDir, "values.yaml")
if err := ioutil.WriteFile(valuesPath, []byte(valuesContent), 0644); err != nil {
if err := os.WriteFile(valuesPath, []byte(valuesContent), 0644); err != nil {
return errors.Wrap(err, "failed to write values file")
}

Expand All @@ -159,16 +162,13 @@ func WriteV1Beta2HelmCharts(opts WriteV1Beta2HelmChartsOptions) error {
return errors.Wrap(err, "failed to process online images")
}

upstreamDir := opts.Upstream.GetUpstreamDir(opts.WriteUpstreamOptions)

installation, err := kotsutil.LoadInstallationFromPath(filepath.Join(upstreamDir, "userdata", "installation.yaml"))
if err != nil {
return errors.Wrap(err, "failed to load kotskinds from new upstream")
}
checkedImages = append(checkedImages, result.CheckedImages...)
}

installation.Spec.KnownImages = append(installation.Spec.KnownImages, result.CheckedImages...)
if len(checkedImages) > 0 {
opts.KotsKinds.Installation.Spec.KnownImages = append(opts.KotsKinds.Installation.Spec.KnownImages, checkedImages...)

if err := SaveInstallation(installation, upstreamDir); err != nil {
if err := SaveInstallation(&opts.KotsKinds.Installation, opts.Upstream.GetUpstreamDir(opts.WriteUpstreamOptions)); err != nil {
return errors.Wrap(err, "failed to save installation")
}
}
Expand Down
Loading
Loading