Last active
April 2, 2018 19:00
-
-
Save sidneyw/32cfbb29169a21a0f1a537d555546169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/client-go/kubernetes" | |
"k8s.io/client-go/rest" | |
) | |
type K8sObject interface { | |
GetAnnotations() map[string]string | |
GetLabels() map[string]string | |
GetName() string | |
GetNamespace() string | |
GetUID() types.UID | |
} | |
type K8sQuery func(*kubernetes.Clientset, func(K8sObject)) | |
func GetK8sClient() *kubernetes.Clientset { | |
config, err := rest.InClusterConfig() | |
if err != nil { | |
panic(err.Error()) | |
} | |
client, err := kubernetes.NewForConfig(config) | |
if err != nil { | |
panic(err.Error()) | |
} | |
return client | |
} | |
func MapDeployments(client *kubernetes.Clientset, do func(K8sObject)) { | |
deployments, _ := client.Apps().Deployments("").List(meta_v1.ListOptions{}) | |
for _, k8sobject := range deployments.Items { | |
do(&k8sobject) | |
} | |
} | |
func GetMetaLatest(obj K8sObject) (id string, latest LatestSample) { | |
url, _ := GetDashboardUrl(obj) | |
// Meta data table ID | |
id = fmt.Sprintf("%s-meta", PREFIX) | |
latest = LatestSample{Value: url} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment