This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
forked from kubernetes-retired/kube-aws
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing Name and ControllerHost in
status
and up
commands
- Loading branch information
Showing
9 changed files
with
216 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cluster | ||
|
||
import ( | ||
"fmt" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/cloudformation" | ||
"github.com/aws/aws-sdk-go/service/elb" | ||
) | ||
|
||
type ClusterDescriber interface { | ||
Info() (*Info, error) | ||
} | ||
|
||
type clusterDescriberImpl struct { | ||
session *session.Session | ||
clusterName string | ||
stackName string | ||
} | ||
|
||
func NewClusterDescriber(clusterName string, stackName string, session *session.Session) ClusterDescriber { | ||
return clusterDescriberImpl{ | ||
clusterName: clusterName, | ||
stackName: stackName, | ||
session: session, | ||
} | ||
} | ||
|
||
func (c clusterDescriberImpl) Info() (*Info, error) { | ||
var elbName string | ||
{ | ||
cfSvc := cloudformation.New(c.session) | ||
resp, err := cfSvc.DescribeStackResource( | ||
&cloudformation.DescribeStackResourceInput{ | ||
LogicalResourceId: aws.String("ElbAPIServer"), | ||
StackName: aws.String(c.stackName), | ||
}, | ||
) | ||
if err != nil { | ||
errmsg := "unable to get public IP of controller instance:\n" + err.Error() | ||
return nil, fmt.Errorf(errmsg) | ||
} | ||
elbName = *resp.StackResourceDetail.PhysicalResourceId | ||
} | ||
|
||
elbSvc := elb.New(c.session) | ||
|
||
var info Info | ||
{ | ||
resp, err := elbSvc.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{ | ||
LoadBalancerNames: []*string{ | ||
aws.String(elbName), | ||
}, | ||
PageSize: aws.Int64(2), | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("error describing load balancer %s: %v", elbName, err) | ||
} | ||
if len(resp.LoadBalancerDescriptions) == 0 { | ||
return nil, fmt.Errorf("could not find a load balancer with name %s", elbName) | ||
} | ||
if len(resp.LoadBalancerDescriptions) > 1 { | ||
return nil, fmt.Errorf("found multiple load balancers with name %s: %v", elbName, resp) | ||
} | ||
|
||
info.Name = c.clusterName | ||
info.ControllerHost = *resp.LoadBalancerDescriptions[0].DNSName | ||
} | ||
return &info, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cluster | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"text/tabwriter" | ||
) | ||
|
||
type Info struct { | ||
Name string | ||
ControllerHost string | ||
} | ||
|
||
func (c *Info) String() string { | ||
buf := new(bytes.Buffer) | ||
w := new(tabwriter.Writer) | ||
w.Init(buf, 0, 8, 0, '\t', 0) | ||
|
||
fmt.Fprintf(w, "Cluster Name:\t%s\n", c.Name) | ||
fmt.Fprintf(w, "Controller DNS Name:\t%s\n", c.ControllerHost) | ||
|
||
w.Flush() | ||
return buf.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package root | ||
|
||
import ( | ||
"fmt" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/cloudformation" | ||
"github.com/coreos/kube-aws/core/controlplane/cluster" | ||
"github.com/coreos/kube-aws/core/root/config" | ||
) | ||
|
||
type Info struct { | ||
ControlPlane *cluster.Info | ||
} | ||
|
||
func (i *Info) String() string { | ||
return i.ControlPlane.String() | ||
} | ||
|
||
type ClusterDescriber interface { | ||
Info() (*Info, error) | ||
} | ||
|
||
type clusterDescriberImpl struct { | ||
session *session.Session | ||
clusterName string | ||
stackName string | ||
} | ||
|
||
func ClusterDescriberFromFile(configPath string) (ClusterDescriber, error) { | ||
config, err := config.ConfigFromFile(configPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
awsConfig := aws.NewConfig(). | ||
WithRegion(config.Region). | ||
WithCredentialsChainVerboseErrors(true) | ||
|
||
session, err := session.NewSession(awsConfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to establish aws session: %v", err) | ||
} | ||
|
||
return NewClusterDescriber(config.ClusterName, config.ClusterName, session), nil | ||
} | ||
|
||
func NewClusterDescriber(clusterName string, stackName string, session *session.Session) ClusterDescriber { | ||
return clusterDescriberImpl{ | ||
clusterName: clusterName, | ||
stackName: stackName, | ||
session: session, | ||
} | ||
} | ||
|
||
func (c clusterDescriberImpl) Info() (*Info, error) { | ||
cfSvc := cloudformation.New(c.session) | ||
|
||
var cpStackName string | ||
{ | ||
resp, err := cfSvc.DescribeStackResource( | ||
&cloudformation.DescribeStackResourceInput{ | ||
LogicalResourceId: aws.String("Controlplane"), | ||
StackName: aws.String(c.stackName), | ||
}, | ||
) | ||
if err != nil { | ||
errmsg := "unable to get nested stack for control-plane:\n" + err.Error() | ||
return nil, fmt.Errorf(errmsg) | ||
} | ||
cpStackName = *resp.StackResourceDetail.PhysicalResourceId | ||
} | ||
|
||
var info Info | ||
{ | ||
resp, err := cfSvc.DescribeStacks(&cloudformation.DescribeStacksInput{ | ||
StackName: aws.String(cpStackName), | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("error describing stack %s: %v", cpStackName, err) | ||
} | ||
if len(resp.Stacks) == 0 { | ||
return nil, fmt.Errorf("could not find a stack with name %s", cpStackName) | ||
} | ||
if len(resp.Stacks) > 1 { | ||
return nil, fmt.Errorf("found multiple load balancers with name %s: %v", cpStackName, resp) | ||
} | ||
|
||
cpDescriber := cluster.NewClusterDescriber(c.clusterName, cpStackName, c.session) | ||
|
||
cpInfo, err := cpDescriber.Info() | ||
|
||
info.ControlPlane = cpInfo | ||
} | ||
|
||
return &info, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.