Skip to content

Commit e0b93bf

Browse files
committed
k8s: add configmap and secret objects
1 parent 1a67d0c commit e0b93bf

File tree

10 files changed

+135
-0
lines changed

10 files changed

+135
-0
lines changed

etc/skydive.yml.default

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ analyzer:
128128
# if list is empty then will resolve to all existing (sub) probes.
129129
probes:
130130
- cluster
131+
- configmap
131132
- container
132133
- cronjob
133134
- deployment
@@ -142,6 +143,7 @@ analyzer:
142143
- pod
143144
- replicaset
144145
- replicationcontroller
146+
- secret
145147
- service
146148
- statefulset
147149
- storageclass

statics/img/configmap.png

33.5 KB
Loading

statics/img/secret.png

16.2 KB
Loading

statics/js/components/layout.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var nodeImgMap = setupFixedImages({
2929
"default": "intf",
3030
// k8s
3131
"cluster": "cluster",
32+
"configmap": "configmap",
3233
"container": "container",
3334
"cronjob": "cronjob",
3435
"daemonset": "daemonset",
@@ -44,6 +45,7 @@ var nodeImgMap = setupFixedImages({
4445
"namespace": "ns",
4546
"replicaset": "replicaset",
4647
"replicationcontroller": "replicationcontroller",
48+
"secret": "secret",
4749
"service": "service",
4850
"statefulset": "statefulset",
4951
"storageclass": "storageclass",

tests/k8s/configmap.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: skydive-test-configmap
5+
namespace: default
6+
data:
7+
log_level: INFO

tests/k8s/secret.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: skydive-test-secret
5+
namespace: default
6+
type: Opaque
7+
data:
8+
# echo -n 'admin' | base64
9+
# YWRtaW4=
10+
username: YWRtaW4=
11+
password: YWRtaW4=

tests/k8s_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ func TestK8sClusterNode(t *testing.T) {
191191
testNodeCreation(t, nil, nil, k8s.Manager, "cluster", k8s.ClusterName)
192192
}
193193

194+
func TestK8sConfigMapNode(t *testing.T) {
195+
testNodeCreationFromConfig(t, k8s.Manager, "configmap", objName+"-configmap")
196+
}
197+
194198
func TestK8sContainerNode(t *testing.T) {
195199
testNodeCreationFromConfig(t, k8s.Manager, "container", objName+"-container", "Image", "Pod")
196200
}
@@ -251,6 +255,10 @@ func TestK8sReplicationControllerNode(t *testing.T) {
251255
testNodeCreationFromConfig(t, k8s.Manager, "replicationcontroller", objName+"-replicationcontroller")
252256
}
253257

258+
func TestK8sSecretNode(t *testing.T) {
259+
testNodeCreationFromConfig(t, k8s.Manager, "secret", objName+"-secret", "Type")
260+
}
261+
254262
func TestK8sServiceNode(t *testing.T) {
255263
testNodeCreationFromConfig(t, k8s.Manager, "service", objName+"-service", "Ports", "ClusterIP", "ServiceType", "SessionAffinity", "LoadBalancerIP", "ExternalName")
256264
}

topology/probes/k8s/configmap.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2018 IBM, Inc.
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
*/
22+
23+
package k8s
24+
25+
import (
26+
"fmt"
27+
28+
"github.com/skydive-project/skydive/graffiti/graph"
29+
30+
"k8s.io/api/core/v1"
31+
"k8s.io/client-go/kubernetes"
32+
)
33+
34+
type configMapHandler struct {
35+
}
36+
37+
func (h *configMapHandler) Dump(obj interface{}) string {
38+
cm := obj.(*v1.ConfigMap)
39+
return fmt.Sprintf("configmap{Namespace: %s, Name: %s}", cm.Namespace, cm.Name)
40+
}
41+
42+
func (h *configMapHandler) Map(obj interface{}) (graph.Identifier, graph.Metadata) {
43+
cm := obj.(*v1.ConfigMap)
44+
m := NewMetadataFields(&cm.ObjectMeta)
45+
return graph.Identifier(cm.GetUID()), NewMetadata(Manager, "configmap", m, cm, cm.Name)
46+
}
47+
48+
func newConfigMapProbe(client interface{}, g *graph.Graph) Subprobe {
49+
return NewResourceCache(client.(*kubernetes.Clientset).CoreV1().RESTClient(), &v1.ConfigMap{}, "configmaps", g, &configMapHandler{})
50+
}

topology/probes/k8s/k8s.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
6767

6868
subprobeHandlers := map[string]SubprobeHandler{
6969
"cluster": newClusterProbe,
70+
"configmap": newConfigMapProbe,
7071
"container": newContainerProbe,
7172
"cronjob": newCronJobProbe,
7273
"daemonset": newDaemonSetProbe,
@@ -82,6 +83,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
8283
"pod": newPodProbe,
8384
"replicaset": newReplicaSetProbe,
8485
"replicationcontroller": newReplicationControllerProbe,
86+
"secret": newSecretProbe,
8587
"service": newServiceProbe,
8688
"statefulset": newStatefulSetProbe,
8789
"storageclass": newStorageClassProbe,
@@ -116,6 +118,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
116118
)
117119

118120
probe.AppendNamespaceLinkers(
121+
"configmap",
119122
"cronjob",
120123
"deployment",
121124
"daemonset",
@@ -126,6 +129,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
126129
"pod",
127130
"replicaset",
128131
"replicationcontroller",
132+
"secret",
129133
"service",
130134
"statefulset",
131135
)

topology/probes/k8s/secret.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2018 IBM, Inc.
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
*/
22+
23+
package k8s
24+
25+
import (
26+
"fmt"
27+
28+
"github.com/skydive-project/skydive/graffiti/graph"
29+
30+
"k8s.io/api/core/v1"
31+
"k8s.io/client-go/kubernetes"
32+
)
33+
34+
type secretHandler struct {
35+
}
36+
37+
func (h *secretHandler) Dump(obj interface{}) string {
38+
secret := obj.(*v1.Secret)
39+
return fmt.Sprintf("secret{Namespace: %s, Name: %s}", secret.Namespace, secret.Name)
40+
}
41+
42+
func (h *secretHandler) Map(obj interface{}) (graph.Identifier, graph.Metadata) {
43+
secret := obj.(*v1.Secret)
44+
m := NewMetadataFields(&secret.ObjectMeta)
45+
m.SetField("Type", secret.Type)
46+
return graph.Identifier(secret.GetUID()), NewMetadata(Manager, "secret", m, secret, secret.Name)
47+
}
48+
49+
func newSecretProbe(client interface{}, g *graph.Graph) Subprobe {
50+
return NewResourceCache(client.(*kubernetes.Clientset).CoreV1().RESTClient(), &v1.Secret{}, "secrets", g, &secretHandler{})
51+
}

0 commit comments

Comments
 (0)