Fargate: Default to cluster name as virtual node name

This commit is contained in:
Onur Filiz
2018-04-30 13:57:44 -07:00
committed by Onur Filiz
parent f6835d9e89
commit cf8af6b360

View File

@@ -76,6 +76,11 @@ func NewCluster(config *ClusterConfig) (*Cluster, error) {
pods: make(map[string]*Pod), pods: make(map[string]*Pod),
} }
// If a node name is not specified, use the Fargate cluster name.
if cluster.nodeName == "" {
cluster.nodeName = cluster.name
}
// Check if the cluster already exists. // Check if the cluster already exists.
err = cluster.describe() err = cluster.describe()
if err != nil { if err != nil {
@@ -83,7 +88,7 @@ func NewCluster(config *ClusterConfig) (*Cluster, error) {
} }
// If not, try to create it. // If not, try to create it.
// This might fail if the role doesn't have the necessary permission. // This might fail if the principal doesn't have the necessary permission.
if cluster.arn == "" { if cluster.arn == "" {
err = cluster.create() err = cluster.create()
if err != nil { if err != nil {
@@ -215,7 +220,7 @@ func (c *Cluster) loadPodState() error {
taskDef := describeTaskDefinitionOutput.TaskDefinition taskDef := describeTaskDefinitionOutput.TaskDefinition
// A pod's tag is stored in its task definition's Family field. // A pod's tag is stored in its task definition's Family field.
tag := *taskDef.Family tag := aws.StringValue(taskDef.Family)
// Rebuild the pod object. // Rebuild the pod object.
// Not all tasks are necessarily pods. Skip tasks that do not have a valid tag. // Not all tasks are necessarily pods. Skip tasks that do not have a valid tag.
@@ -225,22 +230,22 @@ func (c *Cluster) loadPodState() error {
continue continue
} }
pod.uid = k8sTypes.UID(*task.StartedBy) pod.uid = k8sTypes.UID(aws.StringValue(task.StartedBy))
pod.taskDefArn = *task.TaskDefinitionArn pod.taskDefArn = aws.StringValue(task.TaskDefinitionArn)
pod.taskArn = *task.TaskArn pod.taskArn = aws.StringValue(task.TaskArn)
if taskDef.TaskRoleArn != nil { if taskDef.TaskRoleArn != nil {
pod.taskRoleArn = *taskDef.TaskRoleArn pod.taskRoleArn = aws.StringValue(taskDef.TaskRoleArn)
} }
pod.taskStatus = *task.LastStatus pod.taskStatus = aws.StringValue(task.LastStatus)
pod.taskRefreshTime = time.Now() pod.taskRefreshTime = time.Now()
// Rebuild the container objects. // Rebuild the container objects.
for _, cntrDef := range taskDef.ContainerDefinitions { for _, cntrDef := range taskDef.ContainerDefinitions {
cntr, _ := newContainerFromDefinition(cntrDef, task.CreatedAt) cntr, _ := newContainerFromDefinition(cntrDef, task.CreatedAt)
pod.taskCPU += *cntr.definition.Cpu pod.taskCPU += aws.Int64Value(cntr.definition.Cpu)
pod.taskMemory += *cntr.definition.Memory pod.taskMemory += aws.Int64Value(cntr.definition.Memory)
pod.containers[*cntrDef.Name] = cntr pod.containers[aws.StringValue(cntrDef.Name)] = cntr
log.Printf("Found pod %s/%s on cluster %s.", pod.namespace, pod.name, c.name) log.Printf("Found pod %s/%s on cluster %s.", pod.namespace, pod.name, c.name)
} }