From b75115b0678a1034ffc1d1c8fee40c7f5b995c97 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Wed, 17 Jul 2019 16:55:00 -0700 Subject: Add custom label to track created resources Create a custom label on created resources Also, create it on pods where pods are being created. This will help us later for filtering and querying pods and resources. Issue-ID: MULTICLOUD-675 Change-Id: I4b4fce7b67f9f27559d99dcca94a9191b96cb7c6 Signed-off-by: Kiran Kamineni --- src/k8splugin/plugins/generic/plugin.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/k8splugin/plugins/generic/plugin.go') diff --git a/src/k8splugin/plugins/generic/plugin.go b/src/k8splugin/plugins/generic/plugin.go index cc5fcb7a..0711466f 100644 --- a/src/k8splugin/plugins/generic/plugin.go +++ b/src/k8splugin/plugins/generic/plugin.go @@ -21,6 +21,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" utils "github.com/onap/multicloud-k8s/src/k8splugin/internal" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/config" "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm" "github.com/onap/multicloud-k8s/src/k8splugin/internal/plugin" ) @@ -57,6 +58,20 @@ func (g genericPlugin) Create(yamlFilePath string, namespace string, client plug return "", pkgerrors.Wrap(err, "Mapping kind to resource error") } + //Add the tracking label to all resources created here + labels := unstruct.GetLabels() + //Check if labels exist for this object + if labels == nil { + labels = map[string]string{} + } + labels[config.GetConfiguration().KubernetesLabelName] = client.GetInstanceID() + unstruct.SetLabels(labels) + + // This checks if the resource we are creating has a podSpec in it + // Eg: Deployment, StatefulSet, Job etc.. + // If a PodSpec is found, the label will be added to it too. + plugin.TagPodsIfPresent(unstruct, client.GetInstanceID()) + gvr := mapping.Resource var createdObj *unstructured.Unstructured -- cgit 1.2.3-korg