Skip to content

Commit 930ad02

Browse files
committed
add labels to legacy remote runner
1 parent ffe7dbc commit 930ad02

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

lib/k8s/environment/environment.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func (m *Environment) validateRequiredChainLinkLabels() error {
263263
}
264264

265265
for _, child := range *children {
266+
// most of our workloads are Helm charts
266267
if h, ok := child.(cdk8s.Helm); ok {
267268
for _, ao := range *h.ApiObjects() {
268269
switch *ao.Kind() {
@@ -276,6 +277,19 @@ func (m *Environment) validateRequiredChainLinkLabels() error {
276277
}
277278
}
278279
}
280+
// but legacy runners have no Helm charts, but are programmatically defined as KubeJobs
281+
if j, ok := child.(k8s.KubeJob); ok {
282+
// but secrets or role bindings can also be cast to KubeJob, so we need to check if kind is Job
283+
if j.Kind() == nil || *j.Kind() != "Job" {
284+
continue
285+
}
286+
for _, l := range requiredChainLinkWorkloadLabels {
287+
maybeLabel := j.Metadata().GetLabel(&l)
288+
if maybeLabel == nil {
289+
missingWorkloadLabels[*j.Name()] = append(missingWorkloadLabels[*j.Name()], l)
290+
}
291+
}
292+
}
279293
}
280294

281295
if len(missingWorkloadLabels) > 0 {
@@ -380,25 +394,7 @@ func (m *Environment) AddChart(f func(root cdk8s.Chart) ConnectedChart) *Environ
380394
}
381395
config.JSIIGlobalMu.Lock()
382396
defer config.JSIIGlobalMu.Unlock()
383-
chart := f(m.root)
384-
385-
h := cdk8s.NewHelm(m.root, ptr.Ptr(chart.GetName()), &cdk8s.HelmProps{
386-
Chart: ptr.Ptr(chart.GetPath()),
387-
HelmFlags: &[]*string{
388-
ptr.Ptr("--namespace"),
389-
ptr.Ptr(m.Cfg.Namespace),
390-
},
391-
ReleaseName: ptr.Ptr(chart.GetName()),
392-
Values: chart.GetValues(),
393-
})
394-
395-
componentLabels, err := getComponentLabels(m.Cfg.WorkloadLabels, chart.GetLabels())
396-
if err != nil {
397-
m.err = err
398-
}
399-
400-
addRequiredChainLinkLabels(h, componentLabels)
401-
m.Charts = append(m.Charts, chart)
397+
m.Charts = append(m.Charts, f(m.root))
402398
return m
403399
}
404400

lib/k8s/environment/runner.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,30 @@ func (m Chart) ExportData(e *Environment) error {
5151
}
5252

5353
func (m Chart) GetLabels() map[string]string {
54-
return map[string]string{
55-
"chain.link/component": "k8s-test-runner-legacy",
54+
if m.GetProps() == nil {
55+
return nil
5656
}
57+
58+
if props, ok := m.GetProps().(*Props); ok {
59+
if props == nil {
60+
return nil
61+
}
62+
labels := make(map[string]string)
63+
for k, v := range *props.Labels {
64+
if v == nil {
65+
continue
66+
}
67+
labels[k] = *v
68+
}
69+
}
70+
71+
return nil
5772
}
5873

5974
func NewRunner(props *Props) func(root cdk8s.Chart) ConnectedChart {
6075
return func(root cdk8s.Chart) ConnectedChart {
76+
labels := *props.Labels
77+
labels["chain.link/component"] = ptr.Ptr("k8s-test-runner-legacy")
6178
c := &Chart{
6279
Props: props,
6380
}
@@ -80,6 +97,7 @@ func NewRunner(props *Props) func(root cdk8s.Chart) ConnectedChart {
8097
func DataFromRunner(props *Props) func(root cdk8s.Chart) ConnectedChart {
8198
labels := *props.Labels
8299
labels["app"] = ptr.Ptr("runner-data")
100+
labels["chain.link/component"] = ptr.Ptr("k8s-test-runner-data-legacy")
83101
return func(root cdk8s.Chart) ConnectedChart {
84102
c := &Chart{
85103
Props: props,
@@ -264,7 +282,8 @@ func job(chart cdk8s.Chart, props *Props) {
264282
ptr.Ptr(fmt.Sprintf("%s-job", props.BaseName)),
265283
&k8s.KubeJobProps{
266284
Metadata: &k8s.ObjectMeta{
267-
Name: ptr.Ptr(props.BaseName),
285+
Name: ptr.Ptr(props.BaseName),
286+
Labels: props.Labels,
268287
},
269288
Spec: &k8s.JobSpec{
270289
Template: &k8s.PodTemplateSpec{

0 commit comments

Comments
 (0)