Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable task role #2

Merged
merged 1 commit into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions providers/aws/fargate/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ func (c *Cluster) loadPodState() error {
pod.uid = k8sTypes.UID(*task.StartedBy)
pod.taskDefArn = *task.TaskDefinitionArn
pod.taskArn = *task.TaskArn
if taskDef.TaskRoleArn != nil {
pod.taskRoleArn = *taskDef.TaskRoleArn
}
pod.taskStatus = *task.LastStatus
pod.taskRefreshTime = time.Now()

Expand Down
22 changes: 19 additions & 3 deletions providers/aws/fargate/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (

// Reason used for task state changes.
taskGenericReason = "Initiated by user"

// Annotation to configure the task role.
taskRoleAnnotation = "iam.amazonaws.com/role"
)

// Pod is the representation of a Kubernetes pod in Fargate.
Expand All @@ -46,6 +49,7 @@ type Pod struct {
cluster *Cluster
taskDefArn string
taskArn string
taskRoleArn string
taskStatus string
taskRefreshTime time.Time
taskCPU int64
Expand Down Expand Up @@ -104,6 +108,11 @@ func NewPod(cluster *Cluster, pod *corev1.Pod) (*Pod, error) {
taskDef.Cpu = aws.String(strconv.Itoa(int(fgPod.taskCPU)))
taskDef.Memory = aws.String(strconv.Itoa(int(fgPod.taskMemory)))

if val, ok := pod.Annotations[taskRoleAnnotation]; ok {
taskDef.TaskRoleArn = aws.String(val)
fgPod.taskRoleArn = *taskDef.TaskRoleArn
}

// Register the task definition with Fargate.
log.Printf("RegisterTaskDefinition input:%+v", taskDef)
output, err := api.RegisterTaskDefinition(taskDef)
Expand Down Expand Up @@ -372,15 +381,22 @@ func (pod *Pod) getSpec(task *ecs.Task) (*corev1.Pod, error) {
containers = append(containers, cntr)
}

annotations := make(map[string]string)

if pod.taskRoleArn != "" {
annotations[taskRoleAnnotation] = pod.taskRoleArn
}

podSpec := corev1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: pod.namespace,
Name: pod.name,
UID: pod.uid,
Namespace: pod.namespace,
Name: pod.name,
UID: pod.uid,
Annotations: annotations,
},
Spec: corev1.PodSpec{
NodeName: pod.cluster.nodeName,
Expand Down