Skip to content

Commit

Permalink
SKS nodepool: allow specifying kubelet image gc parameters on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrondier committed Apr 4, 2024
1 parent 2cf4dbc commit 24c5f70
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 75 deletions.
82 changes: 46 additions & 36 deletions cmd/sks_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,39 @@ type sksCreateCmd struct {

Name string `cli-arg:"#" cli-usage:"NAME"`

AutoUpgrade bool `cli-usage:"enable automatic upgrading of the SKS cluster control plane Kubernetes version"`
CNI string `cli-usage:"CNI plugin to deploy. e.g. 'calico', or 'cilium'"`
Description string `cli-usage:"SKS cluster description"`
KubernetesVersion string `cli-usage:"SKS cluster control plane Kubernetes version"`
Labels map[string]string `cli-flag:"label" cli-usage:"SKS cluster label (format: key=value)"`
NoCNI bool `cli-usage:"do not deploy a default Container Network Interface plugin in the cluster control plane"`
NoExoscaleCCM bool `cli-usage:"do not deploy the Exoscale Cloud Controller Manager in the cluster control plane"`
NoMetricsServer bool `cli-usage:"do not deploy the Kubernetes Metrics Server in the cluster control plane"`
ExoscaleCSI bool `cli-usage:"deploy the Exoscale Container Storage Interface on worker nodes"`
NodepoolAntiAffinityGroups []string `cli-flag:"nodepool-anti-affinity-group" cli-usage:"default Nodepool Anti-Affinity Group NAME|ID (can be specified multiple times)"`
NodepoolDeployTarget string `cli-usage:"default Nodepool Deploy Target NAME|ID"`
NodepoolDescription string `cli-usage:"default Nodepool description"`
NodepoolDiskSize int64 `cli-usage:"default Nodepool Compute instances disk size"`
NodepoolInstancePrefix string `cli-usage:"string to prefix default Nodepool member names with"`
NodepoolInstanceType string `cli-usage:"default Nodepool Compute instances type"`
NodepoolLabels map[string]string `cli-flag:"nodepool-label" cli-usage:"default Nodepool label (format: key=value)"`
NodepoolName string `cli-usage:"default Nodepool name"`
NodepoolPrivateNetworks []string `cli-flag:"nodepool-private-network" cli-usage:"default Nodepool Private Network NAME|ID (can be specified multiple times)"`
NodepoolSecurityGroups []string `cli-flag:"nodepool-security-group" cli-usage:"default Nodepool Security Group NAME|ID (can be specified multiple times)"`
NodepoolSize int64 `cli-usage:"default Nodepool size. If 0, no default Nodepool will be added to the cluster."`
NodepoolTaints []string `cli-flag:"nodepool-taint" cli-usage:"Kubernetes taint to apply to default Nodepool Nodes (format: KEY=VALUE:EFFECT, can be specified multiple times)"`
OIDCClientID string `cli-flag:"oidc-client-id" cli-usage:"OpenID client ID"`
OIDCGroupsClaim string `cli-flag:"oidc-groups-claim" cli-usage:"OpenID JWT claim to use as the user's group"`
OIDCGroupsPrefix string `cli-flag:"oidc-groups-prefix" cli-usage:"OpenID prefix prepended to group claims"`
OIDCIssuerURL string `cli-flag:"oidc-issuer-url" cli-usage:"OpenID provider URL"`
OIDCRequiredClaim map[string]string `cli-flag:"oidc-required-claim" cli-usage:"OpenID token required claim (format: key=value)"`
OIDCUsernameClaim string `cli-flag:"oidc-username-claim" cli-usage:"OpenID JWT claim to use as the user name"`
OIDCUsernamePrefix string `cli-flag:"oidc-username-prefix" cli-usage:"OpenID prefix prepended to username claims"`
ServiceLevel string `cli-usage:"SKS cluster control plane service level (starter|pro)"`
Zone string `cli-short:"z" cli-usage:"SKS cluster zone"`
AutoUpgrade bool `cli-usage:"enable automatic upgrading of the SKS cluster control plane Kubernetes version"`
CNI string `cli-usage:"CNI plugin to deploy. e.g. 'calico', or 'cilium'"`
Description string `cli-usage:"SKS cluster description"`
KubernetesVersion string `cli-usage:"SKS cluster control plane Kubernetes version"`
Labels map[string]string `cli-flag:"label" cli-usage:"SKS cluster label (format: key=value)"`
NoCNI bool `cli-usage:"do not deploy a default Container Network Interface plugin in the cluster control plane"`
NoExoscaleCCM bool `cli-usage:"do not deploy the Exoscale Cloud Controller Manager in the cluster control plane"`
NoMetricsServer bool `cli-usage:"do not deploy the Kubernetes Metrics Server in the cluster control plane"`
ExoscaleCSI bool `cli-usage:"deploy the Exoscale Container Storage Interface on worker nodes"`
NodepoolAntiAffinityGroups []string `cli-flag:"nodepool-anti-affinity-group" cli-usage:"default Nodepool Anti-Affinity Group NAME|ID (can be specified multiple times)"`
NodepoolDeployTarget string `cli-usage:"default Nodepool Deploy Target NAME|ID"`
NodepoolDescription string `cli-usage:"default Nodepool description"`
NodepoolDiskSize int64 `cli-usage:"default Nodepool Compute instances disk size"`
NodepoolImageGcLowThreshold int64 `cli-flag:"nodepool-image-gc-low-threshold" cli-usage:"default Nodepool the percent of disk usage after which image garbage collection is never run"`
NodepoolImageGcHighThreshold int64 `cli-flag:"nodepool-image-gc-high-threshold" cli-usage:"default Nodepool the percent of disk usage after which image garbage collection is always run"`
NodepoolImageGcMinAge string `cli-flag:"nodepool-image-gc-min-age" cli-usage:"default Nodepool maximum age an image can be unused before it is garbage collected"`
NodepoolInstancePrefix string `cli-usage:"string to prefix default Nodepool member names with"`
NodepoolInstanceType string `cli-usage:"default Nodepool Compute instances type"`
NodepoolLabels map[string]string `cli-flag:"nodepool-label" cli-usage:"default Nodepool label (format: key=value)"`
NodepoolName string `cli-usage:"default Nodepool name"`
NodepoolPrivateNetworks []string `cli-flag:"nodepool-private-network" cli-usage:"default Nodepool Private Network NAME|ID (can be specified multiple times)"`
NodepoolSecurityGroups []string `cli-flag:"nodepool-security-group" cli-usage:"default Nodepool Security Group NAME|ID (can be specified multiple times)"`
NodepoolSize int64 `cli-usage:"default Nodepool size. If 0, no default Nodepool will be added to the cluster."`
NodepoolTaints []string `cli-flag:"nodepool-taint" cli-usage:"Kubernetes taint to apply to default Nodepool Nodes (format: KEY=VALUE:EFFECT, can be specified multiple times)"`
OIDCClientID string `cli-flag:"oidc-client-id" cli-usage:"OpenID client ID"`
OIDCGroupsClaim string `cli-flag:"oidc-groups-claim" cli-usage:"OpenID JWT claim to use as the user's group"`
OIDCGroupsPrefix string `cli-flag:"oidc-groups-prefix" cli-usage:"OpenID prefix prepended to group claims"`
OIDCIssuerURL string `cli-flag:"oidc-issuer-url" cli-usage:"OpenID provider URL"`
OIDCRequiredClaim map[string]string `cli-flag:"oidc-required-claim" cli-usage:"OpenID token required claim (format: key=value)"`
OIDCUsernameClaim string `cli-flag:"oidc-username-claim" cli-usage:"OpenID JWT claim to use as the user name"`
OIDCUsernamePrefix string `cli-flag:"oidc-username-prefix" cli-usage:"OpenID prefix prepended to username claims"`
ServiceLevel string `cli-usage:"SKS cluster control plane service level (starter|pro)"`
Zone string `cli-short:"z" cli-usage:"SKS cluster zone"`
}

func (c *sksCreateCmd) cmdAliases() []string { return gCreateAlias }
Expand Down Expand Up @@ -188,6 +191,11 @@ func (c *sksCreateCmd) cmdRun(_ *cobra.Command, _ []string) error { //nolint:goc
return c.Name
}()),
Size: &c.NodepoolSize,
KubeletImageGc: &egoscale.SKSNodepoolKubeletImageGc{
MinAge: &c.NodepoolImageGcMinAge,
LowThreshold: &c.NodepoolImageGcLowThreshold,
HighThreshold: &c.NodepoolImageGcHighThreshold,
},
}

if l := len(c.NodepoolAntiAffinityGroups); l > 0 {
Expand Down Expand Up @@ -275,12 +283,14 @@ func init() {
cobra.CheckErr(registerCLICommand(sksCmd, &sksCreateCmd{
cliCommandSettings: defaultCLICmdSettings(),

CNI: defaultSKSClusterCNI,
KubernetesVersion: "latest",
NodepoolDiskSize: 50,
NodepoolInstanceType: fmt.Sprintf("%s.%s", defaultInstanceTypeFamily, defaultInstanceType),

ServiceLevel: defaultSKSClusterServiceLevel,
CNI: defaultSKSClusterCNI,
KubernetesVersion: "latest",
NodepoolDiskSize: 50,
NodepoolInstanceType: fmt.Sprintf("%s.%s", defaultInstanceTypeFamily, defaultInstanceType),
NodepoolImageGcLowThreshold: 80,
NodepoolImageGcHighThreshold: 85,
NodepoolImageGcMinAge: "2m",
ServiceLevel: defaultSKSClusterServiceLevel,
}))

}
43 changes: 27 additions & 16 deletions cmd/sks_nodepool_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ type sksNodepoolAddCmd struct {
Cluster string `cli-arg:"#" cli-usage:"CLUSTER-NAME|ID"`
Name string `cli-arg:"#" cli-usage:"NODEPOOL-NAME"`

AntiAffinityGroups []string `cli-flag:"anti-affinity-group" cli-usage:"Nodepool Anti-Affinity Group NAME|ID (can be specified multiple times)"`
DeployTarget string `cli-usage:"Nodepool Deploy Target NAME|ID"`
Description string `cli-usage:"Nodepool description"`
DiskSize int64 `cli-usage:"Nodepool Compute instances disk size"`
InstancePrefix string `cli-usage:"string to prefix Nodepool member names with"`
InstanceType string `cli-usage:"Nodepool Compute instances type"`
Labels []string `cli-flag:"label" cli-usage:"Nodepool label (format: key=value)"`
PrivateNetworks []string `cli-flag:"private-network" cli-usage:"Nodepool Private Network NAME|ID (can be specified multiple times)"`
SecurityGroups []string `cli-flag:"security-group" cli-usage:"Nodepool Security Group NAME|ID (can be specified multiple times)"`
Size int64 `cli-usage:"Nodepool size"`
StorageLvm bool `cli-usage:"Create nodes with non-standard partitioning for persistent storage"`
Taints []string `cli-flag:"taint" cli-usage:"Kubernetes taint to apply to Nodepool Nodes (format: KEY=VALUE:EFFECT, can be specified multiple times)"`
Zone string `cli-short:"z" cli-usage:"SKS cluster zone"`
AntiAffinityGroups []string `cli-flag:"anti-affinity-group" cli-usage:"Nodepool Anti-Affinity Group NAME|ID (can be specified multiple times)"`
DeployTarget string `cli-usage:"Nodepool Deploy Target NAME|ID"`
Description string `cli-usage:"Nodepool description"`
DiskSize int64 `cli-usage:"Nodepool Compute instances disk size"`
ImageGcLowThreshold int64 `cli-flag:"image-gc-low-threshold" cli-usage:"the percent of disk usage after which image garbage collection is never run"`
ImageGcHighThreshold int64 `cli-flag:"image-gc-high-threshold" cli-usage:"the percent of disk usage after which image garbage collection is always run"`
ImageGcMinAge string `cli-flag:"image-gc-min-age" cli-usage:"maximum age an image can be unused before it is garbage collected"`
InstancePrefix string `cli-usage:"string to prefix Nodepool member names with"`
InstanceType string `cli-usage:"Nodepool Compute instances type"`
Labels []string `cli-flag:"label" cli-usage:"Nodepool label (format: key=value)"`
PrivateNetworks []string `cli-flag:"private-network" cli-usage:"Nodepool Private Network NAME|ID (can be specified multiple times)"`
SecurityGroups []string `cli-flag:"security-group" cli-usage:"Nodepool Security Group NAME|ID (can be specified multiple times)"`
Size int64 `cli-usage:"Nodepool size"`
StorageLvm bool `cli-usage:"Create nodes with non-standard partitioning for persistent storage"`
Taints []string `cli-flag:"taint" cli-usage:"Kubernetes taint to apply to Nodepool Nodes (format: KEY=VALUE:EFFECT, can be specified multiple times)"`
Zone string `cli-short:"z" cli-usage:"SKS cluster zone"`
}

func (c *sksNodepoolAddCmd) cmdAliases() []string { return nil }
Expand All @@ -61,6 +64,11 @@ func (c *sksNodepoolAddCmd) cmdRun(_ *cobra.Command, _ []string) error {
InstancePrefix: utils.NonEmptyStringPtr(c.InstancePrefix),
Name: &c.Name,
Size: &c.Size,
KubeletImageGc: &egoscale.SKSNodepoolKubeletImageGc{
MinAge: &c.ImageGcMinAge,
LowThreshold: &c.ImageGcLowThreshold,
HighThreshold: &c.ImageGcHighThreshold,
},
}

ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))
Expand Down Expand Up @@ -180,8 +188,11 @@ func init() {
cobra.CheckErr(registerCLICommand(sksNodepoolCmd, &sksNodepoolAddCmd{
cliCommandSettings: defaultCLICmdSettings(),

Size: 2,
InstanceType: fmt.Sprintf("%s.%s", defaultInstanceTypeFamily, defaultInstanceType),
DiskSize: 50,
Size: 2,
InstanceType: fmt.Sprintf("%s.%s", defaultInstanceTypeFamily, defaultInstanceType),
DiskSize: 50,
ImageGcLowThreshold: 80,
ImageGcHighThreshold: 85,
ImageGcMinAge: "2m",
}))
}
57 changes: 39 additions & 18 deletions cmd/sks_nodepool_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@ import (
)

type sksNodepoolShowOutput struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreationDate string `json:"creation_date"`
InstancePoolID string `json:"instance_pool_id"`
InstancePrefix string `json:"instance_prefix"`
InstanceType string `json:"instance_type"`
Template string `json:"template"`
DiskSize int64 `json:"disk_size"`
AntiAffinityGroups []string `json:"anti_affinity_groups"`
SecurityGroups []string `json:"security_groups"`
PrivateNetworks []string `json:"private_networks"`
Version string `json:"version"`
Size int64 `json:"size"`
State string `json:"state"`
Taints []string `json:"taints"`
Labels map[string]string `json:"labels"`
AddOns []string `json:"addons"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreationDate string `json:"creation_date"`
InstancePoolID string `json:"instance_pool_id"`
InstancePrefix string `json:"instance_prefix"`
InstanceType string `json:"instance_type"`
Template string `json:"template"`
DiskSize int64 `json:"disk_size"`
AntiAffinityGroups []string `json:"anti_affinity_groups"`
SecurityGroups []string `json:"security_groups"`
PrivateNetworks []string `json:"private_networks"`
Version string `json:"version"`
Size int64 `json:"size"`
State string `json:"state"`
Taints []string `json:"taints"`
Labels map[string]string `json:"labels"`
AddOns []string `json:"addons"`
ImageGCMin string `json:"image_gc_min_age"`
ImageGcLowThreshold int64 `json:"image_gc_low_threshold"`
ImageGcHighThreshold int64 `json:"image_gc_high_threshold"`
}

func (o *sksNodepoolShowOutput) Type() string { return "SKS Nodepool" }
Expand Down Expand Up @@ -125,6 +128,24 @@ func (c *sksNodepoolShowCmd) cmdRun(_ *cobra.Command, _ []string) error {
}
return
}(),
ImageGCMin: func() (s string) {
if nodepool.KubeletImageGc != nil && nodepool.KubeletImageGc.MinAge != nil {
return *nodepool.KubeletImageGc.MinAge
}
return "2m"
}(),
ImageGcLowThreshold: func() (s int64) {
if nodepool.KubeletImageGc != nil && nodepool.KubeletImageGc.LowThreshold != nil {
return *nodepool.KubeletImageGc.LowThreshold
}
return 80
}(),
ImageGcHighThreshold: func() (s int64) {
if nodepool.KubeletImageGc != nil && nodepool.KubeletImageGc.HighThreshold != nil {
return *nodepool.KubeletImageGc.HighThreshold
}
return 85
}(),
Version: *nodepool.Version,
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.2.0
github.com/aws/smithy-go v1.1.0
github.com/dustin/go-humanize v1.0.1
github.com/exoscale/egoscale v0.102.4-0.20240223092311-76285ea0504f
github.com/exoscale/egoscale v0.102.4-0.20240327105104-a8a8cb197ac6
github.com/exoscale/openapi-cli-generator v1.1.0
github.com/fatih/camelcase v1.0.0
github.com/google/uuid v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.
github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v0.6.2/go.mod h1:2t7qjJNvHPx8IjnBOzl9E9/baC+qXE/TeeyBRzgJDws=
github.com/exoscale/egoscale v0.102.4-0.20240223092311-76285ea0504f h1:Ivacu1126KBSLhXvXST6H0ftMjehMV637fL/nb222LM=
github.com/exoscale/egoscale v0.102.4-0.20240223092311-76285ea0504f/go.mod h1:sFBCvHJx/h6u8Z5igoIcgbPs+wltBbEJrXA2xp05KoU=
github.com/exoscale/egoscale v0.102.4-0.20240327105104-a8a8cb197ac6 h1:UQwsohHjLp5mkcB+vZ7UuYrTi0FsBrQvgYD0guyNcSo=
github.com/exoscale/egoscale v0.102.4-0.20240327105104-a8a8cb197ac6/go.mod h1:sFBCvHJx/h6u8Z5igoIcgbPs+wltBbEJrXA2xp05KoU=
github.com/exoscale/openapi-cli-generator v1.1.0 h1:fYjmPqHR5vxlOBrbvde7eo7bISNQIFxsGn4A5/acwKA=
github.com/exoscale/openapi-cli-generator v1.1.0/go.mod h1:TZBnbT7f3hJ5ImyUphJwRM+X5xF/zCQZ6o8a42gQeTs=
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
Expand Down
Loading

0 comments on commit 24c5f70

Please sign in to comment.