Support automatic kubernetes updates for stackit_ske_cluster (#360)
* new field kubernets_version_min and deprecate kubernetes_version * Fix lint and tests * Update acc test * Deprecate datasource field, fix checkAllowPrivilegedContainers * Update acc test, datasource and descriptions * Update acc test * Improve descriptions, fix bug * Improve docs, fix acc test * Update docs * Update docs, fix acc test * Update stackit/internal/services/ske/cluster/resource.go Co-authored-by: Diogo Ferrão <diogo.ferrao@freiheit.com> * Fix links * Default ske auto-update to true --------- Co-authored-by: Diogo Ferrão <diogo.ferrao@freiheit.com>
This commit is contained in:
parent
94fbaf765c
commit
27b008a657
8 changed files with 529 additions and 160 deletions
|
|
@ -121,7 +121,7 @@ func TestMapFields(t *testing.T) {
|
|||
Id: types.StringValue("pid,name"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Name: types.StringValue("name"),
|
||||
KubernetesVersion: types.StringValue("1.2"),
|
||||
KubernetesVersion: types.StringNull(),
|
||||
KubernetesVersionUsed: types.StringValue("1.2.3"),
|
||||
AllowPrivilegedContainers: types.BoolValue(true),
|
||||
|
||||
|
|
@ -397,6 +397,7 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
description string
|
||||
availableVersions []ske.KubernetesVersion
|
||||
providedVersion *string
|
||||
providedVersionMin *string
|
||||
expectedVersionUsed *string
|
||||
expectedHasDeprecatedVersion bool
|
||||
isValid bool
|
||||
|
|
@ -421,13 +422,66 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.20.1"),
|
||||
utils.Ptr("1.20.1"),
|
||||
false,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"available_version_zero_patch",
|
||||
[]ske.KubernetesVersion{
|
||||
{
|
||||
Version: utils.Ptr("1.20.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.20.1"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.20.2"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.19.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.20.0"),
|
||||
utils.Ptr("1.20.0"),
|
||||
false,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"available_version_with_no_provided_patch",
|
||||
[]ske.KubernetesVersion{
|
||||
{
|
||||
Version: utils.Ptr("1.20.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.20.1"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.20.2"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.19.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.20"),
|
||||
utils.Ptr("1.20.2"),
|
||||
false,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"available_version_no_patch",
|
||||
"available_version_no_provided_patch_2",
|
||||
[]ske.KubernetesVersion{
|
||||
{
|
||||
Version: utils.Ptr("1.20.0"),
|
||||
|
|
@ -438,6 +492,7 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.20"),
|
||||
utils.Ptr("1.20.0"),
|
||||
false,
|
||||
|
|
@ -455,6 +510,7 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
State: utils.Ptr(VersionStateDeprecated),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.19"),
|
||||
utils.Ptr("1.19.0"),
|
||||
true,
|
||||
|
|
@ -472,6 +528,7 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
State: utils.Ptr(VersionStateDeprecated),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.20"),
|
||||
utils.Ptr("1.20.0"),
|
||||
false,
|
||||
|
|
@ -489,11 +546,48 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.20"),
|
||||
utils.Ptr("1.20.0"),
|
||||
false,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"deprecated_kubernetes_version_field",
|
||||
[]ske.KubernetesVersion{
|
||||
{
|
||||
Version: utils.Ptr("1.20.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.19.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
utils.Ptr("1.20"),
|
||||
nil,
|
||||
utils.Ptr("1.20.0"),
|
||||
false,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"nil_provided_version_get_latest",
|
||||
[]ske.KubernetesVersion{
|
||||
{
|
||||
Version: utils.Ptr("1.20.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.19.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
nil,
|
||||
utils.Ptr("1.20.0"),
|
||||
false,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"no_matching_available_versions",
|
||||
[]ske.KubernetesVersion{
|
||||
|
|
@ -506,14 +600,60 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.21"),
|
||||
nil,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_matching_available_versions_patch",
|
||||
[]ske.KubernetesVersion{
|
||||
{
|
||||
Version: utils.Ptr("1.21.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.20.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.19.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.21.1"),
|
||||
nil,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_matching_available_versions_patch_2",
|
||||
[]ske.KubernetesVersion{
|
||||
{
|
||||
Version: utils.Ptr("1.21.2"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.20.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.19.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr("1.21.1"),
|
||||
nil,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_available_version",
|
||||
[]ske.KubernetesVersion{},
|
||||
nil,
|
||||
utils.Ptr("1.20"),
|
||||
nil,
|
||||
false,
|
||||
|
|
@ -522,6 +662,7 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
{
|
||||
"nil_available_version",
|
||||
nil,
|
||||
nil,
|
||||
utils.Ptr("1.20"),
|
||||
nil,
|
||||
false,
|
||||
|
|
@ -539,32 +680,16 @@ func TestLatestMatchingVersion(t *testing.T) {
|
|||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
utils.Ptr(""),
|
||||
nil,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"nil_provided_version",
|
||||
[]ske.KubernetesVersion{
|
||||
{
|
||||
Version: utils.Ptr("1.20.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
{
|
||||
Version: utils.Ptr("1.19.0"),
|
||||
State: utils.Ptr(VersionStateSupported),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
nil,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
versionUsed, hasDeprecatedVersion, err := latestMatchingVersion(tt.availableVersions, tt.providedVersion)
|
||||
versionUsed, hasDeprecatedVersion, err := latestMatchingVersion(tt.availableVersions, tt.providedVersion, tt.providedVersionMin)
|
||||
if !tt.isValid && err == nil {
|
||||
t.Fatalf("Should have failed")
|
||||
}
|
||||
|
|
@ -738,13 +863,13 @@ func TestCheckAllowPrivilegedContainers(t *testing.T) {
|
|||
isValid bool
|
||||
}{
|
||||
{
|
||||
description: "null_version_1",
|
||||
description: "null_version_1_flag_deprecated",
|
||||
kubernetesVersion: nil,
|
||||
allowPrivilegeContainers: nil,
|
||||
isValid: false,
|
||||
isValid: true,
|
||||
},
|
||||
{
|
||||
description: "null_version_2",
|
||||
description: "null_version_2_flag_deprecated",
|
||||
kubernetesVersion: nil,
|
||||
allowPrivilegeContainers: utils.Ptr(false),
|
||||
isValid: false,
|
||||
|
|
@ -815,3 +940,72 @@ func TestCheckAllowPrivilegedContainers(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetLatestSupportedVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
listKubernetesVersion []ske.KubernetesVersion
|
||||
isValid bool
|
||||
expectedVersion *string
|
||||
}{
|
||||
{
|
||||
description: "base",
|
||||
listKubernetesVersion: []ske.KubernetesVersion{
|
||||
{
|
||||
State: utils.Ptr("supported"),
|
||||
Version: utils.Ptr("1.2.3"),
|
||||
},
|
||||
{
|
||||
State: utils.Ptr("supported"),
|
||||
Version: utils.Ptr("3.2.1"),
|
||||
},
|
||||
{
|
||||
State: utils.Ptr("not-supported"),
|
||||
Version: utils.Ptr("4.4.4"),
|
||||
},
|
||||
},
|
||||
isValid: true,
|
||||
expectedVersion: utils.Ptr("3.2.1"),
|
||||
},
|
||||
{
|
||||
description: "no Kubernetes versions 1",
|
||||
listKubernetesVersion: nil,
|
||||
isValid: false,
|
||||
},
|
||||
{
|
||||
description: "no Kubernetes versions 2",
|
||||
listKubernetesVersion: []ske.KubernetesVersion{},
|
||||
isValid: false,
|
||||
},
|
||||
{
|
||||
description: "no supported Kubernetes versions",
|
||||
listKubernetesVersion: []ske.KubernetesVersion{
|
||||
{
|
||||
State: utils.Ptr("not-supported"),
|
||||
Version: utils.Ptr("1.2.3"),
|
||||
},
|
||||
},
|
||||
isValid: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
version, err := getLatestSupportedKubernetesVersion(tt.listKubernetesVersion)
|
||||
|
||||
if tt.isValid && err != nil {
|
||||
t.Errorf("failed on valid input")
|
||||
}
|
||||
if !tt.isValid && err == nil {
|
||||
t.Errorf("did not fail on invalid input")
|
||||
}
|
||||
if !tt.isValid {
|
||||
return
|
||||
}
|
||||
diff := cmp.Diff(version, tt.expectedVersion)
|
||||
if diff != "" {
|
||||
t.Fatalf("Output is not as expected: %s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue