sigs.k8s.io/cluster-api-provider-aws@v1.5.5/exp/api/v1beta1/types.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  
    22  	infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
    23  )
    24  
    25  const (
    26  	// ExternalResourceGCAnnotation is the name of an annotation that indicates if
    27  	// external resources should be garbage collected for the cluster.
    28  	ExternalResourceGCAnnotation = "aws.cluster.x-k8s.io/external-resource-gc"
    29  )
    30  
    31  // EBS can be used to automatically set up EBS volumes when an instance is launched.
    32  type EBS struct {
    33  	// Encrypted is whether the volume should be encrypted or not.
    34  	// +optional
    35  	Encrypted bool `json:"encrypted,omitempty"`
    36  
    37  	// The size of the volume, in GiB.
    38  	// This can be a number from 1-1,024 for standard, 4-16,384 for io1, 1-16,384
    39  	// for gp2, and 500-16,384 for st1 and sc1. If you specify a snapshot, the volume
    40  	// size must be equal to or larger than the snapshot size.
    41  	// +optional
    42  	VolumeSize int64 `json:"volumeSize,omitempty"`
    43  
    44  	// The volume type
    45  	// For more information, see Amazon EBS Volume Types (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html)
    46  	// +kubebuilder:validation:Enum=standard;io1;gp2;st1;sc1;io2
    47  	// +optional
    48  	VolumeType string `json:"volumeType,omitempty"`
    49  }
    50  
    51  // BlockDeviceMapping specifies the block devices for the instance.
    52  // You can specify virtual devices and EBS volumes.
    53  type BlockDeviceMapping struct {
    54  	// The device name exposed to the EC2 instance (for example, /dev/sdh or xvdh).
    55  	// +kubebuilder:validation:Required
    56  	DeviceName string `json:"deviceName,omitempty"`
    57  
    58  	// You can specify either VirtualName or Ebs, but not both.
    59  	// +optional
    60  	Ebs EBS `json:"ebs,omitempty"`
    61  }
    62  
    63  // AWSLaunchTemplate defines the desired state of AWSLaunchTemplate.
    64  type AWSLaunchTemplate struct {
    65  	// The name of the launch template.
    66  	Name string `json:"name,omitempty"`
    67  
    68  	// The name or the Amazon Resource Name (ARN) of the instance profile associated
    69  	// with the IAM role for the instance. The instance profile contains the IAM
    70  	// role.
    71  	IamInstanceProfile string `json:"iamInstanceProfile,omitempty"`
    72  
    73  	// AMI is the reference to the AMI from which to create the machine instance.
    74  	// +optional
    75  	AMI infrav1.AMIReference `json:"ami,omitempty"`
    76  
    77  	// ImageLookupFormat is the AMI naming format to look up the image for this
    78  	// machine It will be ignored if an explicit AMI is set. Supports
    79  	// substitutions for {{.BaseOS}} and {{.K8sVersion}} with the base OS and
    80  	// kubernetes version, respectively. The BaseOS will be the value in
    81  	// ImageLookupBaseOS or ubuntu (the default), and the kubernetes version as
    82  	// defined by the packages produced by kubernetes/release without v as a
    83  	// prefix: 1.13.0, 1.12.5-mybuild.1, or 1.17.3. For example, the default
    84  	// image format of capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-* will end up
    85  	// searching for AMIs that match the pattern capa-ami-ubuntu-?1.18.0-* for a
    86  	// Machine that is targeting kubernetes v1.18.0 and the ubuntu base OS. See
    87  	// also: https://golang.org/pkg/text/template/
    88  	// +optional
    89  	ImageLookupFormat string `json:"imageLookupFormat,omitempty"`
    90  
    91  	// ImageLookupOrg is the AWS Organization ID to use for image lookup if AMI is not set.
    92  	ImageLookupOrg string `json:"imageLookupOrg,omitempty"`
    93  
    94  	// ImageLookupBaseOS is the name of the base operating system to use for
    95  	// image lookup the AMI is not set.
    96  	ImageLookupBaseOS string `json:"imageLookupBaseOS,omitempty"`
    97  
    98  	// InstanceType is the type of instance to create. Example: m4.xlarge
    99  	InstanceType string `json:"instanceType,omitempty"`
   100  
   101  	// RootVolume encapsulates the configuration options for the root volume
   102  	// +optional
   103  	RootVolume *infrav1.Volume `json:"rootVolume,omitempty"`
   104  
   105  	// SSHKeyName is the name of the ssh key to attach to the instance. Valid values are empty string
   106  	// (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
   107  	// +optional
   108  	SSHKeyName *string `json:"sshKeyName,omitempty"`
   109  
   110  	// VersionNumber is the version of the launch template that is applied.
   111  	// Typically a new version is created when at least one of the following happens:
   112  	// 1) A new launch template spec is applied.
   113  	// 2) One or more parameters in an existing template is changed.
   114  	// 3) A new AMI is discovered.
   115  	VersionNumber *int64 `json:"versionNumber,omitempty"`
   116  
   117  	// AdditionalSecurityGroups is an array of references to security groups that should be applied to the
   118  	// instances. These security groups would be set in addition to any security groups defined
   119  	// at the cluster level or in the actuator.
   120  	// +optional
   121  	AdditionalSecurityGroups []infrav1.AWSResourceReference `json:"additionalSecurityGroups,omitempty"`
   122  }
   123  
   124  // Overrides are used to override the instance type specified by the launch template with multiple
   125  // instance types that can be used to launch On-Demand Instances and Spot Instances.
   126  type Overrides struct {
   127  	InstanceType string `json:"instanceType"`
   128  }
   129  
   130  // OnDemandAllocationStrategy indicates how to allocate instance types to fulfill On-Demand capacity.
   131  type OnDemandAllocationStrategy string
   132  
   133  var (
   134  	// OnDemandAllocationStrategyPrioritized uses the order of instance type overrides
   135  	// for the LaunchTemplate to define the launch priority of each instance type.
   136  	OnDemandAllocationStrategyPrioritized = OnDemandAllocationStrategy("prioritized")
   137  )
   138  
   139  // SpotAllocationStrategy indicates how to allocate instances across Spot Instance pools.
   140  type SpotAllocationStrategy string
   141  
   142  var (
   143  	// SpotAllocationStrategyLowestPrice will make the Auto Scaling group launch
   144  	// instances using the Spot pools with the lowest price, and evenly allocates
   145  	// your instances across the number of Spot pools that you specify.
   146  	SpotAllocationStrategyLowestPrice = SpotAllocationStrategy("lowest-price")
   147  
   148  	// SpotAllocationStrategyCapacityOptimized will make the Auto Scaling group launch
   149  	// instances using Spot pools that are optimally chosen based on the available Spot capacity.
   150  	SpotAllocationStrategyCapacityOptimized = SpotAllocationStrategy("capacity-optimized")
   151  )
   152  
   153  // InstancesDistribution to configure distribution of On-Demand Instances and Spot Instances.
   154  type InstancesDistribution struct {
   155  	// +kubebuilder:validation:Enum=prioritized
   156  	// +kubebuilder:default=prioritized
   157  	OnDemandAllocationStrategy OnDemandAllocationStrategy `json:"onDemandAllocationStrategy,omitempty"`
   158  
   159  	// +kubebuilder:validation:Enum=lowest-price;capacity-optimized
   160  	// +kubebuilder:default=lowest-price
   161  	SpotAllocationStrategy SpotAllocationStrategy `json:"spotAllocationStrategy,omitempty"`
   162  
   163  	// +kubebuilder:default=0
   164  	OnDemandBaseCapacity *int64 `json:"onDemandBaseCapacity,omitempty"`
   165  
   166  	// +kubebuilder:default=100
   167  	OnDemandPercentageAboveBaseCapacity *int64 `json:"onDemandPercentageAboveBaseCapacity,omitempty"`
   168  }
   169  
   170  // MixedInstancesPolicy for an Auto Scaling group.
   171  type MixedInstancesPolicy struct {
   172  	InstancesDistribution *InstancesDistribution `json:"instancesDistribution,omitempty"`
   173  	Overrides             []Overrides            `json:"overrides,omitempty"`
   174  }
   175  
   176  // Tags is a mapping for tags.
   177  type Tags map[string]string
   178  
   179  // AutoScalingGroup describes an AWS autoscaling group.
   180  type AutoScalingGroup struct {
   181  	// The tags associated with the instance.
   182  	ID                string          `json:"id,omitempty"`
   183  	Tags              infrav1.Tags    `json:"tags,omitempty"`
   184  	Name              string          `json:"name,omitempty"`
   185  	DesiredCapacity   *int32          `json:"desiredCapacity,omitempty"`
   186  	MaxSize           int32           `json:"maxSize,omitempty"`
   187  	MinSize           int32           `json:"minSize,omitempty"`
   188  	PlacementGroup    string          `json:"placementGroup,omitempty"`
   189  	Subnets           []string        `json:"subnets,omitempty"`
   190  	DefaultCoolDown   metav1.Duration `json:"defaultCoolDown,omitempty"`
   191  	CapacityRebalance bool            `json:"capacityRebalance,omitempty"`
   192  
   193  	MixedInstancesPolicy *MixedInstancesPolicy `json:"mixedInstancesPolicy,omitempty"`
   194  	Status               ASGStatus
   195  	Instances            []infrav1.Instance `json:"instances,omitempty"`
   196  }
   197  
   198  // ASGStatus is a status string returned by the autoscaling API.
   199  type ASGStatus string
   200  
   201  var (
   202  	// ASGStatusDeleteInProgress is the string representing an ASG that is currently deleting.
   203  	ASGStatusDeleteInProgress = ASGStatus("Delete in progress")
   204  )
   205  
   206  // TaintEffect is the effect for a Kubernetes taint.
   207  type TaintEffect string
   208  
   209  var (
   210  	// TaintEffectNoSchedule is a taint that indicates that a pod shouldn't be scheduled on a node
   211  	// unless it can tolerate the taint.
   212  	TaintEffectNoSchedule = TaintEffect("no-schedule")
   213  	// TaintEffectNoExecute is a taint that indicates that a pod shouldn't be schedule on a node
   214  	// unless it can tolerate it. And if its already running on the node it will be evicted.
   215  	TaintEffectNoExecute = TaintEffect("no-execute")
   216  	// TaintEffectPreferNoSchedule is a taint that indicates that there is a "preference" that pods shouldn't
   217  	// be scheduled on a node unless it can tolerate the taint. the scheduler will try to avoid placing the pod
   218  	// but it may still run on the node if there is no other option.
   219  	TaintEffectPreferNoSchedule = TaintEffect("prefer-no-schedule")
   220  )
   221  
   222  // Taint defines the specs for a Kubernetes taint.
   223  type Taint struct {
   224  	// Effect specifies the effect for the taint
   225  	// +kubebuilder:validation:Required
   226  	// +kubebuilder:validation:Enum=no-schedule;no-execute;prefer-no-schedule
   227  	Effect TaintEffect `json:"effect"`
   228  	// Key is the key of the taint
   229  	// +kubebuilder:validation:Required
   230  	Key string `json:"key"`
   231  	// Value is the value of the taint
   232  	// +kubebuilder:validation:Required
   233  	Value string `json:"value"`
   234  }
   235  
   236  // Equals is used to test if 2 taints are equal.
   237  func (t *Taint) Equals(other *Taint) bool {
   238  	if t == nil || other == nil {
   239  		return t == other
   240  	}
   241  
   242  	return t.Effect == other.Effect &&
   243  		t.Key == other.Key &&
   244  		t.Value == other.Value
   245  }
   246  
   247  // Taints is an array of Taints.
   248  type Taints []Taint
   249  
   250  // Contains checks for existence of a matching taint.
   251  func (t *Taints) Contains(taint *Taint) bool {
   252  	for _, t := range *t {
   253  		if t.Equals(taint) {
   254  			return true
   255  		}
   256  	}
   257  
   258  	return false
   259  }
   260  
   261  // UpdateConfig is the configuration options for updating a nodegroup. Only one of MaxUnavailable
   262  // and MaxUnavailablePercentage should be specified.
   263  type UpdateConfig struct {
   264  	// MaxUnavailable is the maximum number of nodes unavailable at once during a version update.
   265  	// Nodes will be updated in parallel. The maximum number is 100.
   266  	// +optional
   267  	// +kubebuilder:validation:Maximum=100
   268  	// +kubebuilder:validation:Minimum=1
   269  	MaxUnavailable *int `json:"maxUnavailable,omitempty"`
   270  
   271  	// MaxUnavailablePercentage is the maximum percentage of nodes unavailable during a version update. This
   272  	// percentage of nodes will be updated in parallel, up to 100 nodes at once.
   273  	// +optional
   274  	// +kubebuilder:validation:Maximum=100
   275  	// +kubebuilder:validation:Minimum=1
   276  	MaxUnavailablePercentage *int `json:"maxUnavailablePrecentage,omitempty"`
   277  }