Skip to content

Commit

Permalink
Merge pull request #14468 from johngmyers/bastion-nlb
Browse files Browse the repository at this point in the history
Create NLB instead of CLB for bastion
  • Loading branch information
k8s-ci-robot committed Nov 5, 2022
2 parents de45957 + 25b7dc2 commit cdd6fe3
Show file tree
Hide file tree
Showing 35 changed files with 1,587 additions and 1,449 deletions.
3 changes: 3 additions & 0 deletions cloudmock/aws/mockelbv2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package mockelbv2
import (
"sync"

"k8s.io/kops/cloudmock/aws/mockec2"

"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/aws/aws-sdk-go/service/elbv2/elbv2iface"
)
Expand All @@ -28,6 +30,7 @@ type MockELBV2 struct {

mutex sync.Mutex

EC2 *mockec2.MockEC2
LoadBalancers map[string]*loadBalancer
lbCount int
TargetGroups map[string]*targetGroup
Expand Down
18 changes: 15 additions & 3 deletions cloudmock/aws/mockelbv2/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elbv2"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -88,10 +89,17 @@ func (m *MockELBV2) CreateLoadBalancer(request *elbv2.CreateLoadBalancerInput) (
CanonicalHostedZoneId: aws.String("HZ123456"),
}
zones := make([]*elbv2.AvailabilityZone, 0)
vpc := "vpc-1"
for _, subnet := range request.Subnets {
zones = append(zones, &elbv2.AvailabilityZone{
SubnetId: subnet,
})
subnetsOutput, err := m.EC2.DescribeSubnets(&ec2.DescribeSubnetsInput{
SubnetIds: []*string{subnet},
})
if err == nil {
vpc = *subnetsOutput.Subnets[0].VpcId
}
}
for _, subnetMapping := range request.SubnetMappings {
var lbAddrs []*elbv2.LoadBalancerAddress
Expand All @@ -105,12 +113,16 @@ func (m *MockELBV2) CreateLoadBalancer(request *elbv2.CreateLoadBalancerInput) (
SubnetId: subnetMapping.SubnetId,
LoadBalancerAddresses: lbAddrs,
})
subnetsOutput, err := m.EC2.DescribeSubnets(&ec2.DescribeSubnetsInput{
SubnetIds: []*string{subnetMapping.SubnetId},
})
if err == nil {
vpc = *subnetsOutput.Subnets[0].VpcId
}
}
lb.AvailabilityZones = zones

// This is hardcoded because AWS derives it from the subnets above
// But we don'y rely on the NLB's VPC ID at all in awstasks
lb.VpcId = aws.String("vpc-1")
lb.VpcId = aws.String(vpc)

m.lbCount++
arn := fmt.Sprintf("arn:aws-test:elasticloadbalancing:us-test-1:000000000000:loadbalancer/net/%v/%v", aws.StringValue(request.Name), m.lbCount)
Expand Down
6 changes: 5 additions & 1 deletion docs/releases/1.26-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ This is a document to gather the release notes prior to the release.

# Significant changes

* Instance group images can now be dynamically fetched through an AWS SSM Parameter (AWS only).
## AWS only

* Bastions are now fronted by a Network Load Balancer.

* Instance group images can now be dynamically fetched through an AWS SSM Parameter.


# Breaking changes
Expand Down
4 changes: 2 additions & 2 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5604,13 +5604,13 @@ spec:
bastionPublicName:
type: string
idleTimeoutSeconds:
description: IdleTimeoutSeconds is the bastion's Loadbalancer
idle timeout
description: IdleTimeoutSeconds is unused
format: int64
type: integer
loadBalancer:
properties:
additionalSecurityGroups:
description: AdditionalSecurityGroups is unused
items:
type: string
type: array
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/kops/bastion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ package kops
type BastionSpec struct {
// PublicName is the domain name for the bastion load balancer.
PublicName string `json:"publicName,omitempty"`
// IdleTimeoutSeconds is the bastion's load balancer idle timeout.
IdleTimeoutSeconds *int64 `json:"idleTimeoutSeconds,omitempty"`
// LoadBalancer contains settings for the load balancer fronting bastion instances.
LoadBalancer *BastionLoadBalancerSpec `json:"loadBalancer,omitempty"`
}

type BastionLoadBalancerSpec struct {
AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
// Type of load balancer to create, it can be Public or Internal.
Type LoadBalancerType `json:"type,omitempty"`
}
5 changes: 4 additions & 1 deletion pkg/apis/kops/v1alpha2/bastion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package v1alpha2

type BastionSpec struct {
PublicName string `json:"bastionPublicName,omitempty"`
// IdleTimeoutSeconds is the bastion's Loadbalancer idle timeout
// IdleTimeoutSeconds is unused
// +k8s:conversion-gen=false
IdleTimeoutSeconds *int64 `json:"idleTimeoutSeconds,omitempty"`
LoadBalancer *BastionLoadBalancerSpec `json:"loadBalancer,omitempty"`
}

type BastionLoadBalancerSpec struct {
// AdditionalSecurityGroups is unused
// +k8s:conversion-gen=false
AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
// Type of load balancer to create, it can be Public or Internal.
Type LoadBalancerType `json:"type,omitempty"`
Expand Down
6 changes: 2 additions & 4 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.

3 changes: 0 additions & 3 deletions pkg/apis/kops/v1alpha3/bastion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ package v1alpha3
type BastionSpec struct {
// PublicName is the domain name for the bastion load balancer.
PublicName string `json:"publicName,omitempty"`
// IdleTimeoutSeconds is the bastion's load balancer idle timeout.
IdleTimeoutSeconds *int64 `json:"idleTimeoutSeconds,omitempty"`
// LoadBalancer contains settings for the load balancer fronting bastion instances.
LoadBalancer *BastionLoadBalancerSpec `json:"loadBalancer,omitempty"`
}

type BastionLoadBalancerSpec struct {
AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
// Type of load balancer to create, it can be Public or Internal.
Type LoadBalancerType `json:"type,omitempty"`
}
4 changes: 0 additions & 4 deletions pkg/apis/kops/v1alpha3/zz_generated.conversion.go

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

12 changes: 1 addition & 11 deletions pkg/apis/kops/v1alpha3/zz_generated.deepcopy.go

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

7 changes: 0 additions & 7 deletions pkg/apis/kops/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,9 @@ func validateTopology(c *kops.Cluster, topology *kops.TopologySpec, fieldPath *f
}

if topology.Bastion != nil {
bastion := topology.Bastion
if topology.Masters == kops.TopologyPublic || topology.Nodes == kops.TopologyPublic {
allErrs = append(allErrs, field.Forbidden(fieldPath.Child("bastion"), "bastion requires masters and nodes to have private topology"))
}
if bastion.IdleTimeoutSeconds != nil && *bastion.IdleTimeoutSeconds <= 0 {
allErrs = append(allErrs, field.Invalid(fieldPath.Child("bastion", "idleTimeoutSeconds"), *bastion.IdleTimeoutSeconds, "bastion idleTimeoutSeconds should be greater than zero"))
}
if bastion.IdleTimeoutSeconds != nil && *bastion.IdleTimeoutSeconds > 3600 {
allErrs = append(allErrs, field.Invalid(fieldPath.Child("bastion", "idleTimeoutSeconds"), *bastion.IdleTimeoutSeconds, "bastion idleTimeoutSeconds cannot be greater than one hour"))
}
}

if topology.DNS != nil {
Expand Down
12 changes: 1 addition & 11 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.

2 changes: 1 addition & 1 deletion pkg/model/awsmodel/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (b *AutoscalingGroupModelBuilder) buildAutoScalingGroupTask(c *fi.ModelBuil
}

if ig.Spec.Role == kops.InstanceGroupRoleBastion {
t.LoadBalancers = append(t.LoadBalancers, b.LinkToCLB("bastion"))
t.TargetGroups = append(t.TargetGroups, b.LinkToTargetGroup("bastion"))
}
}

Expand Down

0 comments on commit cdd6fe3

Please sign in to comment.