Skip to content

Commit

Permalink
Merge pull request #16816 from rifelpet/bastion-lb-dump
Browse files Browse the repository at this point in the history
Discover a bastion load balancer and use it for dumping artifacts
  • Loading branch information
k8s-ci-robot authored Sep 7, 2024
2 parents eac588a + 3f3d0f1 commit aed4c91
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
14 changes: 11 additions & 3 deletions cmd/kops/toolbox_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,18 @@ func RunToolboxDump(ctx context.Context, f commandutils.Factory, out io.Writer,
}

// look for a bastion instance and use it if exists
// Prefer a bastion load balancer if exists
bastionAddress := ""
for _, instance := range d.Instances {
if strings.Contains(instance.Name, "bastion") {
bastionAddress = instance.PublicAddresses[0]
for _, lb := range d.LoadBalancers {
if strings.Contains(lb.Name, "bastion") && lb.DNSName != "" {
bastionAddress = lb.DNSName
}
}
if bastionAddress == "" {
for _, instance := range d.Instances {
if strings.Contains(instance.Name, "bastion") {
bastionAddress = instance.PublicAddresses[0]
}
}
}
dumper := dump.NewLogDumper(bastionAddress, sshConfig, keyRing, options.Dir)
Expand Down
8 changes: 8 additions & 0 deletions pkg/resources/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,14 @@ func DumpELB(op *resources.DumpOperation, r *resources.Resource) error {
data["type"] = TypeLoadBalancer
data["raw"] = r.Obj
op.Dump.Resources = append(op.Dump.Resources, data)

if lb, ok := r.Obj.(elbv2types.LoadBalancer); ok {
op.Dump.LoadBalancers = append(op.Dump.LoadBalancers, &resources.LoadBalancer{
Name: fi.ValueOf(lb.LoadBalancerName),
DNSName: fi.ValueOf(lb.DNSName),
})

}
return nil
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/resources/dumpmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ type Instance struct {
SSHUser string `json:"sshUser,omitempty"`
}

type LoadBalancer struct {
Name string `json:"name,omitempty"`
DNSName string `json:"dnsName,omitempty"`
}

// Subnet is the type for an subnetwork in a dump
type Subnet struct {
ID string `json:"id,omitempty"`
Expand All @@ -38,8 +43,9 @@ type VPC struct {

// Dump is the type for a dump result
type Dump struct {
Resources []interface{} `json:"resources,omitempty"`
Instances []*Instance `json:"instances,omitempty"`
Subnets []*Subnet `json:"subnets,omitempty"`
VPC *VPC `json:"vpc,omitempty"`
Resources []interface{} `json:"resources,omitempty"`
Instances []*Instance `json:"instances,omitempty"`
LoadBalancers []*LoadBalancer `json:"loadBalancers,omitempty"`
Subnets []*Subnet `json:"subnets,omitempty"`
VPC *VPC `json:"vpc,omitempty"`
}

0 comments on commit aed4c91

Please sign in to comment.