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:
Vicente Pinto 2024-05-14 14:55:33 +01:00 committed by GitHub
parent 94fbaf765c
commit 27b008a657
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 529 additions and 160 deletions

View file

@ -16,6 +16,11 @@ import (
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
)
const (
MajorMinorVersionRegex = `^\d+\.\d+?$`
FullVersionRegex = `^\d+\.\d+.\d+?$`
)
type Validator struct {
description string
markdownDescription string
@ -137,7 +142,7 @@ func MinorVersionNumber() *Validator {
return &Validator{
description: description,
validate: func(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
exp := `^\d+\.\d+?$`
exp := MajorMinorVersionRegex
r := regexp.MustCompile(exp)
version := req.ConfigValue.ValueString()
if !r.MatchString(version) {
@ -151,6 +156,30 @@ func MinorVersionNumber() *Validator {
}
}
func VersionNumber() *Validator {
description := "value must be a version number, without a leading 'v': '[MAJOR].[MINOR]' or '[MAJOR].[MINOR].[PATCH]'"
return &Validator{
description: description,
validate: func(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
minorVersionExp := MajorMinorVersionRegex
minorVersionRegex := regexp.MustCompile(minorVersionExp)
versionExp := FullVersionRegex
versionRegex := regexp.MustCompile(versionExp)
version := req.ConfigValue.ValueString()
if !minorVersionRegex.MatchString(version) && !versionRegex.MatchString(version) {
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
req.Path,
description,
req.ConfigValue.ValueString(),
))
}
},
}
}
func RFC3339SecondsOnly() *Validator {
description := "value must be in RFC339 format (seconds only)"

View file

@ -363,6 +363,80 @@ func TestMinorVersionNumber(t *testing.T) {
}
}
func TestVersionNumber(t *testing.T) {
tests := []struct {
description string
input string
isValid bool
}{
{
"ok",
"1.20",
true,
},
{
"ok-2",
"1.3",
true,
},
{
"ok-3",
"10.1",
true,
},
{
"ok-patch-version",
"1.20.1",
true,
},
{
"ok-patch-version-2",
"1.20.10",
true,
},
{
"ok-patch-version-3",
"10.20.10",
true,
},
{
"Empty",
"",
false,
},
{
"not ok",
"afssfdfs",
false,
},
{
"not ok-major-version",
"1",
false,
},
{
"not ok-version",
"v1.20.1",
false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
r := validator.StringResponse{}
VersionNumber().ValidateString(context.Background(), validator.StringRequest{
ConfigValue: types.StringValue(tt.input),
}, &r)
if !tt.isValid && !r.Diagnostics.HasError() {
t.Fatalf("Should have failed")
}
if tt.isValid && r.Diagnostics.HasError() {
t.Fatalf("Should not have failed: %v", r.Diagnostics.Errors())
}
})
}
}
func TestRFC3339SecondsOnly(t *testing.T) {
tests := []struct {
description string