Skip to content

Commit 8a7ef1e

Browse files
authored
Merge pull request #1627 from hunchback/k8s-configmap-secret
k8s: add configmap and secret objects
2 parents 038573c + e0b93bf commit 8a7ef1e

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
@@ -186,6 +186,10 @@ func TestK8sClusterNode(t *testing.T) {
186186
testNodeCreation(t, nil, nil, k8s.Manager, "cluster", k8s.ClusterName)
187187
}
188188

189+
func TestK8sConfigMapNode(t *testing.T) {
190+
testNodeCreationFromConfig(t, k8s.Manager, "configmap", objName+"-configmap")
191+
}
192+
189193
func TestK8sContainerNode(t *testing.T) {
190194
testNodeCreationFromConfig(t, k8s.Manager, "container", objName+"-container", "Image", "Pod")
191195
}
@@ -246,6 +250,10 @@ func TestK8sReplicationControllerNode(t *testing.T) {
246250
testNodeCreationFromConfig(t, k8s.Manager, "replicationcontroller", objName+"-replicationcontroller")
247251
}
248252

253+
func TestK8sSecretNode(t *testing.T) {
254+
testNodeCreationFromConfig(t, k8s.Manager, "secret", objName+"-secret", "Type")
255+
}
256+
249257
func TestK8sServiceNode(t *testing.T) {
250258
testNodeCreationFromConfig(t, k8s.Manager, "service", objName+"-service", "Ports", "ClusterIP", "ServiceType", "SessionAffinity", "LoadBalancerIP", "ExternalName")
251259
}

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
@@ -62,6 +62,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
6262

6363
subprobeHandlers := map[string]SubprobeHandler{
6464
"cluster": newClusterProbe,
65+
"configmap": newConfigMapProbe,
6566
"container": newContainerProbe,
6667
"cronjob": newCronJobProbe,
6768
"daemonset": newDaemonSetProbe,
@@ -77,6 +78,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
7778
"pod": newPodProbe,
7879
"replicaset": newReplicaSetProbe,
7980
"replicationcontroller": newReplicationControllerProbe,
81+
"secret": newSecretProbe,
8082
"service": newServiceProbe,
8183
"statefulset": newStatefulSetProbe,
8284
"storageclass": newStorageClassProbe,
@@ -111,6 +113,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
111113
)
112114

113115
probe.AppendNamespaceLinkers(
116+
"configmap",
114117
"cronjob",
115118
"deployment",
116119
"daemonset",
@@ -121,6 +124,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
121124
"pod",
122125
"replicaset",
123126
"replicationcontroller",
127+
"secret",
124128
"service",
125129
"statefulset",
126130
)

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)