aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/plugins')
-rw-r--r--src/k8splugin/plugins/generic/plugin.go15
-rw-r--r--src/k8splugin/plugins/namespace/plugin_test.go4
-rw-r--r--src/k8splugin/plugins/service/plugin.go9
-rw-r--r--src/k8splugin/plugins/service/plugin_test.go7
4 files changed, 34 insertions, 1 deletions
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
diff --git a/src/k8splugin/plugins/namespace/plugin_test.go b/src/k8splugin/plugins/namespace/plugin_test.go
index 489ac096..c1944a40 100644
--- a/src/k8splugin/plugins/namespace/plugin_test.go
+++ b/src/k8splugin/plugins/namespace/plugin_test.go
@@ -46,6 +46,10 @@ func (t TestKubernetesConnector) GetStandardClient() kubernetes.Interface {
return fake.NewSimpleClientset(t.object)
}
+func (t TestKubernetesConnector) GetInstanceID() string {
+ return ""
+}
+
func TestCreateNamespace(t *testing.T) {
testCases := []struct {
label string
diff --git a/src/k8splugin/plugins/service/plugin.go b/src/k8splugin/plugins/service/plugin.go
index 136a1343..4c1f37be 100644
--- a/src/k8splugin/plugins/service/plugin.go
+++ b/src/k8splugin/plugins/service/plugin.go
@@ -22,6 +22,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"
)
@@ -52,6 +53,14 @@ func (p servicePlugin) Create(yamlFilePath string, namespace string, client plug
}
service.Namespace = namespace
+ labels := service.GetLabels()
+ //Check if labels exist for this object
+ if labels == nil {
+ labels = map[string]string{}
+ }
+ labels[config.GetConfiguration().KubernetesLabelName] = client.GetInstanceID()
+ service.SetLabels(labels)
+
result, err := client.GetStandardClient().CoreV1().Services(namespace).Create(service)
if err != nil {
return "", pkgerrors.Wrap(err, "Create Service error")
diff --git a/src/k8splugin/plugins/service/plugin_test.go b/src/k8splugin/plugins/service/plugin_test.go
index aa0bcc29..1cef5027 100644
--- a/src/k8splugin/plugins/service/plugin_test.go
+++ b/src/k8splugin/plugins/service/plugin_test.go
@@ -14,11 +14,12 @@ limitations under the License.
package main
import (
- "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm"
"reflect"
"strings"
"testing"
+ "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm"
+
coreV1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -45,6 +46,10 @@ func (t TestKubernetesConnector) GetStandardClient() kubernetes.Interface {
return fake.NewSimpleClientset(t.object)
}
+func (t TestKubernetesConnector) GetInstanceID() string {
+ return ""
+}
+
func TestCreateService(t *testing.T) {
name := "mock-service"
testCases := []struct {