k8s-workload-metadata-provider

command module
v0.0.0-...-7136e67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 17 Imported by: 0

README

k8s-workload-metadata-provider

Docker

Built from KubeOps

images

Install the Custom Resource Definition on the cluster...

kubectl apply -f apis/crd.yml

TODO
Build process for CRD/Annotation
Update pods through downward API from associated deployments

Install the Custom Resource Definition on the cluster...

kubectl apply -f apis/crd.yml

TODO
Build process for CRD/Annotation
Update pods through downward API from associated deployments

Install the Custom Resource Definition on the cluster...

kubectl apply -f apis/crd.yml

How it works

// Inject the MetaDataProviderController into the subscriptions

metadataProvider := pkg.MetaDataProviderController{ KubeClient:kubeconfig}
/*
This is a default template file.
Add subscriptions and watchers to make it your own.
*/
err = runtime.EventBuffer(ctx, kubeClient,
&subscription.Registry{
	Subscriptions: []subscription.ISubscription{
	subscriptions.MetaDataContextSubscriber{ MetaDataProvider: metadataProvider  },
	subscriptions.PodSubscriber{ MetaDataProvider: metadataProvider },
},
}, []watcher.IObject{
	kubeClient.CoreV1().Pods(""),
	metaDataClient.MetaDataContextTypes(""), //Watch for our CRD
})
if err != nil {
	klog.Error(err)
}
Testing

You can then create an example of this CRD with kubectl apply -f apis/example-resource.yaml

Example running locally

❯ go run main.go --kubeconfig=/Users/alexjones/.kube/config
I0412 11:00:23.217006   56851 main.go:57] Starting @ 2021-04-12 11:00:23.216828 +0100 BST m=+0.009834460
I0412 11:00:23.217029   56851 main.go:64] Got watcher client...
I0412 11:00:23.218352   56851 main.go:71] Built config from flags...
I0412 11:00:23.219551   56851 main.go:84] Created new KubeConfig
I0412 11:00:23.219606   56851 main.go:101] Starting event buffer...
I0412 11:00:23.235668   56851 metadatacontextsubscriber.go:26] Found MetaDataContextType with data
I0412 11:00:23.235677   56851 metadatacontextsubscriber.go:29] Key slack: Value: map[critical-alerts:#critical medium-alert:#Medium-SRE server:XXXXXX]

We can see the CRD available here...

image

Documentation

Overview

Copyright © 2020 alexsimonjones@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Directories

Path Synopsis
apis
client/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
client/clientset/versioned/typed/metadata.cloudskunkworks/v1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/metadata.cloudskunkworks/v1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.
examples
crd
lib

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL