Skip to content

Commit 259369b

Browse files
authored
Merge pull request #1242 from hunchback/k8s-job-metadata
k8s: add job metadata fields
2 parents e53c1ee + 8a448a1 commit 259369b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

tests/k8s_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func TestK8sIngressNode(t *testing.T) {
179179
}
180180

181181
func TestK8sJobNode(t *testing.T) {
182-
testNodeCreationFromConfig(t, "job", objName+"-job")
182+
testNodeCreationFromConfig(t, "job", objName+"-job", "Parallelism", "Completions", "Active", "Succeeded", "Failed")
183183
}
184184

185185
func TestK8sNamespaceNode(t *testing.T) {

topology/probes/k8s/job.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ type jobProbe struct {
4040
}
4141

4242
func dumpJob(job *batchv1.Job) string {
43-
return fmt.Sprintf("job{Name: %s}", job.GetName())
43+
return fmt.Sprintf("job{Namespace: %s, Name: %s}", job.Namespace, job.Name)
4444
}
4545

4646
func (p *jobProbe) newMetadata(job *batchv1.Job) graph.Metadata {
47-
return newMetadata("job", job.Namespace, job.GetName(), job)
47+
m := newMetadata("job", job.Namespace, job.Name, job)
48+
m.SetField("Parallelism", job.Spec.Parallelism)
49+
m.SetField("Completions", job.Spec.Completions)
50+
m.SetField("Active", job.Status.Active)
51+
m.SetField("Succeeded", job.Status.Succeeded)
52+
m.SetField("Failed", job.Status.Failed)
53+
return m
4854
}
4955

5056
func jobUID(job *batchv1.Job) graph.Identifier {
@@ -66,8 +72,8 @@ func (p *jobProbe) OnUpdate(oldObj, newObj interface{}) {
6672
p.graph.Lock()
6773
defer p.graph.Unlock()
6874

69-
if node := p.graph.GetNode(jobUID(job)); node != nil {
70-
addMetadata(p.graph, node, job)
75+
if jobNode := p.graph.GetNode(jobUID(job)); jobNode != nil {
76+
addMetadata(p.graph, jobNode, job)
7177
logging.GetLogger().Debugf("Updated %s", dumpJob(job))
7278
}
7379
}
@@ -78,8 +84,8 @@ func (p *jobProbe) OnDelete(obj interface{}) {
7884
p.graph.Lock()
7985
defer p.graph.Unlock()
8086

81-
if node := p.graph.GetNode(jobUID(job)); node != nil {
82-
p.graph.DelNode(node)
87+
if jobNode := p.graph.GetNode(jobUID(job)); jobNode != nil {
88+
p.graph.DelNode(jobNode)
8389
logging.GetLogger().Debugf("Deleted %s", dumpJob(job))
8490
}
8591
}

0 commit comments

Comments
 (0)