aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/DAaaS/microservices/collectd-operator/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'vnfs/DAaaS/microservices/collectd-operator/pkg')
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/apis/addtoscheme_onap_v1alpha1.go10
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/apis/apis.go13
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/collectdplugin_types.go56
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/doc.go4
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/register.go19
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/zz_generated.deepcopy.go108
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/zz_generated.openapi.go124
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/controller/add_collectdplugin.go10
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/controller/collectdplugin/collectdplugin_controller.go215
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/controller/controller.go18
10 files changed, 577 insertions, 0 deletions
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/addtoscheme_onap_v1alpha1.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/addtoscheme_onap_v1alpha1.go
new file mode 100644
index 00000000..711a1182
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/addtoscheme_onap_v1alpha1.go
@@ -0,0 +1,10 @@
+package apis
+
+import (
+ "demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1"
+)
+
+func init() {
+ // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
+ AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
+}
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/apis.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/apis.go
new file mode 100644
index 00000000..07dc9616
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/apis.go
@@ -0,0 +1,13 @@
+package apis
+
+import (
+ "k8s.io/apimachinery/pkg/runtime"
+)
+
+// AddToSchemes may be used to add all resources defined in the project to a Scheme
+var AddToSchemes runtime.SchemeBuilder
+
+// AddToScheme adds all Resources to the Scheme
+func AddToScheme(s *runtime.Scheme) error {
+ return AddToSchemes.AddToScheme(s)
+}
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/collectdplugin_types.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/collectdplugin_types.go
new file mode 100644
index 00000000..d29498e8
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/collectdplugin_types.go
@@ -0,0 +1,56 @@
+package v1alpha1
+
+import (
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
+// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
+
+// CollectdPluginSpec defines the desired state of CollectdPlugin
+// +k8s:openapi-gen=true
+type CollectdPluginSpec struct {
+ // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
+ // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
+ // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
+ PluginName string `json:"pluginName"`
+ PluginConf string `json:"pluginConf"`
+}
+
+// CollectdPluginStatus defines the observed state of CollectdPlugin
+// +k8s:openapi-gen=true
+type CollectdPluginStatus struct {
+ // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
+ // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
+ // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
+ // CollectdAgents are the collectd pods in the Daemonset
+ CollectdAgents []string `json:"collectdAgents"`
+ CollectdConf corev1.ConfigMap `json:"collectdConf"`
+}
+
+// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+
+// CollectdPlugin is the Schema for the collectdplugins API
+// +k8s:openapi-gen=true
+// +kubebuilder:subresource:status
+type CollectdPlugin struct {
+ metav1.TypeMeta `json:",inline"`
+ metav1.ObjectMeta `json:"metadata,omitempty"`
+
+ Spec CollectdPluginSpec `json:"spec,omitempty"`
+ Status CollectdPluginStatus `json:"status,omitempty"`
+}
+
+// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+
+// CollectdPluginList contains a list of CollectdPlugin
+type CollectdPluginList struct {
+ metav1.TypeMeta `json:",inline"`
+ metav1.ListMeta `json:"metadata,omitempty"`
+ Items []CollectdPlugin `json:"items"`
+}
+
+func init() {
+ SchemeBuilder.Register(&CollectdPlugin{}, &CollectdPluginList{})
+}
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/doc.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/doc.go
new file mode 100644
index 00000000..29b3493e
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/doc.go
@@ -0,0 +1,4 @@
+// Package v1alpha1 contains API Schema definitions for the onap v1alpha1 API group
+// +k8s:deepcopy-gen=package,register
+// +groupName=onap.org
+package v1alpha1
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/register.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/register.go
new file mode 100644
index 00000000..c670eea4
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/register.go
@@ -0,0 +1,19 @@
+// NOTE: Boilerplate only. Ignore this file.
+
+// Package v1alpha1 contains API Schema definitions for the onap v1alpha1 API group
+// +k8s:deepcopy-gen=package,register
+// +groupName=onap.org
+package v1alpha1
+
+import (
+ "k8s.io/apimachinery/pkg/runtime/schema"
+ "sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
+)
+
+var (
+ // SchemeGroupVersion is group version used to register these objects
+ SchemeGroupVersion = schema.GroupVersion{Group: "onap.org", Version: "v1alpha1"}
+
+ // SchemeBuilder is used to add go types to the GroupVersionKind scheme
+ SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
+)
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/zz_generated.deepcopy.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/zz_generated.deepcopy.go
new file mode 100644
index 00000000..0fe1dcc3
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/zz_generated.deepcopy.go
@@ -0,0 +1,108 @@
+// +build !ignore_autogenerated
+
+// Code generated by deepcopy-gen. DO NOT EDIT.
+
+package v1alpha1
+
+import (
+ runtime "k8s.io/apimachinery/pkg/runtime"
+)
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *CollectdPlugin) DeepCopyInto(out *CollectdPlugin) {
+ *out = *in
+ out.TypeMeta = in.TypeMeta
+ in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
+ out.Spec = in.Spec
+ in.Status.DeepCopyInto(&out.Status)
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectdPlugin.
+func (in *CollectdPlugin) DeepCopy() *CollectdPlugin {
+ if in == nil {
+ return nil
+ }
+ out := new(CollectdPlugin)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *CollectdPlugin) DeepCopyObject() runtime.Object {
+ if c := in.DeepCopy(); c != nil {
+ return c
+ }
+ return nil
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *CollectdPluginList) DeepCopyInto(out *CollectdPluginList) {
+ *out = *in
+ out.TypeMeta = in.TypeMeta
+ out.ListMeta = in.ListMeta
+ if in.Items != nil {
+ in, out := &in.Items, &out.Items
+ *out = make([]CollectdPlugin, len(*in))
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
+ }
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectdPluginList.
+func (in *CollectdPluginList) DeepCopy() *CollectdPluginList {
+ if in == nil {
+ return nil
+ }
+ out := new(CollectdPluginList)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *CollectdPluginList) DeepCopyObject() runtime.Object {
+ if c := in.DeepCopy(); c != nil {
+ return c
+ }
+ return nil
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *CollectdPluginSpec) DeepCopyInto(out *CollectdPluginSpec) {
+ *out = *in
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectdPluginSpec.
+func (in *CollectdPluginSpec) DeepCopy() *CollectdPluginSpec {
+ if in == nil {
+ return nil
+ }
+ out := new(CollectdPluginSpec)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *CollectdPluginStatus) DeepCopyInto(out *CollectdPluginStatus) {
+ *out = *in
+ if in.CollectdAgents != nil {
+ in, out := &in.CollectdAgents, &out.CollectdAgents
+ *out = make([]string, len(*in))
+ copy(*out, *in)
+ }
+ in.CollectdConf.DeepCopyInto(&out.CollectdConf)
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectdPluginStatus.
+func (in *CollectdPluginStatus) DeepCopy() *CollectdPluginStatus {
+ if in == nil {
+ return nil
+ }
+ out := new(CollectdPluginStatus)
+ in.DeepCopyInto(out)
+ return out
+}
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/zz_generated.openapi.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/zz_generated.openapi.go
new file mode 100644
index 00000000..a1d401b7
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/apis/onap/v1alpha1/zz_generated.openapi.go
@@ -0,0 +1,124 @@
+// +build !ignore_autogenerated
+
+// Code generated by openapi-gen. DO NOT EDIT.
+
+// This file was autogenerated by openapi-gen. Do not edit it manually!
+
+package v1alpha1
+
+import (
+ spec "github.com/go-openapi/spec"
+ common "k8s.io/kube-openapi/pkg/common"
+)
+
+func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
+ return map[string]common.OpenAPIDefinition{
+ "demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1.CollectdPlugin": schema_pkg_apis_onap_v1alpha1_CollectdPlugin(ref),
+ "demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1.CollectdPluginSpec": schema_pkg_apis_onap_v1alpha1_CollectdPluginSpec(ref),
+ "demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1.CollectdPluginStatus": schema_pkg_apis_onap_v1alpha1_CollectdPluginStatus(ref),
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_CollectdPlugin(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "CollectdPlugin is the Schema for the collectdplugins API",
+ Properties: map[string]spec.Schema{
+ "kind": {
+ SchemaProps: spec.SchemaProps{
+ Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "apiVersion": {
+ SchemaProps: spec.SchemaProps{
+ Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "metadata": {
+ SchemaProps: spec.SchemaProps{
+ Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
+ },
+ },
+ "spec": {
+ SchemaProps: spec.SchemaProps{
+ Ref: ref("demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1.CollectdPluginSpec"),
+ },
+ },
+ "status": {
+ SchemaProps: spec.SchemaProps{
+ Ref: ref("demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1.CollectdPluginStatus"),
+ },
+ },
+ },
+ },
+ },
+ Dependencies: []string{
+ "demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1.CollectdPluginSpec", "demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1.CollectdPluginStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_CollectdPluginSpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "CollectdPluginSpec defines the desired state of CollectdPlugin",
+ Properties: map[string]spec.Schema{
+ "pluginName": {
+ SchemaProps: spec.SchemaProps{
+ Description: "INSERT ADDITIONAL SPEC FIELDS - desired state of cluster Important: Run \"operator-sdk generate k8s\" to regenerate code after modifying this file Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html",
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "pluginConf": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ },
+ Required: []string{"pluginName", "pluginConf"},
+ },
+ },
+ Dependencies: []string{},
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_CollectdPluginStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "CollectdPluginStatus defines the observed state of CollectdPlugin",
+ Properties: map[string]spec.Schema{
+ "collectdAgents": {
+ SchemaProps: spec.SchemaProps{
+ Description: "INSERT ADDITIONAL STATUS FIELD - define observed state of cluster Important: Run \"operator-sdk generate k8s\" to regenerate code after modifying this file Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html CollectdAgents are the collectd pods in the Daemonset",
+ Type: []string{"array"},
+ Items: &spec.SchemaOrArray{
+ Schema: &spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ },
+ },
+ },
+ "collectdConf": {
+ SchemaProps: spec.SchemaProps{
+ Ref: ref("k8s.io/api/core/v1.ConfigMap"),
+ },
+ },
+ },
+ Required: []string{"collectdAgents", "collectdConf"},
+ },
+ },
+ Dependencies: []string{
+ "k8s.io/api/core/v1.ConfigMap"},
+ }
+}
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/add_collectdplugin.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/add_collectdplugin.go
new file mode 100644
index 00000000..da8d1e1d
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/add_collectdplugin.go
@@ -0,0 +1,10 @@
+package controller
+
+import (
+ "demo/vnfs/DAaaS/collectd-operator/pkg/controller/collectdplugin"
+)
+
+func init() {
+ // AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
+ AddToManagerFuncs = append(AddToManagerFuncs, collectdplugin.Add)
+}
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/collectdplugin/collectdplugin_controller.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/collectdplugin/collectdplugin_controller.go
new file mode 100644
index 00000000..77d7e157
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/collectdplugin/collectdplugin_controller.go
@@ -0,0 +1,215 @@
+package collectdplugin
+
+import (
+ "context"
+ "crypto/sha256"
+
+ onapv1alpha1 "demo/vnfs/DAaaS/collectd-operator/pkg/apis/onap/v1alpha1"
+
+ corev1 "k8s.io/api/core/v1"
+ extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
+ "k8s.io/apimachinery/pkg/api/errors"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/runtime"
+ "sigs.k8s.io/controller-runtime/pkg/client"
+ "sigs.k8s.io/controller-runtime/pkg/controller"
+ "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
+ "sigs.k8s.io/controller-runtime/pkg/handler"
+ "sigs.k8s.io/controller-runtime/pkg/manager"
+ "sigs.k8s.io/controller-runtime/pkg/reconcile"
+ logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
+ "sigs.k8s.io/controller-runtime/pkg/source"
+)
+
+var log = logf.Log.WithName("controller_collectdplugin")
+
+// ResourceMap to hold objects to update/reload
+type ResourceMap struct {
+ configMap *corev1.ConfigMap
+ daemonSet *extensionsv1beta1.DaemonSet
+}
+
+/**
+* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller
+* business logic. Delete these comments after modifying this file.*
+ */
+
+// Add creates a new CollectdPlugin Controller and adds it to the Manager. The Manager will set fields on the Controller
+// and Start it when the Manager is Started.
+func Add(mgr manager.Manager) error {
+ return add(mgr, newReconciler(mgr))
+}
+
+// newReconciler returns a new reconcile.Reconciler
+func newReconciler(mgr manager.Manager) reconcile.Reconciler {
+ return &ReconcileCollectdPlugin{client: mgr.GetClient(), scheme: mgr.GetScheme()}
+}
+
+// add adds a new Controller to mgr with r as the reconcile.Reconciler
+func add(mgr manager.Manager, r reconcile.Reconciler) error {
+ // Create a new controller
+ log.V(1).Info("Creating a new controller for CollectdPlugin")
+ c, err := controller.New("collectdplugin-controller", mgr, controller.Options{Reconciler: r})
+ if err != nil {
+ return err
+ }
+
+ // Watch for changes to primary resource CollectdPlugin
+ log.V(1).Info("Add watcher for primary resource CollectdPlugin")
+ err = c.Watch(&source.Kind{Type: &onapv1alpha1.CollectdPlugin{}}, &handler.EnqueueRequestForObject{})
+ if err != nil {
+ return err
+ }
+
+ // TODO(user): Modify this to be the types you create that are owned by the primary resource
+ // Watch for changes to secondary resource Pods and requeue the owner CollectdPlugin
+ log.V(1).Info("Add watcher for secondary resource ConfigMap")
+ err = c.Watch(&source.Kind{Type: &corev1.ConfigMap{}}, &handler.EnqueueRequestForOwner{
+ IsController: true,
+ OwnerType: &onapv1alpha1.CollectdPlugin{},
+ })
+ if err != nil {
+ return err
+ }
+
+ err = c.Watch(&source.Kind{Type: &extensionsv1beta1.DaemonSet{}}, &handler.EnqueueRequestForOwner{
+ IsController: true,
+ OwnerType: &onapv1alpha1.CollectdPlugin{},
+ })
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// blank assignment to verify that ReconcileCollectdPlugin implements reconcile.Reconciler
+var _ reconcile.Reconciler = &ReconcileCollectdPlugin{}
+
+// ReconcileCollectdPlugin reconciles a CollectdPlugin object
+type ReconcileCollectdPlugin struct {
+ // This client, initialized using mgr.Client() above, is a split client
+ // that reads objects from the cache and writes to the apiserver
+ client client.Client
+ scheme *runtime.Scheme
+}
+
+// Reconcile reads that state of the cluster for a CollectdPlugin object and makes changes based on the state read
+// and what is in the CollectdPlugin.Spec
+// TODO(user): Modify this Reconcile function to implement your Controller logic. This example creates
+// a Pod as an example
+// Note:
+// The Controller will requeue the Request to be processed again if the returned error is non-nil or
+// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
+func (r *ReconcileCollectdPlugin) Reconcile(request reconcile.Request) (reconcile.Result, error) {
+ reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
+ reqLogger.Info("Reconciling CollectdPlugin")
+
+ // Fetch the CollectdPlugin instance
+ instance := &onapv1alpha1.CollectdPlugin{}
+ err := r.client.Get(context.TODO(), request.NamespacedName, instance)
+ if err != nil {
+ if errors.IsNotFound(err) {
+ // Request object not found, could have been deleted after reconcile request.
+ // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
+ // Return and don't requeue
+ reqLogger.V(1).Info("CollectdPlugin object Not found")
+ return reconcile.Result{}, nil
+ }
+ // Error reading the object - requeue the request.
+ reqLogger.V(1).Info("Error reading the CollectdPlugin object, Requeuing")
+ return reconcile.Result{}, err
+ }
+
+ rmap, err := findResourceMapForCR(r, instance)
+ if err != nil {
+ reqLogger.Info("Skip reconcile: ConfigMap not found")
+ return reconcile.Result{}, err
+ }
+
+ cm := rmap.configMap
+ ds := rmap.daemonSet
+ reqLogger.V(1).Info("Found ResourceMap")
+ reqLogger.V(1).Info("ConfigMap.Namespace", cm.Namespace, "ConfigMap.Name", cm.Name)
+ reqLogger.V(1).Info("DaemonSet.Namespace", ds.Namespace, "DaemonSet.Name", ds.Name)
+ // Set CollectdPlugin instance as the owner and controller
+ if err := controllerutil.SetControllerReference(instance, cm, r.scheme); err != nil {
+ return reconcile.Result{}, err
+ }
+ // Set CollectdConf instance as the owner and controller
+ if err := controllerutil.SetControllerReference(instance, ds, r.scheme); err != nil {
+ return reconcile.Result{}, err
+ }
+
+ // Update the ConfigMap with new Spec and reload DaemonSets
+ reqLogger.Info("Updating the ConfigMap", "ConfigMap.Namespace", cm.Namespace, "ConfigMap.Name", cm.Name)
+ log.Info("Map: ", cm.Data)
+ err = r.client.Update(context.TODO(), cm)
+ if err != nil {
+ return reconcile.Result{}, err
+ }
+
+ //Restart Collectd Pods
+
+ ds.Spec.Template.SetLabels(map[string]string{
+ "daaas-random": ComputeSHA256([]byte("TEST")),
+ })
+ // Reconcile success
+ reqLogger.Info("Updated the ConfigMap", "ConfigMap.Namespace", cm.Namespace, "ConfigMap.Name", cm.Name)
+ return reconcile.Result{}, nil
+}
+
+// ComputeSHA256 returns hash of data as string
+func ComputeSHA256(data []byte) string {
+ hash := sha256.Sum256(data)
+ return string(hash[:])
+}
+
+// findConfigMapForCR returns the configMap used by collectd Daemonset
+func findResourceMapForCR(r *ReconcileCollectdPlugin, cr *onapv1alpha1.CollectdPlugin) (ResourceMap, error) {
+ cmList := &corev1.ConfigMapList{}
+ opts := &client.ListOptions{}
+ rmap := ResourceMap{}
+
+ // Select ConfigMaps with label app=collectd
+ opts.SetLabelSelector("app=collectd")
+ opts.InNamespace(cr.Namespace)
+ err := r.client.List(context.TODO(), opts, cmList)
+ if err != nil {
+ return rmap, err
+ }
+
+ // Select DaemonSets with label app=collectd
+ dsList := &extensionsv1beta1.DaemonSet{}
+ err = r.client.List(context.TODO(), opts, dsList)
+ if err != nil {
+ return rmap, err
+ }
+
+ rmap.configMap = &cmList.Items[0]
+ rmap.daemonSet = dsList
+ return rmap, err
+}
+
+// newPodForCR returns a busybox pod with the same name/namespace as the cr
+func newPodForCR(cr *onapv1alpha1.CollectdPlugin) *corev1.Pod {
+ labels := map[string]string{
+ "app": cr.Name,
+ }
+ return &corev1.Pod{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: cr.Name + "-pod",
+ Namespace: cr.Namespace,
+ Labels: labels,
+ },
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: "busybox",
+ Image: "busybox",
+ Command: []string{"sleep", "3600"},
+ },
+ },
+ },
+ }
+}
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/controller.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/controller.go
new file mode 100644
index 00000000..7c069f3e
--- /dev/null
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/controller.go
@@ -0,0 +1,18 @@
+package controller
+
+import (
+ "sigs.k8s.io/controller-runtime/pkg/manager"
+)
+
+// AddToManagerFuncs is a list of functions to add all Controllers to the Manager
+var AddToManagerFuncs []func(manager.Manager) error
+
+// AddToManager adds all Controllers to the Manager
+func AddToManager(m manager.Manager) error {
+ for _, f := range AddToManagerFuncs {
+ if err := f(m); err != nil {
+ return err
+ }
+ }
+ return nil
+}