Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kube options #168

Merged
merged 23 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
69d9ea9
Added feature gates & admission controllers to kube options
pavelpereyma Dec 18, 2020
90ade1e
Update terraform-plugin-sdk, mks-go; test workflow; fix tabs in test …
pavelpereyma Aug 20, 2021
2a5a020
Update cluster tests, changelog
pavelpereyma Aug 23, 2021
bc6ec96
Added available_feature_gates datasource with tests
pavelpereyma Aug 25, 2021
d1e8d26
Added available_admission_controllers datasource with tests
pavelpereyma Aug 30, 2021
4b3538b
Update changelog, fix imports
pavelpereyma Aug 30, 2021
9dea259
Revert back changelog
pavelpereyma Oct 27, 2021
d790a55
Merge branch 'master' into update-kube-options
pavelpereyma Oct 27, 2021
c317b59
Linter fixes; update vendor
pavelpereyma Nov 10, 2021
86243f2
Fix naming issues; update schema types; code optimizations
pavelpereyma Nov 11, 2021
402bf35
Merge branch 'master' into update-kube-options
pavelpereyma Nov 11, 2021
fd14f9f
Fix go.sum conflict
pavelpereyma Nov 11, 2021
7f4249f
Update kube options resource schema
pavelpereyma Nov 15, 2021
2e278fc
Fix tests, admission-controllers
pavelpereyma Nov 15, 2021
8ef01ee
Merge branch 'master' into update-kube-options
pavelpereyma Nov 15, 2021
c66f767
Add documentation for kube options
pavelpereyma Nov 16, 2021
7972408
Fix test cluster update with kube options
pavelpereyma Nov 16, 2021
d743f43
Refactor mks cluster tests with kube options;
pavelpereyma Nov 20, 2021
50ea0a8
Update docs attributes references;
pavelpereyma Nov 23, 2021
7b4b8c8
Rename test cluster update function;
pavelpereyma Nov 24, 2021
85e03ad
Fix empty set instead nil
pavelpereyma Dec 7, 2021
c0fddd0
Fix linter gci issue
pavelpereyma Dec 10, 2021
0412c90
Merge branch 'master' into update-kube-options
kolsean Dec 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Run test
run: make testacc
env:
GO_FLAGS: -mod=vendor
GO_FLAGS: -mod=vendor -v
pavelpereyma marked this conversation as resolved.
Show resolved Hide resolved
GO111MODULE: on
SEL_TOKEN: ${{ secrets.SEL_TOKEN }}

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ require (
github.com/selectel/dbaas-go v0.4.0
github.com/selectel/domains-go v0.3.0
github.com/selectel/go-selvpcclient v1.12.0
github.com/selectel/mks-go v0.6.0
github.com/selectel/mks-go v0.8.0
github.com/stretchr/testify v1.7.0
)
12 changes: 2 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/apparentlymart/go-cidr v1.0.1 h1:NmIwLZ/KdsjIUlhf+/Np40atNXm/+lZ5txfTJ/SpF+U=
github.com/apparentlymart/go-cidr v1.0.1/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
Expand All @@ -60,7 +58,6 @@ github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJE
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
github.com/aws/aws-sdk-go v1.25.3 h1:uM16hIw9BotjZKMZlX05SN2EFtaWfi/NonPKIARiBLQ=
Expand All @@ -87,16 +84,13 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-billy/v5 v5.1.0 h1:4pl5BV4o7ZG/lterP4S6WzJ6xr49Ba5ET9ygheTYahk=
github.com/go-git/go-billy/v5 v5.1.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12 h1:PbKy9zOy4aAKrJ5pibIRpVO2BXnK1Tlcg+caKI7Ox5M=
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
github.com/go-git/go-git/v5 v5.3.0 h1:8WKMtJR2j8RntEXR/uvTKagfEt4GYlwQ7mntE4+0GWc=
github.com/go-git/go-git/v5 v5.3.0/go.mod h1:xdX4bWJ48aOrdhnl2XqHYstHbbp6+LFS4r4X+lNVprw=
Expand Down Expand Up @@ -282,7 +276,6 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -296,8 +289,8 @@ github.com/selectel/domains-go v0.3.0 h1:0shjqQmpkWc6eM1SwgKqbTTNiT5G2BOEnvS7Jvu
github.com/selectel/domains-go v0.3.0/go.mod h1:AhXhwyMSTkpEWFiBLUvzFP76W+WN+ZblwmjLJLt7y58=
github.com/selectel/go-selvpcclient v1.12.0 h1:LsT074HOVF1dWYapsAWjaaJDQhmDPpcsVjSwQ1r1fj0=
github.com/selectel/go-selvpcclient v1.12.0/go.mod h1:HNteVXevZMjUCRR6lImTsGZZSTeKu89S/qbEDWDqmgc=
github.com/selectel/mks-go v0.6.0 h1:5ZlqvwlVrjrrbNygsiFfUGZTyTPzPGGo8aYJkbtrYV0=
github.com/selectel/mks-go v0.6.0/go.mod h1:OrlLnGes+HK7HNxUab/8Rll5iT0XQQnx4+dW1Ysph2o=
github.com/selectel/mks-go v0.8.0 h1:tZJ248zZmJEGYZaygqLzboTFml0qxKkRjEAPzVAN0Ro=
github.com/selectel/mks-go v0.8.0/go.mod h1:OrlLnGes+HK7HNxUab/8Rll5iT0XQQnx4+dW1Ysph2o=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
Expand Down Expand Up @@ -601,7 +594,6 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
251 changes: 251 additions & 0 deletions selectel/data_source_selectel_mks_kube_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
package selectel

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/selectel/mks-go/pkg/v1/kubeoptions"
)

func dataSourceMKSFeatureGatesV1() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceMKSFeatureGateV1Read,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Required: true,
},
"region": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
ru1Region,
ru2Region,
ru3Region,
ru7Region,
ru8Region,
ru9Region,
}, false),
},
"filter": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kube_version": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"feature_gates": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kube_version_minor": {
pavelpereyma marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Computed: true,
},
"names": {
pavelpereyma marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
},
},
},
},
},
}
}

func dataSourceMKSFeatureGateV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
mksClient, diagErr := getMKSClient(ctx, d, meta)
if diagErr != nil {
return diagErr
}

featureGates, _, err := kubeoptions.ListFeatureGates(ctx, mksClient)
if err != nil {
return diag.FromErr(errGettingObjects(objectFeatureGates, err))
}

filterSet := d.Get("filter").(*schema.Set)
if filterSet.Len() == 0 {
flatFG := flattenFeatureGates(featureGates)
if err := d.Set("feature_gates", flatFG); err != nil {
return diag.FromErr(err)
}

checksum, err := interfaceListChecksum(flatFG)
if err != nil {
return diag.FromErr(err)
}
d.SetId(checksum)

return nil
}

filterMap := filterSet.List()[0].(map[string]interface{})
kubeVersion := filterMap["kube_version"].(string)

if kubeVersion == "" {
return diag.Errorf("kubernetes version is not set")
}
kubeMinorVersion, err := kubeVersionTrimToMinor(kubeVersion)
if err != nil {
return diag.FromErr(err)
}

availableFeatureGates, err := filterKubeOptionsByKubeVersion(featureGates, kubeMinorVersion)
if err != nil {
return diag.FromErr(err)
}

flatFG := flattenFeatureGatesFromSlice(kubeMinorVersion, availableFeatureGates)
if err := d.Set("feature_gates", flatFG); err != nil {
return diag.FromErr(err)
}

checksum, err := stringListChecksum(availableFeatureGates)
if err != nil {
return diag.FromErr(err)
}
d.SetId(checksum)

return nil
}

func filterKubeOptionsByKubeVersion(options []*kubeoptions.View, version string) ([]string, error) {
if version == "" {
return nil, fmt.Errorf("kubernetes version is not set")
}

for _, view := range options {
if view.KubeVersion == version {
return view.Names, nil
}
}

return nil, fmt.Errorf("available kubernetes options for kubernetes version %q is not found", version)
}

func dataSourceMKSAdmissionControllersV1() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceMKSAdmissionControllersV1Read,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Required: true,
},
"region": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
ru1Region,
ru2Region,
ru3Region,
ru7Region,
ru8Region,
ru9Region,
}, false),
},
"filter": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kube_version": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"admission_controllers": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kube_version_minor": {
pavelpereyma marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Computed: true,
},
"names": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
},
},
},
},
},
}
}

func dataSourceMKSAdmissionControllersV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
mksClient, diagErr := getMKSClient(ctx, d, meta)
if diagErr != nil {
return diagErr
}

admissionControllers, _, err := kubeoptions.ListAdmissionControllers(ctx, mksClient)
if err != nil {
return diag.FromErr(errGettingObjects(objectAdmissionControllers, err))
}

filterSet := d.Get("filter").(*schema.Set)
if filterSet.Len() == 0 {
flatAC := flattenAdmissionControllers(admissionControllers)
if err := d.Set("admission_controllers", flatAC); err != nil {
return diag.FromErr(err)
}

checksum, err := interfaceListChecksum(flatAC)
if err != nil {
return diag.FromErr(err)
}
d.SetId(checksum)

return nil
}

filterMap := filterSet.List()[0].(map[string]interface{})
kubeVersion := filterMap["kube_version"].(string)

if kubeVersion == "" {
return diag.Errorf("kubernetes version is not set")
}
kubeMinorVersion, err := kubeVersionTrimToMinor(kubeVersion)
if err != nil {
return diag.FromErr(err)
}

availableAdmissionControllers, err := filterKubeOptionsByKubeVersion(admissionControllers, kubeMinorVersion)
if err != nil {
return diag.FromErr(err)
}

flatFG := flattenAdmissionControllersFromSlice(kubeMinorVersion, availableAdmissionControllers)
if err := d.Set("admission_controllers", flatFG); err != nil {
return diag.FromErr(err)
}

checksum, err := stringListChecksum(availableAdmissionControllers)
if err != nil {
return diag.FromErr(err)
}
d.SetId(checksum)

return nil
}
Loading