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-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}})
|
2023-10-24 09:39:18 -04:00
|
|
|
fsWithStateFileAndTfState := func() file.Handler {
|
2023-10-09 07:04:29 -04:00
|
|
|
fh := file.NewHandler(afero.NewMemMapFs())
|
2023-10-24 09:39:18 -04:00
|
|
|
require.NoError(t, fh.MkdirAll(constants.TerraformWorkingDir))
|
2023-10-09 07:04:29 -04:00
|
|
|
require.NoError(t, fh.WriteYAML(constants.StateFilename, defaultState))
|
|
|
|
return fh
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:49:44 -04:00
|
|
|
testCases := map[string]struct {
|
2023-10-13 04:21:21 -04:00
|
|
|
helmUpgrader helmApplier
|
|
|
|
kubeUpgrader *stubKubernetesUpgrader
|
|
|
|
fh func() file.Handler
|
|
|
|
fhAssertions func(require *require.Assertions, assert *assert.Assertions, fh file.Handler)
|
|
|
|
terraformUpgrader clusterUpgrader
|
|
|
|
wantErr bool
|
|
|
|
customK8sVersion string
|
2023-10-24 09:39:18 -04:00
|
|
|
flags applyFlags
|
2023-10-13 04:21:21 -04:00
|
|
|
stdin string
|
2022-08-29 10:49:44 -04:00
|
|
|
}{
|
|
|
|
"success": {
|
2023-10-13 04:21:21 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{currentConfig: config.DefaultForAzureSEVSNP()},
|
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
|
|
|
fh: fsWithStateFileAndTfState,
|
2023-10-09 07:04:29 -04:00
|
|
|
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)
|
|
|
|
},
|
|
|
|
},
|
2023-10-24 09:39:18 -04:00
|
|
|
"id file and state file do not exist": {
|
2023-10-13 04:21:21 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{currentConfig: config.DefaultForAzureSEVSNP()},
|
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
2023-10-09 07:04:29 -04:00
|
|
|
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-13 04:21:21 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
wantErr: true,
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
|
|
|
fh: fsWithStateFileAndTfState,
|
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-13 04:21:21 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
|
|
|
fh: fsWithStateFileAndTfState,
|
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-13 04:21:21 -04:00
|
|
|
helmUpgrader: stubApplier{err: assert.AnError},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
wantErr: true,
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
|
|
|
fh: fsWithStateFileAndTfState,
|
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-13 04:21:21 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{terraformDiff: true},
|
|
|
|
wantErr: true,
|
|
|
|
stdin: "no\n",
|
2023-10-24 09:39:18 -04:00
|
|
|
fh: fsWithStateFileAndTfState,
|
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-13 04:21:21 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{terraformDiff: true, rollbackWorkspaceErr: assert.AnError},
|
|
|
|
wantErr: true,
|
|
|
|
stdin: "no\n",
|
2023-10-24 09:39:18 -04:00
|
|
|
fh: fsWithStateFileAndTfState,
|
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-13 04:21:21 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{planTerraformErr: assert.AnError},
|
|
|
|
wantErr: true,
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
|
|
|
fh: fsWithStateFileAndTfState,
|
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-13 04:21:21 -04:00
|
|
|
wantErr: true,
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
|
|
|
fh: fsWithStateFileAndTfState,
|
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-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
|
|
|
fh: fsWithStateFileAndTfState,
|
2023-09-19 07:50:00 -04:00
|
|
|
},
|
|
|
|
"outdated K8s version": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
2023-10-13 04:21:21 -04:00
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
customK8sVersion: "v1.20.0",
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{yes: true},
|
2023-10-13 04:21:21 -04:00
|
|
|
wantErr: true,
|
2023-10-24 09:39:18 -04:00
|
|
|
fh: fsWithStateFileAndTfState,
|
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{},
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{
|
|
|
|
skipPhases: skipPhases{
|
|
|
|
skipInfrastructurePhase: struct{}{}, skipHelmPhase: struct{}{},
|
|
|
|
skipK8sPhase: struct{}{}, skipImagePhase: struct{}{},
|
|
|
|
},
|
|
|
|
yes: true,
|
2023-09-08 08:55:07 -04:00
|
|
|
},
|
2023-10-24 09:39:18 -04:00
|
|
|
fh: fsWithStateFileAndTfState,
|
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{},
|
2023-10-24 09:39:18 -04:00
|
|
|
flags: applyFlags{
|
|
|
|
skipPhases: skipPhases{
|
|
|
|
skipInfrastructurePhase: struct{}{}, skipHelmPhase: struct{}{},
|
|
|
|
skipK8sPhase: struct{}{},
|
|
|
|
},
|
|
|
|
yes: true,
|
2023-09-08 08:55:07 -04:00
|
|
|
},
|
2023-10-24 09:39:18 -04:00
|
|
|
fh: fsWithStateFileAndTfState,
|
|
|
|
},
|
|
|
|
"no tf state, skip infrastructure upgrade": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
|
|
|
helmUpgrader: &stubApplier{},
|
|
|
|
terraformUpgrader: &mockTerraformUpgrader{},
|
|
|
|
flags: applyFlags{
|
|
|
|
yes: true,
|
|
|
|
},
|
|
|
|
fh: func() file.Handler {
|
|
|
|
fh := file.NewHandler(afero.NewMemMapFs())
|
|
|
|
require.NoError(t, fh.WriteYAML(constants.StateFilename, defaultState))
|
|
|
|
return fh
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"attempt to change attestation variant": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{currentConfig: &config.AzureTrustedLaunch{}},
|
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
|
|
|
flags: applyFlags{yes: true},
|
|
|
|
fh: fsWithStateFileAndTfState,
|
|
|
|
wantErr: true,
|
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()
|
2023-10-24 09:39:18 -04:00
|
|
|
require.NoError(fh.Write(constants.AdminConfFilename, []byte{}))
|
2023-10-09 07:04:29 -04:00
|
|
|
require.NoError(fh.WriteYAML(constants.ConfigFilename, cfg))
|
|
|
|
require.NoError(fh.WriteJSON(constants.MasterSecretFilename, uri.MasterSecret{}))
|
2022-08-29 10:49:44 -04:00
|
|
|
|
2023-10-24 09:39:18 -04:00
|
|
|
upgrader := &applyCmd{
|
|
|
|
fileHandler: fh,
|
|
|
|
flags: tc.flags,
|
|
|
|
log: logger.NewTest(t),
|
|
|
|
spinner: &nopSpinner{},
|
|
|
|
merger: &stubMerger{},
|
|
|
|
quotaChecker: &stubLicenseClient{},
|
|
|
|
newHelmClient: func(string, debugLog) (helmApplier, error) {
|
|
|
|
return tc.helmUpgrader, nil
|
|
|
|
},
|
|
|
|
newKubeUpgrader: func(_ io.Writer, _ string, _ debugLog) (kubernetesUpgrader, error) {
|
|
|
|
return tc.kubeUpgrader, nil
|
|
|
|
},
|
2023-08-23 04:35:42 -04:00
|
|
|
clusterUpgrader: tc.terraformUpgrader,
|
2023-08-16 03:59:32 -04:00
|
|
|
}
|
2023-10-24 09:39:18 -04:00
|
|
|
err := upgrader.apply(cmd, stubAttestationFetcher{}, "test")
|
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) {
|
2023-10-16 09:05:29 -04:00
|
|
|
require := require.New(t)
|
2023-09-08 08:55:07 -04:00
|
|
|
cmd := newUpgradeApplyCmd()
|
2023-10-16 09:05:29 -04:00
|
|
|
// register persistent flags manually
|
|
|
|
cmd.Flags().String("workspace", "", "")
|
|
|
|
cmd.Flags().Bool("force", true, "")
|
|
|
|
cmd.Flags().String("tf-log", "NONE", "")
|
|
|
|
cmd.Flags().Bool("debug", false, "")
|
2023-10-24 09:39:18 -04:00
|
|
|
cmd.Flags().Bool("merge-kubeconfig", false, "")
|
2023-10-16 09:05:29 -04:00
|
|
|
|
|
|
|
require.NoError(cmd.Flags().Set("skip-phases", "infrastructure,helm,k8s,image"))
|
2023-10-24 09:39:18 -04:00
|
|
|
wantPhases := skipPhases{}
|
|
|
|
wantPhases.add(skipInfrastructurePhase, skipHelmPhase, skipK8sPhase, skipImagePhase)
|
2023-10-16 09:05:29 -04:00
|
|
|
|
2023-10-24 09:39:18 -04:00
|
|
|
var flags applyFlags
|
2023-10-16 09:05:29 -04:00
|
|
|
err := flags.parse(cmd.Flags())
|
|
|
|
require.NoError(err)
|
2023-10-24 09:39:18 -04:00
|
|
|
assert.Equal(t, wantPhases, flags.skipPhases)
|
2023-09-08 08:55:07 -04:00
|
|
|
}
|
|
|
|
|
2023-08-24 10:40:47 -04:00
|
|
|
type stubKubernetesUpgrader struct {
|
2023-10-24 09:39:18 -04:00
|
|
|
nodeVersionErr error
|
|
|
|
currentConfig config.AttestationCfg
|
|
|
|
getClusterAttestationConfigErr error
|
|
|
|
calledNodeUpgrade bool
|
|
|
|
backupCRDsErr error
|
|
|
|
backupCRDsCalled bool
|
|
|
|
backupCRsErr error
|
|
|
|
backupCRsCalled 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-10-24 09:39:18 -04:00
|
|
|
u.backupCRDsCalled = true
|
|
|
|
return []apiextensionsv1.CustomResourceDefinition{}, u.backupCRDsErr
|
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-10-24 09:39:18 -04:00
|
|
|
u.backupCRsCalled = true
|
|
|
|
return u.backupCRsErr
|
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-10-24 09:39:18 -04:00
|
|
|
return u.currentConfig, u.getClusterAttestationConfigErr
|
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)
|
|
|
|
}
|