Skip to content

Commit ed51251

Browse files
authored
feat(k8s): add new features (#781)
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent bf506fa commit ed51251

20 files changed

+18126
-4374
lines changed

docs/resources/k8s_cluster.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ The following arguments are supported:
138138

139139
- `expendable_pods_priority_cutoff` - (Defaults to `-10`) Pods with priority below cutoff will be expendable. They can be killed without any consideration during scale down and they don't cause scale up. Pods with null priority (PodPriority disabled) are non expendable.
140140

141+
- `scale_down_utilization_threshold` - (Defaults to `0.5`) Node utilization level, defined as sum of requested resources divided by capacity, below which a node can be considered for scale down
142+
143+
- `max_graceful_termination_sec` - (Defaults to `600`) Maximum number of seconds the cluster autoscaler waits for pod termination when trying to scale down a node
144+
141145
- `auto_upgrade` - (Optional) The auto upgrade configuration.
142146

143147
- `enable` - (Optional) Set to `true` to enable Kubernetes patch version auto upgrades.
@@ -151,13 +155,30 @@ The following arguments are supported:
151155

152156
- `admission_plugins` - (Optional) The list of [admission plugins](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/) to enable on the cluster.
153157

158+
- `apiserver_cert_sans` - (Optional) Additional Subject Alternative Names for the Kubernetes API server certificate
159+
160+
- `open_id_connect_config` - (Optional) The OpenID Connect configuration of the cluster
161+
162+
- `issuer_url` - (Required) URL of the provider which allows the API server to discover public signing keys
163+
164+
- `client_id` - (Required) A client id that all tokens must be issued for
165+
166+
- `username_claim` - (Optional) JWT claim to use as the user name
167+
168+
- `username_prefix` - (Optional) Prefix prepended to username
169+
170+
- `groups_claim` - (Optional) JWT claim to use as the user's group
171+
172+
- `groups_prefix` - (Optional) Prefix prepended to group claims
173+
174+
- `required_claim` - (Optional) Multiple key=value pairs that describes a required claim in the ID Token
175+
154176
- `delete_additional_resources` - (Defaults to `false`) Delete additional resources like block volumes and loadbalancers that were created in Kubernetes on cluster deletion.
155177

156178
- `default_pool` - (Deprecated) See below.
157179

158180
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the cluster should be created.
159181

160-
161182
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the cluster is associated with.
162183

163184

docs/resources/k8s_pool.md

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ The following arguments are supported:
6565
- `container_runtime` - (Defaults to `docker`) The container runtime of the pool.
6666
~> **Important:** Updates to this field will recreate a new resource.
6767

68+
- `kubelet_args` - (Optional) The Kubelet arguments to be used by this pool
69+
70+
- `upgrade_policy` - (Optional) The Pool upgrade policy
71+
72+
- `max_surge` - (Defaults to `0`) The maximum number of nodes to be created during the upgrade
73+
74+
- `max_unavailable` - (Defaults to `1`) The maximum number of nodes that can be not ready at the same time
75+
76+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#regions) in which the pool should be created.
77+
~> **Important:** Updates to this field will recreate a new resource.
78+
6879
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the pool should be created.
6980

7081
- `wait_for_pool_ready` - (Default to `false`) Whether to wait for the pool to be ready.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/google/go-cmp v0.5.4
88
github.com/hashicorp/go-retryablehttp v0.6.8
99
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.0
10-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210202173413-337fb17121a1
10+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210211085245-203deabc64c6
1111
github.com/stretchr/testify v1.6.1
1212
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
1313
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
315315
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
316316
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
317317
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
318-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210202173413-337fb17121a1 h1:vytHInJpH5I4FheLyFW2wu5LmtcQOJhetm3+jaVGp74=
319-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210202173413-337fb17121a1/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
318+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210211085245-203deabc64c6 h1:Ei7z7j+ogIz1gYYbcskXjHPorPR2Vz5XPWL9TW0lUPo=
319+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210211085245-203deabc64c6/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
320320
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
321321
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
322322
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=

scaleway/helpers_k8s.go

+53
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package scaleway
33
import (
44
"context"
55
"fmt"
6+
"strconv"
67
"strings"
78
"time"
89

@@ -198,9 +199,31 @@ func clusterAutoscalerConfigFlatten(cluster *k8s.Cluster) []map[string]interface
198199
autoscalerConfig["balance_similar_node_groups"] = cluster.AutoscalerConfig.BalanceSimilarNodeGroups
199200
autoscalerConfig["expendable_pods_priority_cutoff"] = cluster.AutoscalerConfig.ExpendablePodsPriorityCutoff
200201

202+
// need to convert a f32 to f64 without precision loss
203+
thresholdF64, err := strconv.ParseFloat(fmt.Sprintf("%f", cluster.AutoscalerConfig.ScaleDownUtilizationThreshold), 64)
204+
if err != nil {
205+
// should never happen
206+
return nil
207+
}
208+
autoscalerConfig["scale_down_utilization_threshold"] = thresholdF64
209+
autoscalerConfig["max_graceful_termination_sec"] = cluster.AutoscalerConfig.MaxGracefulTerminationSec
210+
201211
return []map[string]interface{}{autoscalerConfig}
202212
}
203213

214+
func clusterOpenIDConnectConfigFlatten(cluster *k8s.Cluster) []map[string]interface{} {
215+
openIDConnectConfig := map[string]interface{}{}
216+
openIDConnectConfig["issuer_url"] = cluster.OpenIDConnectConfig.IssuerURL
217+
openIDConnectConfig["client_id"] = cluster.OpenIDConnectConfig.ClientID
218+
openIDConnectConfig["username_claim"] = cluster.OpenIDConnectConfig.UsernameClaim
219+
openIDConnectConfig["username_prefix"] = cluster.OpenIDConnectConfig.UsernamePrefix
220+
openIDConnectConfig["groups_claim"] = cluster.OpenIDConnectConfig.GroupsClaim
221+
openIDConnectConfig["groups_prefix"] = cluster.OpenIDConnectConfig.GroupsPrefix
222+
openIDConnectConfig["required_claim"] = cluster.OpenIDConnectConfig.RequiredClaim
223+
224+
return []map[string]interface{}{openIDConnectConfig}
225+
}
226+
204227
func clusterAutoUpgradeFlatten(cluster *k8s.Cluster) []map[string]interface{} {
205228
autoUpgrade := map[string]interface{}{}
206229
autoUpgrade["enable"] = cluster.AutoUpgrade.Enabled
@@ -209,3 +232,33 @@ func clusterAutoUpgradeFlatten(cluster *k8s.Cluster) []map[string]interface{} {
209232

210233
return []map[string]interface{}{autoUpgrade}
211234
}
235+
236+
func poolUpgradePolicyFlatten(pool *k8s.Pool) []map[string]interface{} {
237+
upgradePolicy := map[string]interface{}{}
238+
if pool.UpgradePolicy != nil {
239+
upgradePolicy["max_surge"] = pool.UpgradePolicy.MaxSurge
240+
upgradePolicy["max_unavailable"] = pool.UpgradePolicy.MaxUnavailable
241+
}
242+
243+
return []map[string]interface{}{upgradePolicy}
244+
}
245+
246+
func expandKubeletArgs(args interface{}) map[string]string {
247+
kubeletArgs := map[string]string{}
248+
249+
for key, value := range args.(map[string]interface{}) {
250+
kubeletArgs[key] = value.(string)
251+
}
252+
253+
return kubeletArgs
254+
}
255+
256+
func flattenKubeletArgs(args map[string]string) map[string]interface{} {
257+
kubeletArgs := map[string]interface{}{}
258+
259+
for key, value := range args {
260+
kubeletArgs[key] = value
261+
}
262+
263+
return kubeletArgs
264+
}

0 commit comments

Comments
 (0)