Skip to content

Commit 7b321ba

Browse files
authored
feat: add support for specifying container runtime (#323)
* feat: add support for specifying container runtime Signed-off-by: Jonah Back <[email protected]> * document bootstrap options Signed-off-by: Jonah Back <[email protected]> * Validate container runtime being used Signed-off-by: Jonah Back <[email protected]>
1 parent 1e16aff commit 7b321ba

File tree

7 files changed

+60
-6
lines changed

7 files changed

+60
-6
lines changed

api/v1alpha1/instancegroup_types.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ const (
7878
DedicatedPlacementTenancyType = "dedicated"
7979
)
8080

81+
type ContainerRuntime string
8182
type ScalingConfigurationType string
8283

8384
const (
8485
LaunchConfiguration ScalingConfigurationType = "LaunchConfiguration"
8586
LaunchTemplate ScalingConfigurationType = "LaunchTemplate"
87+
88+
DockerRuntime ContainerRuntime = "dockerd"
89+
ContainerDRuntime ContainerRuntime = "containerd"
8690
)
8791

8892
var (
@@ -105,6 +109,7 @@ var (
105109
}
106110
DefaultCRDStrategyMaxRetries = 3
107111

112+
AllowedContainerRuntimes = []ContainerRuntime{ContainerDRuntime, DockerRuntime}
108113
AllowedFileSystemTypes = []string{FileSystemTypeXFS, FileSystemTypeEXT4}
109114
AllowedMixedPolicyStrategies = []string{LaunchTemplateStrategyCapacityOptimized, LaunchTemplateStrategyLowestPrice}
110115
AllowedInstancePools = []string{SubFamilyFlexibleInstancePool}
@@ -187,7 +192,8 @@ type EKSManagedSpec struct {
187192
}
188193

189194
type BootstrapOptions struct {
190-
MaxPods int64 `json:"maxPods,omitempty"`
195+
MaxPods int64 `json:"maxPods,omitempty"`
196+
ContainerRuntime ContainerRuntime `json:"containerRuntime,omitempty"`
191197
}
192198

193199
type WarmPoolSpec struct {
@@ -474,6 +480,15 @@ func (s *EKSSpec) HasWarmPool() bool {
474480
return false
475481
}
476482

483+
func contains(s []ContainerRuntime, e ContainerRuntime) bool {
484+
for _, a := range s {
485+
if a == e {
486+
return true
487+
}
488+
}
489+
return false
490+
}
491+
477492
func (c *EKSConfiguration) Validate() error {
478493
if common.StringEmpty(c.EksClusterName) {
479494
return errors.Errorf("validation failed, 'clusterName' is a required parameter")
@@ -506,6 +521,13 @@ func (c *EKSConfiguration) Validate() error {
506521
c.SuspendedProcesses = processes
507522
}
508523

524+
525+
if c.BootstrapOptions != nil {
526+
if c.BootstrapOptions.ContainerRuntime != "" && !contains(AllowedContainerRuntimes, c.BootstrapOptions.ContainerRuntime) {
527+
return errors.Errorf("validation failed, 'bootstrapOptions.containerRuntime' must be one of %+v", AllowedContainerRuntimes)
528+
}
529+
}
530+
509531
hooks := []LifecycleHookSpec{}
510532
for _, h := range c.LifecycleHooks {
511533
if h.HeartbeatTimeout == 0 {

api/v1alpha1/instancegroup_types_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ func TestInstanceGroupSpecValidate(t *testing.T) {
109109
},
110110
want: "validation failed, 'LicenseSpecifications[0]' must be a valid IAM role ARN",
111111
},
112+
{
113+
name: "eks with invalid container runtime",
114+
args: args{
115+
instancegroup: MockInstanceGroup("eks", "rollingUpdate", &EKSSpec{
116+
MaxSize: 1,
117+
MinSize: 1,
118+
Type: "LaunchTemplate",
119+
EKSConfiguration: &EKSConfiguration{
120+
BootstrapOptions: &BootstrapOptions{ContainerRuntime: "foo"},
121+
EksClusterName: "my-eks-cluster",
122+
NodeSecurityGroups: []string{"sg-123456789"},
123+
Image: "ami-12345",
124+
InstanceType: "m5.large",
125+
KeyPairName: "thisShouldBeOptional",
126+
Subnets: []string{"subnet-1111111", "subnet-222222"},
127+
},
128+
}, nil, nil),
129+
},
130+
want: "validation failed, 'bootstrapOptions.containerRuntime' must be one of [containerd dockerd]",
131+
},
112132
{
113133
name: "eks with valid Placement",
114134
args: args{
@@ -283,7 +303,7 @@ func TestInstanceGroupSpecValidate(t *testing.T) {
283303
},
284304
Volumes: []NodeVolume{
285305
{
286-
Type: "gp2",
306+
Type: "gp2",
287307
Iops: 1000,
288308
},
289309
},

config/crd/bases/instancemgr.keikoproj.io_instancegroups.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ spec:
7575
type: string
7676
bootstrapOptions:
7777
properties:
78+
containerRuntime:
79+
type: string
7880
maxPods:
7981
format: int64
8082
type: integer

controllers/providers/aws/eks_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88

99
func TestClusterDns(t *testing.T) {
1010
var (
11-
g = gomega.NewGomegaWithT(t)
11+
g = gomega.NewGomegaWithT(t)
1212
)
1313

1414
awsWorker := AwsWorker{}
1515
cidr := "172.16.0.0/12"
1616
ip := awsWorker.GetDNSClusterIP(&eks.Cluster{KubernetesNetworkConfig: &eks.KubernetesNetworkConfigResponse{ServiceIpv4Cidr: &cidr}})
1717
g.Expect(ip).To(gomega.Equal("172.16.0.10"))
1818

19-
}
19+
}

controllers/provisioners/eks/helpers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ func (ctx *EksInstanceGroupContext) GetBootstrapArgs() string {
539539
if bootstrapOptions != nil && bootstrapOptions.MaxPods > 0 {
540540
sb.WriteString("--use-max-pods false ")
541541
}
542+
543+
if bootstrapOptions != nil && bootstrapOptions.ContainerRuntime != "" {
544+
sb.WriteString(fmt.Sprintf("--container-runtime %v ", bootstrapOptions.ContainerRuntime))
545+
}
542546
if state.Cluster != nil {
543547
sb.WriteString(fmt.Sprintf("--b64-cluster-ca %v ", aws.StringValue(state.Cluster.CertificateAuthority.Data)))
544548
sb.WriteString(fmt.Sprintf("--apiserver-endpoint %v ", aws.StringValue(state.Cluster.Endpoint)))

controllers/provisioners/eks/helpers_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ func TestGetBasicUserDataAmazonLinux2(t *testing.T) {
9696
ctx := MockContext(ig, k, w)
9797

9898
configuration.BootstrapOptions = &v1alpha1.BootstrapOptions{
99-
MaxPods: 4,
99+
MaxPods: 4,
100+
ContainerRuntime: "containerd",
100101
}
101102
configuration.Labels = map[string]string{
102103
"foo": "bar",
@@ -159,7 +160,7 @@ if [[ $(type -P $(which aws)) ]] && [[ $(type -P $(which jq)) ]] ; then
159160
fi
160161
fi
161162
set -o xtrace
162-
/etc/eks/bootstrap.sh foo --use-max-pods false --b64-cluster-ca dGVzdA== --apiserver-endpoint foo.amazonaws.com --dns-cluster-ip 172.20.0.10 --kubelet-extra-args '--node-labels=foo=bar,instancemgr.keikoproj.io/image=ami-123456789012,node.kubernetes.io/role=instance-group-1 --register-with-taints=foo=bar:NoSchedule --eviction-hard=memory.available<300Mi,nodefs.available<5% --system-reserved=memory=2.5Gi --v=2 --max-pods=4'
163+
/etc/eks/bootstrap.sh foo --use-max-pods false --container-runtime containerd --b64-cluster-ca dGVzdA== --apiserver-endpoint foo.amazonaws.com --dns-cluster-ip 172.20.0.10 --kubelet-extra-args '--node-labels=foo=bar,instancemgr.keikoproj.io/image=ami-123456789012,node.kubernetes.io/role=instance-group-1 --register-with-taints=foo=bar:NoSchedule --eviction-hard=memory.available<300Mi,nodefs.available<5% --system-reserved=memory=2.5Gi --v=2 --max-pods=4'
163164
set +o xtrace
164165
bar`
165166
userData := ctx.GetBasicUserData("foo", args, kubeletArgs, userDataPayload, mounts)

docs/EKS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ spec:
5858
# All (will suspend all above processes)
5959
suspendProcesses: <[]string> : must match scaling process names to suspend
6060

61+
bootstrapOptions:
62+
containerRuntime: <string> : one of "dockerd" or "containerd". Specifies which container runtime to use. Currently only available on Amazon Linux 2
63+
maxPods: <int> : maximum number of pods that can be run per-node in this IG.
64+
65+
6166
bootstrapArguments: <string> : additional flags to pass to boostrap.sh script
6267
spotPrice: <string> : must be a decimal number represnting a minimal spot price
6368

0 commit comments

Comments
 (0)