|
| 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