Skip to content

Commit

Permalink
Add addon for aws node termination handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Sep 17, 2020
1 parent 1ecb9ab commit b9212f8
Show file tree
Hide file tree
Showing 15 changed files with 651 additions and 0 deletions.
16 changes: 16 additions & 0 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,22 @@ spec:
items:
type: string
type: array
nodeTerminationHandler:
description: NodeTerminationHandlerConfig determines the cluster autoscaler configuration.
properties:
enableScheduledEventDraining:
description: 'EnableScheduledEventDraining makes node termination handler drain nodes before the maintenance window starts for an EC2 instance scheduled event. Default: false'
type: boolean
enableSpotInterruptionDraining:
description: 'EnableSpotInterruptionDraining makes node termination handler drain nodes when spot interruption termination notice is received. Default: true'
type: boolean
enabled:
description: 'Enabled enables the node termination handler. Default: true'
type: boolean
prometheusEnable:
description: EnablePrometheusMetrics enables the "/metrics" endpoint.
type: boolean
type: object
nonMasqueradeCIDR:
description: MasterIPRange string `json:",omitempty"` NonMasqueradeCIDR is the CIDR for the internal k8s network (on which pods & services live) It cannot overlap ServiceClusterIPRange
type: string
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ type ClusterSpec struct {
CloudConfig *CloudConfiguration `json:"cloudConfig,omitempty"`
ExternalDNS *ExternalDNSConfig `json:"externalDns,omitempty"`

// NodeTerminationHandlerConfig determines the cluster autoscaler configuration.
NodeTerminationHandler *NodeTerminationHandlerConfig `json:"nodeTerminationHandler,omitempty"`

// Networking configuration
Networking *NetworkingSpec `json:"networking,omitempty"`
// API field controls how the API is exposed outside the cluster
Expand Down
16 changes: 16 additions & 0 deletions pkg/apis/kops/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,22 @@ type CloudConfiguration struct {
Openstack *OpenstackConfiguration `json:"openstack,omitempty"`
}

// NodeTerminationHandlerConfig determines the node termination handler configuration.
type NodeTerminationHandlerConfig struct {
// Enabled enables the node termination handler.
// Default: true
Enabled *bool `json:"enabled,omitempty"`
// EnableSpotInterruptionDraining makes node termination handler drain nodes when spot interruption termination notice is received.
// Default: true
EnableSpotInterruptionDraining *bool `json:"enableSpotInterruptionDraining,omitempty"`
// EnableScheduledEventDraining makes node termination handler drain nodes before the maintenance window starts for an EC2 instance scheduled event.
// Default: false
EnableScheduledEventDraining *bool `json:"enableScheduledEventDraining,omitempty"`

// EnablePrometheusMetrics enables the "/metrics" endpoint.
EnablePrometheusMetrics *bool `json:"prometheusEnable,omitempty"`
}

// ClusterAutoscalerConfig determines the cluster autoscaler configuration.
type ClusterAutoscalerConfig struct {
// Enabled enables the cluster autoscaler.
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kops/v1alpha2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ type ClusterSpec struct {
MasterKubelet *KubeletConfigSpec `json:"masterKubelet,omitempty"`
CloudConfig *CloudConfiguration `json:"cloudConfig,omitempty"`
ExternalDNS *ExternalDNSConfig `json:"externalDns,omitempty"`

// NodeTerminationHandlerConfig determines the cluster autoscaler configuration.
NodeTerminationHandler *NodeTerminationHandlerConfig `json:"nodeTerminationHandler,omitempty"`

// Networking configuration
Networking *NetworkingSpec `json:"networking,omitempty"`
// API field controls how the API is exposed outside the cluster
Expand Down
16 changes: 16 additions & 0 deletions pkg/apis/kops/v1alpha2/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,22 @@ type CloudConfiguration struct {
Openstack *OpenstackConfiguration `json:"openstack,omitempty"`
}

// NodeTerminationHandlerConfig determines the node termination handler configuration.
type NodeTerminationHandlerConfig struct {
// Enabled enables the node termination handler.
// Default: true
Enabled *bool `json:"enabled,omitempty"`
// EnableSpotInterruptionDraining makes node termination handler drain nodes when spot interruption termination notice is received.
// Default: true
EnableSpotInterruptionDraining *bool `json:"enableSpotInterruptionDraining,omitempty"`
// EnableScheduledEventDraining makes node termination handler drain nodes before the maintenance window starts for an EC2 instance scheduled event.
// Default: false
EnableScheduledEventDraining *bool `json:"enableScheduledEventDraining,omitempty"`

// EnablePrometheusMetrics enables the "/metrics" endpoint.
EnablePrometheusMetrics *bool `json:"prometheusEnable,omitempty"`
}

// ClusterAutoscalerConfig determines the cluster autoscaler configuration.
type ClusterAutoscalerConfig struct {
// Enabled enables the cluster autoscaler.
Expand Down
54 changes: 54 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pkg/apis/kops/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func validateClusterSpec(spec *kops.ClusterSpec, c *kops.Cluster, fieldPath *fie
allErrs = append(allErrs, validateClusterAutoscaler(c, spec.ClusterAutoscaler, fieldPath.Child("clusterAutoscaler"))...)
}

if spec.NodeTerminationHandler != nil {
allErrs = append(allErrs, validateNodeTerminationHandler(c, spec.NodeTerminationHandler, fieldPath.Child("nodeTerminationHandler"))...)
}

// IAM additionalPolicies
if spec.AdditionalPolicies != nil {
for k, v := range *spec.AdditionalPolicies {
Expand Down Expand Up @@ -1140,3 +1144,10 @@ func validateClusterAutoscaler(cluster *kops.Cluster, spec *kops.ClusterAutoscal

return allErrs
}

func validateNodeTerminationHandler(cluster *kops.Cluster, spec *kops.NodeTerminationHandlerConfig, fldPath *field.Path) (allErrs field.ErrorList) {
if kops.CloudProviderID(cluster.Spec.CloudProvider) != kops.CloudProviderAWS {
allErrs = append(allErrs, field.Forbidden(fldPath, "Node Termination Handler supports only AWS"))
}
return allErrs
}
41 changes: 41 additions & 0 deletions pkg/apis/kops/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/model/components/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"kubeproxy.go",
"kubescheduler.go",
"networking.go",
"nodeterminationhandler.go",
"openstack.go",
],
importpath = "k8s.io/kops/pkg/model/components",
Expand Down
52 changes: 52 additions & 0 deletions pkg/model/components/nodeterminationhandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package components

import (
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/loader"
)

// NodeTerminationHandlerOptionsBuilder adds options for the node termination handler to the model.
type NodeTerminationHandlerOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &NodeTerminationHandlerOptionsBuilder{}

func (b *NodeTerminationHandlerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
if clusterSpec.NodeTerminationHandler == nil {
return nil
}
nth := clusterSpec.NodeTerminationHandler
if nth.Enabled == nil {
nth.Enabled = fi.Bool(true)
}
if nth.EnableSpotInterruptionDraining == nil {
nth.EnableSpotInterruptionDraining = fi.Bool(true)
}
if nth.EnableScheduledEventDraining == nil {
nth.EnableScheduledEventDraining = fi.Bool(false)
}

if nth.EnablePrometheusMetrics == nil {
nth.EnablePrometheusMetrics = fi.Bool(false)
}
return nil
}
Loading

0 comments on commit b9212f8

Please sign in to comment.