Skip to content

Commit e53c1ee

Browse files
authored
Merge pull request #1243 from hunchback/k8s-ingress-metadata
k8s: add ingress metadata fields
2 parents c0ec658 + 0da6cbe commit e53c1ee

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

tests/k8s_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestK8sDeploymentNode(t *testing.T) {
175175
}
176176

177177
func TestK8sIngressNode(t *testing.T) {
178-
testNodeCreationFromConfig(t, "ingress", objName+"-ingress")
178+
testNodeCreationFromConfig(t, "ingress", objName+"-ingress", "Backend", "TLS", "Rules")
179179
}
180180

181181
func TestK8sJobNode(t *testing.T) {

topology/probes/k8s/ingress.go

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

4242
func dumpIngress(ingress *v1beta1.Ingress) string {
43-
return fmt.Sprintf("ingress{Name: %s}", ingress.GetName())
43+
return fmt.Sprintf("ingress{Namespace: %s, Name: %s}", ingress.Namespace, ingress.Name)
4444
}
4545

4646
func (p *ingressProbe) newMetadata(ingress *v1beta1.Ingress) graph.Metadata {
47-
return newMetadata("ingress", ingress.Namespace, ingress.GetName(), ingress)
47+
m := newMetadata("ingress", ingress.Namespace, ingress.Name, ingress)
48+
m.SetFieldAndNormalize("Backend", ingress.Spec.Backend)
49+
m.SetFieldAndNormalize("TLS", ingress.Spec.TLS)
50+
m.SetFieldAndNormalize("Rules", ingress.Spec.Rules)
51+
return m
4852
}
4953

5054
func ingressUID(ingress *v1beta1.Ingress) graph.Identifier {
@@ -66,8 +70,8 @@ func (p *ingressProbe) OnUpdate(oldObj, newObj interface{}) {
6670
p.graph.Lock()
6771
defer p.graph.Unlock()
6872

69-
if nsNode := p.graph.GetNode(ingressUID(ingress)); nsNode != nil {
70-
addMetadata(p.graph, nsNode, ingress)
73+
if ingressNode := p.graph.GetNode(ingressUID(ingress)); ingressNode != nil {
74+
addMetadata(p.graph, ingressNode, ingress)
7175
logging.GetLogger().Debugf("Updated %s", dumpIngress(ingress))
7276
}
7377
}
@@ -78,8 +82,8 @@ func (p *ingressProbe) OnDelete(obj interface{}) {
7882
p.graph.Lock()
7983
defer p.graph.Unlock()
8084

81-
if nsNode := p.graph.GetNode(ingressUID(ingress)); nsNode != nil {
82-
p.graph.DelNode(nsNode)
85+
if ingressNode := p.graph.GetNode(ingressUID(ingress)); ingressNode != nil {
86+
p.graph.DelNode(ingressNode)
8387
logging.GetLogger().Debugf("Deleted %s", dumpIngress(ingress))
8488
}
8589
}

0 commit comments

Comments
 (0)