2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-08-29 10:49:44 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-05-22 07:31:20 -04:00
|
|
|
"bytes"
|
2022-08-29 10:49:44 -04:00
|
|
|
"context"
|
2023-08-23 04:35:42 -04:00
|
|
|
"io"
|
2022-08-29 10:49:44 -04:00
|
|
|
"testing"
|
|
|
|
|
2023-05-03 05:11:53 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/clusterid"
|
2023-09-08 08:55:07 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/helm"
|
2023-08-21 10:15:32 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/kubecmd"
|
2023-09-25 10:19:43 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/state"
|
2023-08-11 09:18:59 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/terraform"
|
2023-06-09 09:41:02 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
2022-11-15 09:40:49 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
2023-08-11 09:18:59 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/uri"
|
2023-02-09 09:54:12 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
2023-09-19 07:50:00 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/semver"
|
2023-09-08 08:55:07 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/versions"
|
2022-08-29 10:49:44 -04:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-09-08 08:55:07 -04:00
|
|
|
"github.com/stretchr/testify/mock"
|
2022-08-29 10:49:44 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-08-24 10:40:47 -04:00
|
|
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
2022-08-29 10:49:44 -04:00
|
|
|
)
|
|
|
|
|
2023-02-01 04:56:47 -05:00
|
|
|
func TestUpgradeApply(t *testing.T) {
|
2023-10-09 07:04:29 -04:00
|
|
|
defaultState := state.New().
|
|
|
|
SetInfrastructure(state.Infrastructure{
|
|
|
|
APIServerCertSANs: []string{},
|
|
|
|
UID: "uid",
|
|
|
|
Name: "kubernetes-uid", // default test cfg uses "kubernetes" prefix
|
|
|
|
InitSecret: []byte{0x42},
|
|
|
|
}).
|
|
|
|
SetClusterValues(state.ClusterValues{MeasurementSalt: []byte{0x41}})
|
|
|
|
defaultIDFile := clusterid.File{
|
|
|
|
MeasurementSalt: []byte{0x41},
|
|
|
|
UID: "uid",
|
|
|
|
InitSecret: []byte{0x42},
|
|
|
|
}
|
|
|
|
fsWithIDFile := func() file.Handler {
|
|
|
|
fh := file.NewHandler(afero.NewMemMapFs())
|
|
|
|
require.NoError(t, fh.WriteJSON(constants.ClusterIDsFilename, defaultIDFile))
|
|
|
|
return fh
|
|
|
|
}
|
|
|
|
fsWithStateFile := func() file.Handler {
|
|
|
|
fh := file.NewHandler(afero.NewMemMapFs())
|
|
|
|
require.NoError(t, fh.WriteYAML(constants.StateFilename, defaultState))
|
|
|
|
return fh
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:49:44 -04:00
|
|
|
testCases := map[string]struct {
|
2023-10-09 07:04:29 -04:00
|
|
|
helmUpgrader helmApplier
|
|
|
|
kubeUpgrader *stubKubernetesUpgrader
|
|
|
|
fh func() file.Handler
|
|
|
|
fhAssertions func(require *require.Assertions, assert *assert.Assertions, fh file.Handler)
|
|
|
|
terraformUpgrader clusterUpgrader
|
|
|
|
infrastructureShower *stubShowInfrastructure
|
|
|
|
wantErr bool
|
|
|
|
customK8sVersion string
|
|
|
|
flags upgradeApplyFlags
|
|
|
|
stdin string
|
2022-08-29 10:49:44 -04:00
|
|
|
}{
|
|
|
|
"success": {
|
2023-10-09 07:04:29 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{currentConfig: config.DefaultForAzureSEVSNP()},
|
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
|
|
|
fhAssertions: func(require *require.Assertions, assert *assert.Assertions, fh file.Handler) {
|
|
|
|
gotState, err := state.ReadFromFile(fh, constants.StateFilename)
|
|
|
|
require.NoError(err)
|
|
|
|
assert.Equal("v1", gotState.Version)
|
|
|
|
assert.Equal(defaultState, gotState)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"fall back to id file": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{currentConfig: config.DefaultForAzureSEVSNP()},
|
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithIDFile,
|
|
|
|
fhAssertions: func(require *require.Assertions, assert *assert.Assertions, fh file.Handler) {
|
|
|
|
gotState, err := state.ReadFromFile(fh, constants.StateFilename)
|
|
|
|
require.NoError(err)
|
|
|
|
assert.Equal("v1", gotState.Version)
|
|
|
|
assert.Equal(defaultState, gotState)
|
|
|
|
var oldIDFile clusterid.File
|
|
|
|
err = fh.ReadJSON(constants.ClusterIDsFilename+".old", &oldIDFile)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(defaultIDFile, oldIDFile)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"id file and state file do not exist": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{currentConfig: config.DefaultForAzureSEVSNP()},
|
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: func() file.Handler {
|
|
|
|
return file.NewHandler(afero.NewMemMapFs())
|
|
|
|
},
|
|
|
|
wantErr: true,
|
2022-11-29 05:39:07 -05:00
|
|
|
},
|
2023-03-03 03:38:23 -05:00
|
|
|
"nodeVersion some error": {
|
2023-08-16 03:59:32 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
2023-05-03 05:11:53 -04:00
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
2023-08-16 03:59:32 -04:00
|
|
|
nodeVersionErr: assert.AnError,
|
2023-05-03 05:11:53 -04:00
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
wantErr: true,
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-03-03 03:38:23 -05:00
|
|
|
},
|
|
|
|
"nodeVersion in progress error": {
|
2023-08-16 03:59:32 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
2023-05-03 05:11:53 -04:00
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
2023-08-21 10:15:32 -04:00
|
|
|
nodeVersionErr: kubecmd.ErrInProgress,
|
2023-05-03 05:11:53 -04:00
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2022-08-29 10:49:44 -04:00
|
|
|
},
|
2023-03-03 03:38:23 -05:00
|
|
|
"helm other error": {
|
2023-08-16 03:59:32 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
2023-05-03 05:11:53 -04:00
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
helmUpgrader: stubApplier{err: assert.AnError},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
wantErr: true,
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-05-22 07:31:20 -04:00
|
|
|
},
|
|
|
|
"abort": {
|
2023-08-16 03:59:32 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
2023-05-22 07:31:20 -04:00
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{terraformDiff: true},
|
|
|
|
wantErr: true,
|
|
|
|
stdin: "no\n",
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-05-22 07:31:20 -04:00
|
|
|
},
|
2023-09-14 05:51:20 -04:00
|
|
|
"abort, restore terraform err": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{terraformDiff: true, rollbackWorkspaceErr: assert.AnError},
|
|
|
|
wantErr: true,
|
|
|
|
stdin: "no\n",
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-09-14 05:51:20 -04:00
|
|
|
},
|
2023-05-22 07:31:20 -04:00
|
|
|
"plan terraform error": {
|
2023-08-16 03:59:32 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
2023-05-22 07:31:20 -04:00
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{planTerraformErr: assert.AnError},
|
|
|
|
wantErr: true,
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-05-22 07:31:20 -04:00
|
|
|
},
|
|
|
|
"apply terraform error": {
|
2023-08-16 03:59:32 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
2023-08-24 10:40:47 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
2023-08-16 03:59:32 -04:00
|
|
|
terraformUpgrader: &stubTerraformUpgrader{
|
|
|
|
applyTerraformErr: assert.AnError,
|
2023-05-22 07:31:20 -04:00
|
|
|
terraformDiff: true,
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
wantErr: true,
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-08-11 09:18:59 -04:00
|
|
|
},
|
2023-09-19 07:50:00 -04:00
|
|
|
"outdated K8s patch version": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
customK8sVersion: func() string {
|
|
|
|
v, err := semver.New(versions.SupportedK8sVersions()[0])
|
|
|
|
require.NoError(t, err)
|
|
|
|
return semver.NewFromInt(v.Major(), v.Minor(), v.Patch()-1, "").String()
|
|
|
|
}(),
|
2023-10-09 07:04:29 -04:00
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-09-19 07:50:00 -04:00
|
|
|
},
|
|
|
|
"outdated K8s version": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
customK8sVersion: "v1.20.0",
|
|
|
|
flags: upgradeApplyFlags{yes: true},
|
|
|
|
wantErr: true,
|
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-09-19 07:50:00 -04:00
|
|
|
},
|
2023-09-08 08:55:07 -04:00
|
|
|
"skip all upgrade phases": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
|
|
|
helmUpgrader: &mockApplier{}, // mocks ensure that no methods are called
|
|
|
|
terraformUpgrader: &mockTerraformUpgrader{},
|
|
|
|
flags: upgradeApplyFlags{
|
|
|
|
skipPhases: []skipPhase{skipInfrastructurePhase, skipHelmPhase, skipK8sPhase, skipImagePhase},
|
|
|
|
yes: true,
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
|
|
|
},
|
|
|
|
"show state err": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
|
|
|
helmUpgrader: &stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
flags: upgradeApplyFlags{
|
|
|
|
skipPhases: []skipPhase{skipInfrastructurePhase},
|
|
|
|
yes: true,
|
|
|
|
},
|
|
|
|
infrastructureShower: &stubShowInfrastructure{
|
|
|
|
showInfraErr: assert.AnError,
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
fh: fsWithStateFile,
|
2023-09-08 08:55:07 -04:00
|
|
|
},
|
|
|
|
"skip all phases except node upgrade": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
|
|
|
helmUpgrader: &mockApplier{}, // mocks ensure that no methods are called
|
|
|
|
terraformUpgrader: &mockTerraformUpgrader{},
|
|
|
|
flags: upgradeApplyFlags{
|
|
|
|
skipPhases: []skipPhase{skipInfrastructurePhase, skipHelmPhase, skipK8sPhase},
|
|
|
|
yes: true,
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
infrastructureShower: &stubShowInfrastructure{},
|
|
|
|
fh: fsWithStateFile,
|
2023-09-08 08:55:07 -04:00
|
|
|
},
|
2022-08-29 10:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
2023-02-01 04:56:47 -05:00
|
|
|
cmd := newUpgradeApplyCmd()
|
2023-05-22 07:31:20 -04:00
|
|
|
cmd.SetIn(bytes.NewBufferString(tc.stdin))
|
2023-03-14 13:34:58 -04:00
|
|
|
|
2023-08-11 09:18:59 -04:00
|
|
|
cfg := defaultConfigWithExpectedMeasurements(t, config.Default(), cloudprovider.Azure)
|
2023-09-19 07:50:00 -04:00
|
|
|
if tc.customK8sVersion != "" {
|
|
|
|
cfg.KubernetesVersion = versions.ValidK8sVersion(tc.customK8sVersion)
|
|
|
|
}
|
2023-10-09 07:04:29 -04:00
|
|
|
fh := tc.fh()
|
|
|
|
require.NoError(fh.WriteYAML(constants.ConfigFilename, cfg))
|
|
|
|
require.NoError(fh.WriteJSON(constants.MasterSecretFilename, uri.MasterSecret{}))
|
2022-08-29 10:49:44 -04:00
|
|
|
|
2023-08-16 03:59:32 -04:00
|
|
|
upgrader := upgradeApplyCmd{
|
2023-08-23 04:35:42 -04:00
|
|
|
kubeUpgrader: tc.kubeUpgrader,
|
2023-08-24 10:40:47 -04:00
|
|
|
helmApplier: tc.helmUpgrader,
|
2023-08-23 04:35:42 -04:00
|
|
|
clusterUpgrader: tc.terraformUpgrader,
|
|
|
|
log: logger.NewTest(t),
|
|
|
|
configFetcher: stubAttestationFetcher{},
|
2023-10-09 07:04:29 -04:00
|
|
|
clusterShower: tc.infrastructureShower,
|
|
|
|
fileHandler: fh,
|
2023-08-16 03:59:32 -04:00
|
|
|
}
|
2023-07-24 04:30:53 -04:00
|
|
|
|
2023-08-23 04:35:42 -04:00
|
|
|
err := upgrader.upgradeApply(cmd, "test", tc.flags)
|
2022-08-29 10:49:44 -04:00
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
2023-08-11 09:18:59 -04:00
|
|
|
return
|
2022-08-29 10:49:44 -04:00
|
|
|
}
|
2023-08-11 09:18:59 -04:00
|
|
|
assert.NoError(err)
|
2023-09-08 08:55:07 -04:00
|
|
|
assert.Equal(!tc.flags.skipPhases.contains(skipImagePhase), tc.kubeUpgrader.calledNodeUpgrade,
|
|
|
|
"incorrect node upgrade skipping behavior")
|
2023-09-25 10:19:43 -04:00
|
|
|
|
2023-10-09 07:04:29 -04:00
|
|
|
if tc.fhAssertions != nil {
|
|
|
|
tc.fhAssertions(require, assert, fh)
|
2023-09-25 10:19:43 -04:00
|
|
|
}
|
2022-08-29 10:49:44 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
func TestUpgradeApplyFlagsForSkipPhases(t *testing.T) {
|
|
|
|
cmd := newUpgradeApplyCmd()
|
|
|
|
cmd.Flags().String("workspace", "", "") // register persistent flag manually
|
|
|
|
cmd.Flags().Bool("force", true, "") // register persistent flag manually
|
|
|
|
cmd.Flags().String("tf-log", "NONE", "") // register persistent flag manually
|
|
|
|
require.NoError(t, cmd.Flags().Set("skip-phases", "infrastructure,helm,k8s,image"))
|
|
|
|
result, err := parseUpgradeApplyFlags(cmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error while parsing flags: %v", err)
|
|
|
|
}
|
|
|
|
assert.ElementsMatch(t, []skipPhase{skipInfrastructurePhase, skipHelmPhase, skipK8sPhase, skipImagePhase}, result.skipPhases)
|
|
|
|
}
|
|
|
|
|
2023-08-24 10:40:47 -04:00
|
|
|
type stubKubernetesUpgrader struct {
|
2023-09-08 08:55:07 -04:00
|
|
|
nodeVersionErr error
|
|
|
|
currentConfig config.AttestationCfg
|
|
|
|
calledNodeUpgrade bool
|
2023-08-11 09:18:59 -04:00
|
|
|
}
|
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
func (u *stubKubernetesUpgrader) BackupCRDs(_ context.Context, _ string) ([]apiextensionsv1.CustomResourceDefinition, error) {
|
2023-08-24 10:40:47 -04:00
|
|
|
return []apiextensionsv1.CustomResourceDefinition{}, nil
|
2022-08-29 10:49:44 -04:00
|
|
|
}
|
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
func (u *stubKubernetesUpgrader) BackupCRs(_ context.Context, _ []apiextensionsv1.CustomResourceDefinition, _ string) error {
|
2023-08-24 10:40:47 -04:00
|
|
|
return nil
|
2023-08-11 09:18:59 -04:00
|
|
|
}
|
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
func (u *stubKubernetesUpgrader) UpgradeNodeVersion(_ context.Context, _ *config.Config, _, _, _ bool) error {
|
|
|
|
u.calledNodeUpgrade = true
|
2023-03-03 03:38:23 -05:00
|
|
|
return u.nodeVersionErr
|
2022-08-29 10:49:44 -04:00
|
|
|
}
|
2022-11-29 05:39:07 -05:00
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
func (u *stubKubernetesUpgrader) ApplyJoinConfig(_ context.Context, _ config.AttestationCfg, _ []byte) error {
|
2023-08-16 03:59:32 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
func (u *stubKubernetesUpgrader) GetClusterAttestationConfig(_ context.Context, _ variant.Variant) (config.AttestationCfg, error) {
|
2023-08-16 03:59:32 -04:00
|
|
|
return u.currentConfig, nil
|
2022-12-19 10:52:15 -05:00
|
|
|
}
|
2023-03-14 13:34:58 -04:00
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
func (u *stubKubernetesUpgrader) ExtendClusterConfigCertSANs(_ context.Context, _ []string) error {
|
2023-03-14 13:34:58 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-08 15:15:02 -04:00
|
|
|
// TODO(v2.11): Remove this function after v2.11 is released.
|
2023-09-08 08:55:07 -04:00
|
|
|
func (u *stubKubernetesUpgrader) RemoveAttestationConfigHelmManagement(_ context.Context) error {
|
2023-08-23 02:14:39 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(v2.12): Remove this function.
|
2023-09-08 08:55:07 -04:00
|
|
|
func (u *stubKubernetesUpgrader) RemoveHelmKeepAnnotation(_ context.Context) error {
|
2023-08-23 02:14:39 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-16 03:59:32 -04:00
|
|
|
type stubTerraformUpgrader struct {
|
2023-09-14 05:51:20 -04:00
|
|
|
terraformDiff bool
|
|
|
|
planTerraformErr error
|
|
|
|
applyTerraformErr error
|
|
|
|
rollbackWorkspaceErr error
|
2023-03-14 13:34:58 -04:00
|
|
|
}
|
2023-05-22 07:31:20 -04:00
|
|
|
|
2023-08-23 04:35:42 -04:00
|
|
|
func (u stubTerraformUpgrader) PlanClusterUpgrade(_ context.Context, _ io.Writer, _ terraform.Variables, _ cloudprovider.Provider) (bool, error) {
|
2023-05-22 07:31:20 -04:00
|
|
|
return u.terraformDiff, u.planTerraformErr
|
|
|
|
}
|
|
|
|
|
2023-09-25 11:10:23 -04:00
|
|
|
func (u stubTerraformUpgrader) ApplyClusterUpgrade(_ context.Context, _ cloudprovider.Provider) (state.Infrastructure, error) {
|
|
|
|
return state.Infrastructure{}, u.applyTerraformErr
|
2023-05-22 07:31:20 -04:00
|
|
|
}
|
2023-09-08 08:55:07 -04:00
|
|
|
|
2023-09-14 05:51:20 -04:00
|
|
|
func (u stubTerraformUpgrader) RestoreClusterWorkspace() error {
|
|
|
|
return u.rollbackWorkspaceErr
|
|
|
|
}
|
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
type mockTerraformUpgrader struct {
|
|
|
|
mock.Mock
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTerraformUpgrader) PlanClusterUpgrade(ctx context.Context, w io.Writer, variables terraform.Variables, provider cloudprovider.Provider) (bool, error) {
|
|
|
|
args := m.Called(ctx, w, variables, provider)
|
|
|
|
return args.Bool(0), args.Error(1)
|
|
|
|
}
|
|
|
|
|
2023-09-25 11:10:23 -04:00
|
|
|
func (m *mockTerraformUpgrader) ApplyClusterUpgrade(ctx context.Context, provider cloudprovider.Provider) (state.Infrastructure, error) {
|
2023-09-08 08:55:07 -04:00
|
|
|
args := m.Called(ctx, provider)
|
2023-09-25 11:10:23 -04:00
|
|
|
return args.Get(0).(state.Infrastructure), args.Error(1)
|
2023-09-08 08:55:07 -04:00
|
|
|
}
|
|
|
|
|
2023-09-14 05:51:20 -04:00
|
|
|
func (m *mockTerraformUpgrader) RestoreClusterWorkspace() error {
|
|
|
|
args := m.Called()
|
|
|
|
return args.Error(0)
|
|
|
|
}
|
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
type mockApplier struct {
|
|
|
|
mock.Mock
|
|
|
|
}
|
|
|
|
|
2023-10-09 07:04:29 -04:00
|
|
|
func (m *mockApplier) PrepareApply(cfg *config.Config, stateFile *state.State,
|
|
|
|
helmOpts helm.Options, str string, masterSecret uri.MasterSecret,
|
2023-09-25 10:19:43 -04:00
|
|
|
) (helm.Applier, bool, error) {
|
2023-10-09 07:04:29 -04:00
|
|
|
args := m.Called(cfg, stateFile, helmOpts, str, masterSecret)
|
2023-09-08 08:55:07 -04:00
|
|
|
return args.Get(0).(helm.Applier), args.Bool(1), args.Error(2)
|
|
|
|
}
|
2023-10-09 07:04:29 -04:00
|
|
|
|
|
|
|
type stubShowInfrastructure struct {
|
|
|
|
showInfraErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubShowInfrastructure) ShowInfrastructure(context.Context, cloudprovider.Provider) (state.Infrastructure, error) {
|
|
|
|
return state.Infrastructure{}, s.showInfraErr
|
|
|
|
}
|