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

Kubernetes: add taints field to node pool create and update requests #368

Merged
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ type KubernetesClusterUpgradeRequest struct {
VersionSlug string `json:"version,omitempty"`
}

// Taint represents a Kubernetes taint that can be associated with a node pool
// (and, transitively, with all nodes of that pool).
type Taint struct {
Key string
Value string
Effect string
}

func (t Taint) String() string {
if t.Value == "" {
return fmt.Sprintf("%s:%s", t.Key, t.Effect)
}
return fmt.Sprintf("%s=%s:%s", t.Key, t.Value, t.Effect)
}

// KubernetesNodePoolCreateRequest represents a request to create a node pool for a
// Kubernetes cluster.
type KubernetesNodePoolCreateRequest struct {
Expand All @@ -91,6 +106,7 @@ type KubernetesNodePoolCreateRequest struct {
Count int `json:"count,omitempty"`
Tags []string `json:"tags,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Taints []Taint `json:"taints,omitempty"`
AutoScale bool `json:"auto_scale,omitempty"`
MinNodes int `json:"min_nodes,omitempty"`
MaxNodes int `json:"max_nodes,omitempty"`
Expand All @@ -103,6 +119,7 @@ type KubernetesNodePoolUpdateRequest struct {
Count *int `json:"count,omitempty"`
Tags []string `json:"tags,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Taints *[]Taint `json:"taints,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a pointer here? Just curious because I've noticed that the other structs have Taints []Taint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question. The pointer is needed here so that we can differentiate between taints being omitted on the update (meaning "I do not want to change the taints at all in my update request") and setting the empty (not nil) slice (meaning "I want to clear all taints").

Taints on the other structs are not pointerized because in the respective cases, there is no need to:

  • for the create request in KubernetesNodePoolCreateRequest, not setting the taints is equal to leaving the taints empty, so no pointer is needed.
  • the KubernetesNodePool struct is returned from the API and is meant to indicate which taints are set. We want to be able to indicate if DOKS uses have zero or more taints set, so again no pointer is needed.

Hope this helps.

AutoScale *bool `json:"auto_scale,omitempty"`
MinNodes *int `json:"min_nodes,omitempty"`
MaxNodes *int `json:"max_nodes,omitempty"`
Expand Down Expand Up @@ -308,6 +325,7 @@ type KubernetesNodePool struct {
Count int `json:"count,omitempty"`
Tags []string `json:"tags,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Taints []Taint `json:"taints,omitempty"`
AutoScale bool `json:"auto_scale,omitempty"`
MinNodes int `json:"min_nodes,omitempty"`
MaxNodes int `json:"max_nodes,omitempty"`
Expand Down