aboutsummaryrefslogtreecommitdiffstats
path: root/src/monitor/pkg/controller/resourcebundlestate/helpers.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-07-31 15:32:28 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-08-28 12:45:14 -0700
commitab8c95eff5c1228237f758d3ccfc99c751f713f7 (patch)
treea950ac5356f547434f24c8cc3bf53f3620e84a74 /src/monitor/pkg/controller/resourcebundlestate/helpers.go
parentdcace0784979890bb986fb078348b4b3ceef146c (diff)
Adding monitor operator to monitor edge resources
Add an operator to monitor resources at the edge location. The operator listens to pods and services right now and stores their information in a CustomResource Issue-ID: MULTICLOUD-675 Change-Id: I801478a77fcd019010ea1b4388d6077f63b89d05 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/monitor/pkg/controller/resourcebundlestate/helpers.go')
-rw-r--r--src/monitor/pkg/controller/resourcebundlestate/helpers.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/monitor/pkg/controller/resourcebundlestate/helpers.go b/src/monitor/pkg/controller/resourcebundlestate/helpers.go
new file mode 100644
index 00000000..dab78825
--- /dev/null
+++ b/src/monitor/pkg/controller/resourcebundlestate/helpers.go
@@ -0,0 +1,54 @@
+package resourcebundlestate
+
+import (
+ "context"
+ "log"
+
+ "k8s.io/apimachinery/pkg/labels"
+ "k8s.io/apimachinery/pkg/runtime"
+ "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+// checkLabel verifies if the expected label exists and returns bool
+func checkLabel(labels map[string]string) bool {
+
+ _, ok := labels["k8splugin.io/rb-inst-id"]
+ if !ok {
+ log.Printf("Pod does not have label. Filter it.")
+ return false
+ }
+ return true
+}
+
+// returnLabel verifies if the expected label exists and returns a map
+func returnLabel(labels map[string]string) map[string]string {
+
+ l, ok := labels["k8splugin.io/rb-inst-id"]
+ if !ok {
+ log.Printf("Pod does not have label. Filter it.")
+ return nil
+ }
+ return map[string]string{
+ "k8splugin.io/rb-inst-id": l,
+ }
+}
+
+// listResources lists resources based on the selectors provided
+// The data is returned in the pointer to the runtime.Object
+// provided as argument.
+func listResources(cli client.Client, namespace string,
+ labelSelector map[string]string, returnData runtime.Object) error {
+
+ listOptions := &client.ListOptions{
+ Namespace: namespace,
+ LabelSelector: labels.SelectorFromSet(labelSelector),
+ }
+
+ err := cli.List(context.TODO(), listOptions, returnData)
+ if err != nil {
+ log.Printf("Failed to list CRs: %v", err)
+ return err
+ }
+
+ return nil
+}