Skip to content

Commit 6f10bfe

Browse files
authored
Fix k8s tag propagation and controller-uid detection (#656)
* Fix k8s tag propagation and controller-uid detection * Apply suggested changes to delete task.Tags
1 parent bb76827 commit 6f10bfe

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

cmd/create/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func (o *Options) Run(cmd *cobra.Command, args []string, cloud *common.Cloud) er
7070
}
7171
}
7272

73+
cloud.Tags = o.Tags
74+
7375
script := o.Script
7476
if !strings.HasPrefix(script, "#!") {
7577
script = "#!/bin/sh\n" + script

iterative/kubernetes/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func ResourceMachineCreate(ctx context.Context, d *terraform_schema.ResourceData
140140
log.Printf("[INFO] Submitted new job: %#v", out)
141141

142142
// Get the controller unique identifier for the job, so we can easily find the pods it creates.
143-
waitSelector := fmt.Sprintf("controller-uid=%s", out.GetObjectMeta().GetLabels()["controller-uid"])
143+
waitSelector := fmt.Sprintf("controller-uid=%s", out.Spec.Selector.MatchLabels["controller-uid"])
144144

145145
// Wait for the job to satisfy the readiness condition specified through kubernetes_readiness_command.
146146
return terraform_resource.Retry(d.Timeout(terraform_schema.TimeoutCreate), func() *terraform_resource.RetryError {
@@ -414,7 +414,7 @@ func ResourceMachineLogs(ctx context.Context, d *terraform_schema.ResourceData,
414414
}
415415

416416
pods, err := conn.CoreV1().Pods(namespace).List(ctx, kubernetes_meta.ListOptions{
417-
LabelSelector: fmt.Sprintf("controller-uid=%s", job.GetObjectMeta().GetLabels()["controller-uid"]),
417+
LabelSelector: fmt.Sprintf("controller-uid=%s", job.Spec.Selector.MatchLabels["controller-uid"]),
418418
})
419419
if err != nil {
420420
return "", err

task/aws/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func List(ctx context.Context, cloud common.Cloud) ([]common.Identifier, error)
2323
}
2424

2525
func New(ctx context.Context, cloud common.Cloud, identifier common.Identifier, task common.Task) (*Task, error) {
26-
client, err := client.New(ctx, cloud, task.Tags)
26+
client, err := client.New(ctx, cloud, cloud.Tags)
2727
if err != nil {
2828
return nil, err
2929
}

task/az/resources/resource_virtual_machine_scale_set.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func NewVirtualMachineScaleSet(client *client.Client, identifier common.Identifi
2828
v.Attributes.Size = task.Size
2929
v.Attributes.Environment = task.Environment
3030
v.Attributes.Firewall = task.Firewall
31-
v.Attributes.Tags = task.Tags
3231
v.Attributes.Parallelism = &task.Parallelism
3332
v.Attributes.Spot = float64(task.Spot)
3433
v.Dependencies.ResourceGroup = resourceGroup
@@ -46,7 +45,6 @@ type VirtualMachineScaleSet struct {
4645
Size common.Size
4746
Environment common.Environment
4847
Firewall common.Firewall
49-
Tags map[string]string
5048
Parallelism *uint16
5149
Spot float64
5250
Addresses []net.IP

task/az/task.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func List(ctx context.Context, cloud common.Cloud) ([]common.Identifier, error)
2323
}
2424

2525
func New(ctx context.Context, cloud common.Cloud, identifier common.Identifier, task common.Task) (*Task, error) {
26-
client, err := client.New(ctx, cloud, task.Tags)
26+
client, err := client.New(ctx, cloud, cloud.Tags)
2727
if err != nil {
2828
return nil, err
2929
}
@@ -137,10 +137,10 @@ func (t *Task) Create(ctx context.Context) error {
137137
}}
138138
if t.Attributes.Environment.Directory != "" {
139139
steps = append(steps, common.Step{
140-
Description: "Uploading Directory...",
141-
Action: func(ctx context.Context) error {
140+
Description: "Uploading Directory...",
141+
Action: func(ctx context.Context) error {
142142
return t.Push(ctx, t.Attributes.Environment.Directory)
143-
},
143+
},
144144
})
145145
}
146146
steps = append(steps, common.Step{
@@ -201,8 +201,8 @@ func (t *Task) Delete(ctx context.Context) error {
201201
if t.Read(ctx) == nil {
202202
if t.Attributes.Environment.DirectoryOut != "" {
203203
steps = []common.Step{{
204-
Description: "Downloading Directory...",
205-
Action: func(ctx context.Context)error {
204+
Description: "Downloading Directory...",
205+
Action: func(ctx context.Context) error {
206206
err := t.Pull(ctx, t.Attributes.Environment.Directory, t.Attributes.Environment.DirectoryOut)
207207
if err != nil && err != common.NotFoundError {
208208
return err
@@ -211,36 +211,37 @@ func (t *Task) Delete(ctx context.Context) error {
211211
},
212212
}, {
213213
Description: "Emptying Bucket...",
214-
Action: func(ctx context.Context)error {
214+
Action: func(ctx context.Context) error {
215215
err := machine.Delete(ctx, t.DataSources.Credentials.Resource["RCLONE_REMOTE"])
216216
if err != nil && err != common.NotFoundError {
217217
return err
218218
}
219219
return nil
220220
},
221221
}}
222-
}}
222+
}
223+
}
223224
steps = append(steps, []common.Step{{
224225
Description: "Deleting VirtualMachineScaleSet...",
225-
Action: t.Resources.VirtualMachineScaleSet.Delete,
226-
},{
226+
Action: t.Resources.VirtualMachineScaleSet.Delete,
227+
}, {
227228
Description: "Deleting Subnet...",
228-
Action: t.Resources.Subnet.Delete,
229+
Action: t.Resources.Subnet.Delete,
229230
}, {
230231
Description: "Deleting SecurityGroup...",
231-
Action: t.Resources.SecurityGroup.Delete,
232+
Action: t.Resources.SecurityGroup.Delete,
232233
}, {
233234
Description: "Deleting VirtualNetwork...",
234-
Action: t.Resources.VirtualNetwork.Delete,
235+
Action: t.Resources.VirtualNetwork.Delete,
235236
}, {
236237
Description: "Deleting BlobContainer...",
237-
Action: t.Resources.BlobContainer.Delete,
238+
Action: t.Resources.BlobContainer.Delete,
238239
}, {
239240
Description: "Deleting StorageAccount...",
240-
Action: t.Resources.StorageAccount.Delete,
241+
Action: t.Resources.StorageAccount.Delete,
241242
}, {
242243
Description: "Deleting ResourceGroup...",
243-
Action: t.Resources.ResourceGroup.Delete,
244+
Action: t.Resources.ResourceGroup.Delete,
244245
}}...)
245246
if err := common.RunSteps(ctx, steps); err != nil {
246247
return err

task/common/values.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type Task struct {
5050
PermissionSet string
5151
Spot Spot
5252
Parallelism uint16
53-
Tags map[string]string // Deprecated
5453

5554
Addresses []net.IP
5655
Status Status

task/gcp/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func List(ctx context.Context, cloud common.Cloud) ([]common.Identifier, error)
2323
}
2424

2525
func New(ctx context.Context, cloud common.Cloud, identifier common.Identifier, task common.Task) (*Task, error) {
26-
client, err := client.New(ctx, cloud, task.Tags)
26+
client, err := client.New(ctx, cloud, cloud.Tags)
2727
if err != nil {
2828
return nil, err
2929
}

task/k8s/resources/resource_job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (j *Job) Delete(ctx context.Context) error {
337337

338338
func (j *Job) Logs(ctx context.Context) ([]string, error) {
339339
pods, err := j.Client.Services.Core.Pods(j.Client.Namespace).List(ctx, kubernetes_meta.ListOptions{
340-
LabelSelector: fmt.Sprintf("controller-uid=%s", j.Resource.GetObjectMeta().GetLabels()["controller-uid"]),
340+
LabelSelector: fmt.Sprintf("controller-uid=%s", j.Resource.Spec.Selector.MatchLabels["controller-uid"]),
341341
})
342342
if err != nil {
343343
return nil, err

task/k8s/task.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func List(ctx context.Context, cloud common.Cloud) ([]common.Identifier, error)
3434
}
3535

3636
func New(ctx context.Context, cloud common.Cloud, identifier common.Identifier, task common.Task) (*Task, error) {
37-
client, err := client.New(ctx, cloud, task.Tags)
37+
client, err := client.New(ctx, cloud, cloud.Tags)
3838
if err != nil {
3939
return nil, err
4040
}
@@ -226,7 +226,7 @@ func (t *Task) Delete(ctx context.Context) error {
226226
}
227227

228228
func (t *Task) Push(ctx context.Context, source string) error {
229-
waitSelector := fmt.Sprintf("controller-uid=%s", t.Resources.Job.Resource.GetObjectMeta().GetLabels()["controller-uid"])
229+
waitSelector := fmt.Sprintf("controller-uid=%s", t.Resources.Job.Resource.Spec.Selector.MatchLabels["controller-uid"])
230230
pod, err := resources.WaitForPods(ctx, t.Client, 1*time.Second, t.Client.Cloud.Timeouts.Create, t.Client.Namespace, waitSelector)
231231
if err != nil {
232232
return err
@@ -241,7 +241,7 @@ func (t *Task) Push(ctx context.Context, source string) error {
241241
}
242242

243243
func (t *Task) Pull(ctx context.Context, destination, include string) error {
244-
waitSelector := fmt.Sprintf("controller-uid=%s", t.Resources.Job.Resource.GetObjectMeta().GetLabels()["controller-uid"])
244+
waitSelector := fmt.Sprintf("controller-uid=%s", t.Resources.Job.Resource.Spec.Selector.MatchLabels["controller-uid"])
245245
pod, err := resources.WaitForPods(ctx, t.Client, 1*time.Second, t.Client.Cloud.Timeouts.Delete, t.Client.Namespace, waitSelector)
246246
if err != nil {
247247
return err

0 commit comments

Comments
 (0)