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-10-31 07:46:40 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd"
|
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-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-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-11-20 05:17:16 -05:00
|
|
|
require.NoError(t, fh.WriteYAML(constants.StateFilename, defaultStateFile(cloudprovider.Azure)))
|
2023-10-09 07:04:29 -04:00
|
|
|
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)
|
2023-10-31 07:46:40 -04:00
|
|
|
terraformUpgrader cloudApplier
|
2023-10-13 04:21:21 -04:00
|
|
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
2023-10-24 09:39:18 -04:00
|
|
|
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)
|
2023-11-20 05:17:16 -05:00
|
|
|
assert.Equal(defaultStateFile(cloudprovider.Azure), gotState)
|
2023-10-09 07:04:29 -04:00
|
|
|
},
|
|
|
|
},
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
2023-10-24 09:39:18 -04:00
|
|
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
2023-10-24 09:39:18 -04:00
|
|
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
2023-10-24 09:39:18 -04:00
|
|
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
2023-10-24 09:39:18 -04:00
|
|
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
2023-10-24 09:39:18 -04:00
|
|
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
2023-10-24 09:39:18 -04:00
|
|
|
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-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
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{
|
2023-11-20 05:17:16 -05:00
|
|
|
skipPhases: newPhases(skipInfrastructurePhase, skipAttestationConfigPhase, skipCertSANsPhase, skipHelmPhase, skipK8sPhase, skipImagePhase),
|
|
|
|
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{
|
2023-11-20 05:17:16 -05:00
|
|
|
skipPhases: newPhases(skipInfrastructurePhase, skipAttestationConfigPhase, skipCertSANsPhase, skipHelmPhase, skipK8sPhase),
|
|
|
|
yes: true,
|
2023-09-08 08:55:07 -04:00
|
|
|
},
|
2023-10-24 09:39:18 -04:00
|
|
|
fh: fsWithStateFileAndTfState,
|
|
|
|
},
|
2023-11-20 05:17:16 -05:00
|
|
|
"no tf state, infra phase skipped": {
|
2023-10-24 09:39:18 -04:00
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{
|
|
|
|
currentConfig: config.DefaultForAzureSEVSNP(),
|
|
|
|
},
|
|
|
|
helmUpgrader: &stubApplier{},
|
|
|
|
terraformUpgrader: &mockTerraformUpgrader{},
|
|
|
|
flags: applyFlags{
|
2023-11-20 05:17:16 -05:00
|
|
|
yes: true,
|
|
|
|
skipPhases: newPhases(skipInfrastructurePhase),
|
2023-10-24 09:39:18 -04:00
|
|
|
},
|
|
|
|
fh: func() file.Handler {
|
|
|
|
fh := file.NewHandler(afero.NewMemMapFs())
|
2023-11-20 05:17:16 -05:00
|
|
|
require.NoError(t, fh.WriteYAML(constants.StateFilename, defaultStateFile(cloudprovider.Azure)))
|
2023-10-24 09:39:18 -04:00
|
|
|
return fh
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"attempt to change attestation variant": {
|
|
|
|
kubeUpgrader: &stubKubernetesUpgrader{currentConfig: &config.AzureTrustedLaunch{}},
|
|
|
|
helmUpgrader: stubApplier{},
|
|
|
|
terraformUpgrader: &stubTerraformUpgrader{},
|
2023-11-03 10:47:03 -04:00
|
|
|
flags: applyFlags{yes: true, skipPhases: skipPhases{skipInitPhase: struct{}{}}},
|
2023-10-24 09:39:18 -04:00
|
|
|
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{
|
2023-11-20 05:17:16 -05:00
|
|
|
fileHandler: fh,
|
|
|
|
flags: tc.flags,
|
|
|
|
log: logger.NewTest(t),
|
|
|
|
spinner: &nopSpinner{},
|
|
|
|
merger: &stubMerger{},
|
2023-10-24 09:39:18 -04:00
|
|
|
newHelmClient: func(string, debugLog) (helmApplier, error) {
|
|
|
|
return tc.helmUpgrader, nil
|
|
|
|
},
|
|
|
|
newKubeUpgrader: func(_ io.Writer, _ string, _ debugLog) (kubernetesUpgrader, error) {
|
|
|
|
return tc.kubeUpgrader, nil
|
|
|
|
},
|
2023-10-31 07:46:40 -04:00
|
|
|
newInfraApplier: func(ctx context.Context) (cloudApplier, func(), error) {
|
|
|
|
return tc.terraformUpgrader, func() {}, nil
|
|
|
|
},
|
2023-08-16 03:59:32 -04:00
|
|
|
}
|
2023-11-20 05:17:16 -05:00
|
|
|
err := upgrader.apply(cmd, stubAttestationFetcher{}, &stubLicenseClient{}, "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-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-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-10-31 07:46:40 -04:00
|
|
|
func (u stubTerraformUpgrader) Plan(_ context.Context, _ *config.Config) (bool, error) {
|
2023-05-22 07:31:20 -04:00
|
|
|
return u.terraformDiff, u.planTerraformErr
|
|
|
|
}
|
|
|
|
|
2023-10-31 07:46:40 -04:00
|
|
|
func (u stubTerraformUpgrader) Apply(_ context.Context, _ cloudprovider.Provider, _ cloudcmd.RollbackBehavior) (state.Infrastructure, error) {
|
2023-09-25 11:10:23 -04:00
|
|
|
return state.Infrastructure{}, u.applyTerraformErr
|
2023-05-22 07:31:20 -04:00
|
|
|
}
|
2023-09-08 08:55:07 -04:00
|
|
|
|
2023-10-31 07:46:40 -04:00
|
|
|
func (u stubTerraformUpgrader) RestoreWorkspace() error {
|
2023-09-14 05:51:20 -04:00
|
|
|
return u.rollbackWorkspaceErr
|
|
|
|
}
|
|
|
|
|
2023-11-20 05:17:16 -05:00
|
|
|
func (u stubTerraformUpgrader) WorkingDirIsEmpty() (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2023-09-08 08:55:07 -04:00
|
|
|
type mockTerraformUpgrader struct {
|
|
|
|
mock.Mock
|
|
|
|
}
|
|
|
|
|
2023-10-31 07:46:40 -04:00
|
|
|
func (m *mockTerraformUpgrader) Plan(ctx context.Context, conf *config.Config) (bool, error) {
|
|
|
|
args := m.Called(ctx, conf)
|
2023-09-08 08:55:07 -04:00
|
|
|
return args.Bool(0), args.Error(1)
|
|
|
|
}
|
|
|
|
|
2023-10-31 07:46:40 -04:00
|
|
|
func (m *mockTerraformUpgrader) Apply(ctx context.Context, provider cloudprovider.Provider, rollback cloudcmd.RollbackBehavior) (state.Infrastructure, error) {
|
|
|
|
args := m.Called(ctx, provider, rollback)
|
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-10-31 07:46:40 -04:00
|
|
|
func (m *mockTerraformUpgrader) RestoreWorkspace() error {
|
2023-09-14 05:51:20 -04:00
|
|
|
args := m.Called()
|
|
|
|
return args.Error(0)
|
|
|
|
}
|
|
|
|
|
2023-11-20 05:17:16 -05:00
|
|
|
func (m *mockTerraformUpgrader) WorkingDirIsEmpty() (bool, error) {
|
|
|
|
args := m.Called()
|
|
|
|
return args.Bool(0), args.Error(1)
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|