Skip to content

Commit

Permalink
k8s: add configmap and secret objects
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchback committed Jan 28, 2019
1 parent 1a67d0c commit e0b93bf
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 0 deletions.
2 changes: 2 additions & 0 deletions etc/skydive.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ analyzer:
# if list is empty then will resolve to all existing (sub) probes.
probes:
- cluster
- configmap
- container
- cronjob
- deployment
Expand All @@ -142,6 +143,7 @@ analyzer:
- pod
- replicaset
- replicationcontroller
- secret
- service
- statefulset
- storageclass
Expand Down
Binary file added statics/img/configmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added statics/img/secret.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions statics/js/components/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var nodeImgMap = setupFixedImages({
"default": "intf",
// k8s
"cluster": "cluster",
"configmap": "configmap",
"container": "container",
"cronjob": "cronjob",
"daemonset": "daemonset",
Expand All @@ -44,6 +45,7 @@ var nodeImgMap = setupFixedImages({
"namespace": "ns",
"replicaset": "replicaset",
"replicationcontroller": "replicationcontroller",
"secret": "secret",
"service": "service",
"statefulset": "statefulset",
"storageclass": "storageclass",
Expand Down
7 changes: 7 additions & 0 deletions tests/k8s/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: skydive-test-configmap
namespace: default
data:
log_level: INFO
11 changes: 11 additions & 0 deletions tests/k8s/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: skydive-test-secret
namespace: default
type: Opaque
data:
# echo -n 'admin' | base64
# YWRtaW4=
username: YWRtaW4=
password: YWRtaW4=
8 changes: 8 additions & 0 deletions tests/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func TestK8sClusterNode(t *testing.T) {
testNodeCreation(t, nil, nil, k8s.Manager, "cluster", k8s.ClusterName)
}

func TestK8sConfigMapNode(t *testing.T) {
testNodeCreationFromConfig(t, k8s.Manager, "configmap", objName+"-configmap")
}

func TestK8sContainerNode(t *testing.T) {
testNodeCreationFromConfig(t, k8s.Manager, "container", objName+"-container", "Image", "Pod")
}
Expand Down Expand Up @@ -251,6 +255,10 @@ func TestK8sReplicationControllerNode(t *testing.T) {
testNodeCreationFromConfig(t, k8s.Manager, "replicationcontroller", objName+"-replicationcontroller")
}

func TestK8sSecretNode(t *testing.T) {
testNodeCreationFromConfig(t, k8s.Manager, "secret", objName+"-secret", "Type")
}

func TestK8sServiceNode(t *testing.T) {
testNodeCreationFromConfig(t, k8s.Manager, "service", objName+"-service", "Ports", "ClusterIP", "ServiceType", "SessionAffinity", "LoadBalancerIP", "ExternalName")
}
Expand Down
50 changes: 50 additions & 0 deletions topology/probes/k8s/configmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2018 IBM, Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

package k8s

import (
"fmt"

"github.com/skydive-project/skydive/graffiti/graph"

"k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)

type configMapHandler struct {
}

func (h *configMapHandler) Dump(obj interface{}) string {
cm := obj.(*v1.ConfigMap)
return fmt.Sprintf("configmap{Namespace: %s, Name: %s}", cm.Namespace, cm.Name)
}

func (h *configMapHandler) Map(obj interface{}) (graph.Identifier, graph.Metadata) {
cm := obj.(*v1.ConfigMap)
m := NewMetadataFields(&cm.ObjectMeta)
return graph.Identifier(cm.GetUID()), NewMetadata(Manager, "configmap", m, cm, cm.Name)
}

func newConfigMapProbe(client interface{}, g *graph.Graph) Subprobe {
return NewResourceCache(client.(*kubernetes.Clientset).CoreV1().RESTClient(), &v1.ConfigMap{}, "configmaps", g, &configMapHandler{})
}
4 changes: 4 additions & 0 deletions topology/probes/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {

subprobeHandlers := map[string]SubprobeHandler{
"cluster": newClusterProbe,
"configmap": newConfigMapProbe,
"container": newContainerProbe,
"cronjob": newCronJobProbe,
"daemonset": newDaemonSetProbe,
Expand All @@ -82,6 +83,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
"pod": newPodProbe,
"replicaset": newReplicaSetProbe,
"replicationcontroller": newReplicationControllerProbe,
"secret": newSecretProbe,
"service": newServiceProbe,
"statefulset": newStatefulSetProbe,
"storageclass": newStorageClassProbe,
Expand Down Expand Up @@ -116,6 +118,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
)

probe.AppendNamespaceLinkers(
"configmap",
"cronjob",
"deployment",
"daemonset",
Expand All @@ -126,6 +129,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
"pod",
"replicaset",
"replicationcontroller",
"secret",
"service",
"statefulset",
)
Expand Down
51 changes: 51 additions & 0 deletions topology/probes/k8s/secret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2018 IBM, Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

package k8s

import (
"fmt"

"github.com/skydive-project/skydive/graffiti/graph"

"k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)

type secretHandler struct {
}

func (h *secretHandler) Dump(obj interface{}) string {
secret := obj.(*v1.Secret)
return fmt.Sprintf("secret{Namespace: %s, Name: %s}", secret.Namespace, secret.Name)
}

func (h *secretHandler) Map(obj interface{}) (graph.Identifier, graph.Metadata) {
secret := obj.(*v1.Secret)
m := NewMetadataFields(&secret.ObjectMeta)
m.SetField("Type", secret.Type)
return graph.Identifier(secret.GetUID()), NewMetadata(Manager, "secret", m, secret, secret.Name)
}

func newSecretProbe(client interface{}, g *graph.Graph) Subprobe {
return NewResourceCache(client.(*kubernetes.Clientset).CoreV1().RESTClient(), &v1.Secret{}, "secrets", g, &secretHandler{})
}

0 comments on commit e0b93bf

Please sign in to comment.