Skip to content

Commit

Permalink
Merge pull request #9289 from johngmyers/launch-template
Browse files Browse the repository at this point in the history
Use launch templates by default
  • Loading branch information
k8s-ci-robot authored Jun 11, 2020
2 parents 2ce351f + 1b03e72 commit 54d4a81
Show file tree
Hide file tree
Showing 205 changed files with 7,803 additions and 20,877 deletions.
1 change: 1 addition & 0 deletions cloudmock/aws/mockautoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (m *MockAutoscaling) CreateAutoScalingGroup(input *autoscaling.CreateAutoSc
HealthCheckType: input.HealthCheckType,
Instances: []*autoscaling.Instance{},
LaunchConfigurationName: input.LaunchConfigurationName,
LaunchTemplate: input.LaunchTemplate,
LoadBalancerNames: input.LoadBalancerNames,
MaxSize: input.MaxSize,
MinSize: input.MinSize,
Expand Down
21 changes: 16 additions & 5 deletions cloudmock/aws/mockec2/launch_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,21 @@ func (m *MockEC2) CreateLaunchTemplate(request *ec2.CreateLaunchTemplateInput) (
}
if len(request.LaunchTemplateData.BlockDeviceMappings) > 0 {
for _, x := range request.LaunchTemplateData.BlockDeviceMappings {
resp.BlockDeviceMappings = append(resp.BlockDeviceMappings, &ec2.LaunchTemplateBlockDeviceMapping{
DeviceName: x.DeviceName,
Ebs: &ec2.LaunchTemplateEbsBlockDevice{
var ebs *ec2.LaunchTemplateEbsBlockDevice
if x.Ebs != nil {
ebs = &ec2.LaunchTemplateEbsBlockDevice{
DeleteOnTermination: x.Ebs.DeleteOnTermination,
Encrypted: x.Ebs.Encrypted,
Iops: x.Ebs.Iops,
KmsKeyId: x.Ebs.KmsKeyId,
SnapshotId: x.Ebs.SnapshotId,
VolumeSize: x.Ebs.VolumeSize,
VolumeType: x.Ebs.VolumeType,
},
}
}
resp.BlockDeviceMappings = append(resp.BlockDeviceMappings, &ec2.LaunchTemplateBlockDeviceMapping{
DeviceName: x.DeviceName,
Ebs: ebs,
NoDevice: x.NoDevice,
VirtualName: x.VirtualName,
})
Expand Down Expand Up @@ -157,7 +161,14 @@ func (m *MockEC2) CreateLaunchTemplate(request *ec2.CreateLaunchTemplateInput) (
})
}
}

if len(request.LaunchTemplateData.TagSpecifications) > 0 {
for _, x := range request.LaunchTemplateData.TagSpecifications {
resp.TagSpecifications = append(resp.TagSpecifications, &ec2.LaunchTemplateTagSpecification{
ResourceType: x.ResourceType,
Tags: x.Tags,
})
}
}
return &ec2.CreateLaunchTemplateOutput{}, nil
}

Expand Down
56 changes: 28 additions & 28 deletions cmd/kops/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ import (
const updateClusterTestBase = "../../tests/integration/update_cluster/"

type integrationTest struct {
clusterName string
srcDir string
version string
private bool
zones int
expectPolicies bool
launchTemplate bool
lifecycleOverrides []string
sshKey bool
jsonOutput bool
bastionUserData bool
clusterName string
srcDir string
version string
private bool
zones int
expectPolicies bool
launchConfiguration bool
lifecycleOverrides []string
sshKey bool
jsonOutput bool
bastionUserData bool
}

func newIntegrationTest(clusterName, srcDir string) *integrationTest {
Expand Down Expand Up @@ -111,8 +111,8 @@ func (i *integrationTest) withPrivate() *integrationTest {
return i
}

func (i *integrationTest) withLaunchTemplate() *integrationTest {
i.launchTemplate = true
func (i *integrationTest) withLaunchConfiguration() *integrationTest {
i.launchConfiguration = true
return i
}

Expand Down Expand Up @@ -317,31 +317,31 @@ func TestPhaseCluster(t *testing.T) {

// TestMixedInstancesASG tests ASGs using a mixed instance policy
func TestMixedInstancesASG(t *testing.T) {
newIntegrationTest("mixedinstances.example.com", "mixed_instances").withZones(3).withLaunchTemplate().runTestTerraformAWS(t)
newIntegrationTest("mixedinstances.example.com", "mixed_instances").withZones(3).withLaunchTemplate().runTestCloudformation(t)
newIntegrationTest("mixedinstances.example.com", "mixed_instances").withZones(3).runTestTerraformAWS(t)
newIntegrationTest("mixedinstances.example.com", "mixed_instances").withZones(3).runTestCloudformation(t)
}

// TestMixedInstancesSpotASG tests ASGs using a mixed instance policy and spot instances
func TestMixedInstancesSpotASG(t *testing.T) {
newIntegrationTest("mixedinstances.example.com", "mixed_instances_spot").withZones(3).withLaunchTemplate().runTestTerraformAWS(t)
newIntegrationTest("mixedinstances.example.com", "mixed_instances_spot").withZones(3).withLaunchTemplate().runTestCloudformation(t)
newIntegrationTest("mixedinstances.example.com", "mixed_instances_spot").withZones(3).runTestTerraformAWS(t)
newIntegrationTest("mixedinstances.example.com", "mixed_instances_spot").withZones(3).runTestCloudformation(t)
}

// TestContainerdCloudformation runs the test on a containerd configuration
func TestContainerdCloudformation(t *testing.T) {
newIntegrationTest("containerd.example.com", "containerd-cloudformation").runTestCloudformation(t)
}

// TestLaunchTemplatesASG tests ASGs using launch templates instead of launch configurations
func TestLaunchTemplatesASG(t *testing.T) {
featureflag.ParseFlags("+EnableLaunchTemplates")
// TestLaunchConfigurationASG tests ASGs using launch configurations instead of launch templates
func TestLaunchConfigurationASG(t *testing.T) {
featureflag.ParseFlags("-EnableLaunchTemplates")
unsetFeaureFlag := func() {
featureflag.ParseFlags("-EnableLaunchTemplates")
featureflag.ParseFlags("+EnableLaunchTemplates")
}
defer unsetFeaureFlag()

newIntegrationTest("launchtemplates.example.com", "launch_templates").withZones(3).withLaunchTemplate().runTestTerraformAWS(t)
newIntegrationTest("launchtemplates.example.com", "launch_templates").withZones(3).withLaunchTemplate().runTestCloudformation(t)
newIntegrationTest("launchtemplates.example.com", "launch_templates").withZones(3).withLaunchConfiguration().runTestTerraformAWS(t)
newIntegrationTest("launchtemplates.example.com", "launch_templates").withZones(3).withLaunchConfiguration().runTestCloudformation(t)
}

func (i *integrationTest) runTest(t *testing.T, h *testutils.IntegrationTestHarness, expectedDataFilenames []string, tfFileName string, expectedTfFileName string, phase *cloudup.Phase) {
Expand Down Expand Up @@ -497,10 +497,10 @@ func (i *integrationTest) runTestTerraformAWS(t *testing.T) {

expectedFilenames := []string{}

if i.launchTemplate {
expectedFilenames = append(expectedFilenames, "aws_launch_template_nodes."+i.clusterName+"_user_data")
} else {
if i.launchConfiguration {
expectedFilenames = append(expectedFilenames, "aws_launch_configuration_nodes."+i.clusterName+"_user_data")
} else {
expectedFilenames = append(expectedFilenames, "aws_launch_template_nodes."+i.clusterName+"_user_data")
}
if i.sshKey {
expectedFilenames = append(expectedFilenames, "aws_key_pair_kubernetes."+i.clusterName+"-c4a6ed9aa889b9e2c39cd663eb9c7157_public_key")
Expand Down Expand Up @@ -528,7 +528,7 @@ func (i *integrationTest) runTestTerraformAWS(t *testing.T) {
"aws_iam_role_policy_bastions." + i.clusterName + "_policy",
}...)
if i.bastionUserData {
expectedFilenames = append(expectedFilenames, "aws_launch_configuration_bastion."+i.clusterName+"_user_data")
expectedFilenames = append(expectedFilenames, "aws_launch_template_bastion."+i.clusterName+"_user_data")
}
}
}
Expand Down Expand Up @@ -561,7 +561,7 @@ func (i *integrationTest) runTestPhase(t *testing.T, phase cloudup.Phase) {
expectedFilenames = append(expectedFilenames, []string{
"aws_iam_role_bastions." + i.clusterName + "_policy",
"aws_iam_role_policy_bastions." + i.clusterName + "_policy",
"aws_launch_configuration_bastion." + i.clusterName + "_user_data",
"aws_launch_template_bastion." + i.clusterName + "_user_data",
}...)
}
} else if phase == cloudup.PhaseCluster {
Expand Down
1 change: 0 additions & 1 deletion docs/advanced/experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Enable experimental features with:
The following experimental features are currently available:

* `+EnableExternalDNS` - Enable external-dns with default settings (ingress sources only).
* `+EnableLaunchTemplates` - Enable using launch templates rather than launchconfigurations (AWS only)
* `+VPCSkipEnableDNSSupport` - Enables creation of a VPC that does not need DNSSupport enabled.
* `+SkipTerraformFormat` - Do not `terraform fmt` the generated terraform files.
* `+EnableExternalCloudController` - Enables the use of cloud-controller-manager introduced in v1.7.
Expand Down
2 changes: 2 additions & 0 deletions docs/releases/1.19-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Significant changes

* On AWS kops now defaults to using launch templates instead of launch configurations.

* Clusters using the Amazon VPC CNI provider now perform an `ec2.DescribeInstanceTypes` call at instance launch time. In large clusters or AWS accounts this may lead to API throttling which could delay node readiness. If this becomes a problem please open a GitHub issue.

# Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion pkg/featureflag/featureflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
// DNSPreCreate controls whether we pre-create DNS records.
DNSPreCreate = New("DNSPreCreate", Bool(true))
// EnableLaunchTemplates indicates we wish to switch to using launch templates rather than launchconfigurations
EnableLaunchTemplates = New("EnableLaunchTemplates", Bool(false))
EnableLaunchTemplates = New("EnableLaunchTemplates", Bool(true))
//EnableExternalCloudController toggles the use of cloud-controller-manager introduced in v1.7
EnableExternalCloudController = New("EnableExternalCloudController", Bool(false))
// EnableExternalDNS enables external DNS
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/awsmodel/autoscalinggroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestRootVolumeOptimizationFlag(t *testing.T) {

b.Build(c)

lc := c.Tasks["LaunchConfiguration/nodes.testcluster.test.com"].(*awstasks.LaunchConfiguration)
lc := c.Tasks["LaunchTemplate/nodes.testcluster.test.com"].(*awstasks.LaunchTemplate)

if *lc.RootVolumeOptimization == false {
t.Fatalf("RootVolumeOptimization was expected to be true, but was false")
Expand Down
Loading

0 comments on commit 54d4a81

Please sign in to comment.