-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added feature gates & admission controllers to kube options * Update terraform-plugin-sdk, mks-go; test workflow; fix tabs in test fixtures Update dependencies * Update cluster tests, changelog * Added available_feature_gates datasource with tests * Added available_admission_controllers datasource with tests * Update changelog, fix imports * Revert back changelog * Linter fixes; update vendor * Fix naming issues; update schema types; code optimizations * Fix go.sum conflict * Update kube options resource schema * Fix tests, admission-controllers * Add documentation for kube options * Fix test cluster update with kube options * Refactor mks cluster tests with kube options; Rename kube_version_minor -> kube_version; Update website docs; Revert back go test flag. * Update docs attributes references; Fix linter issues * Rename test cluster update function; Refactor getting MKS client in tests * Fix empty set instead nil * Fix linter gci issue Co-authored-by: Sergei Kolyshkin <kolyshkin.sa@gmail.com>
- Loading branch information
1 parent
0a3a4ce
commit 22f58a9
Showing
23 changed files
with
1,119 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ linters: | |
|
||
linters-settings: | ||
dupl: | ||
threshold: 200 | ||
threshold: 300 | ||
|
||
issues: | ||
exclude-rules: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"names": { | ||
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": { | ||
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 | ||
} |
Oops, something went wrong.