aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/DAaaS/microservices/remote-config-operator/pkg
diff options
context:
space:
mode:
authorSrivahni <srivahni.chivukula@intel.com>2019-10-24 14:08:58 -0700
committerMarco Platania <platania@research.att.com>2019-11-13 14:12:44 +0000
commit2026cb5283fbc44a4f68641f6e85628381ebda04 (patch)
treef66efc4b80884b6ff7a494b57c516e13e814f061 /vnfs/DAaaS/microservices/remote-config-operator/pkg
parent938afb8217d5414c4cd0d63650e24d0398ddcc91 (diff)
Add/update/delete PrometheusRemoteEndpoint CR
PrometheusRemoteEndpoint CR when applied, a remote write endpoint is added/updated/deleted in prometheus. Issue-ID: ONAPARC-393 Signed-off-by: Srivahni <srivahni.chivukula@intel.com> Change-Id: I8cdc0b673b35be3457a2b12c6769cd3cf62ac6c5
Diffstat (limited to 'vnfs/DAaaS/microservices/remote-config-operator/pkg')
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/addtoscheme_onap_v1alpha1.go10
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/apis.go13
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/group.go6
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/doc.go4
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/prometheusremoteendpoint_types.go73
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/register.go19
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/remotefilteraction_types.go50
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/zz_generated.deepcopy.go260
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/zz_generated.openapi.go231
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/add_prometheusremoteendpoint.go10
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/controller.go18
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/prometheusremoteendpoint/prometheusremoteendpoint_controller.go254
-rw-r--r--vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/utils/remoteconfigutils.go77
13 files changed, 1025 insertions, 0 deletions
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/addtoscheme_onap_v1alpha1.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/addtoscheme_onap_v1alpha1.go
new file mode 100644
index 00000000..29d7c508
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/addtoscheme_onap_v1alpha1.go
@@ -0,0 +1,10 @@
+package apis
+
+import (
+ "remote-config-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/remote-config-operator/pkg/apis/apis.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/apis.go
new file mode 100644
index 00000000..07dc9616
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-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/remote-config-operator/pkg/apis/onap/group.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/group.go
new file mode 100644
index 00000000..d35634ca
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/group.go
@@ -0,0 +1,6 @@
+// Package onap contains onap API versions.
+//
+// This file ensures Go source parsers acknowledge the onap package
+// and any child packages. It can be removed if any other Go source files are
+// added to this package.
+package onap
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/doc.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/doc.go
new file mode 100644
index 00000000..29b3493e
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-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/remote-config-operator/pkg/apis/onap/v1alpha1/prometheusremoteendpoint_types.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/prometheusremoteendpoint_types.go
new file mode 100644
index 00000000..71b38dc2
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/prometheusremoteendpoint_types.go
@@ -0,0 +1,73 @@
+package v1alpha1
+
+import (
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+type Metadata struct {
+ Name string `json:"Name"`
+ Labels []string `json:"Labels"`
+}
+
+// PrometheusRemoteEndpointSpec defines the desired state of PrometheusRemoteEndpoint
+// +k8s:openapi-gen=true
+type PrometheusRemoteEndpointSpec struct {
+ AdapterUrl string `json:"adapterUrl"`
+ FilterSelector *metav1.LabelSelector `json:"filterSelector,omitempty"`
+ Type string `json:"type"`
+ KafkaConfig string `json:"kafkaConfig,omitempty"`
+ QueueConfig QueueConfig `json:"queueConfig,omitempty"`
+ RemoteTimeout string `json:"remoteTimeout,omitempty"`
+}
+
+type KafkaConfig struct {
+ BrokerUrl string `json:"brokerUrl"`
+ Group string `json:"group,omitempty"`
+ Topic string `json:"topic"`
+}
+
+type QueueConfig struct {
+ BatchSendDeadline string `json:"batchSendDeadline,omitempty"`
+ Capacity string `json:"capacity,omitempty"`
+ MaxBackoff string `json:"maxBackoff,omitempty"`
+ MaxRetries string `json:"maxRetries,omitempty"`
+ MaxSamplesPerSend string `json:"maxSamplesPerSend,omitempty"`
+ MaxShards string `json:"maxShards,omitempty"`
+ MinBackoff string `json:"minBackoff,omitempty"`
+ MinShards string `json:"minShards,omitempty"`
+}
+
+// PrometheusRemoteEndpointStatus defines the observed state of PrometheusRemoteEndpoint
+// +k8s:openapi-gen=true
+type PrometheusRemoteEndpointStatus 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-v1.book.kubebuilder.io/beyond_basics/generating_crd.html
+}
+
+// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+
+// PrometheusRemoteEndpoint is the Schema for the prometheusremoteendpoints API
+// +k8s:openapi-gen=true
+// +kubebuilder:subresource:status
+// +kubebuilder:resource:path=prometheusremoteendpoints,scope=Namespaced
+type PrometheusRemoteEndpoint struct {
+ metav1.TypeMeta `json:",inline"`
+ metav1.ObjectMeta `json:"metadata,omitempty"`
+
+ Spec PrometheusRemoteEndpointSpec `json:"spec,omitempty"`
+ Status PrometheusRemoteEndpointStatus `json:"status,omitempty"`
+}
+
+// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+
+// PrometheusRemoteEndpointList contains a list of PrometheusRemoteEndpoint
+type PrometheusRemoteEndpointList struct {
+ metav1.TypeMeta `json:",inline"`
+ metav1.ListMeta `json:"metadata,omitempty"`
+ Items []PrometheusRemoteEndpoint `json:"items"`
+}
+
+func init() {
+ SchemeBuilder.Register(&PrometheusRemoteEndpoint{}, &PrometheusRemoteEndpointList{})
+}
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/register.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/register.go
new file mode 100644
index 00000000..343c0adf
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-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/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/remote-config-operator/pkg/apis/onap/v1alpha1/remotefilteraction_types.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/remotefilteraction_types.go
new file mode 100644
index 00000000..18b3dc6d
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/remotefilteraction_types.go
@@ -0,0 +1,50 @@
+package v1alpha1
+
+import (
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// RemoteFilterActionSpec defines the desired state of RemoteFilterAction
+// +k8s:openapi-gen=true
+type RemoteFilterActionSpec struct {
+ Action string `json:"action,omitempty"`
+ Regex string `json:"regex,omitempty"`
+ SourceLabels []string `json:"sourceLabels,omitempty"`
+ TargetLabel string `json:"targetLabel,omitempty"`
+ Replacement string `json:"replacement,omitempty"`
+}
+
+// RemoteFilterActionStatus defines the observed state of RemoteFilterAction
+// +k8s:openapi-gen=true
+type RemoteFilterActionStatus 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-v1.book.kubebuilder.io/beyond_basics/generating_crd.html
+}
+
+// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+
+// RemoteFilterAction is the Schema for the remotefilteractions API
+// +k8s:openapi-gen=true
+// +kubebuilder:subresource:status
+// +kubebuilder:resource:path=remotefilteractions,scope=Namespaced
+type RemoteFilterAction struct {
+ metav1.TypeMeta `json:",inline"`
+ metav1.ObjectMeta `json:"metadata,omitempty"`
+
+ Spec RemoteFilterActionSpec `json:"spec,omitempty"`
+ Status RemoteFilterActionStatus `json:"status,omitempty"`
+}
+
+// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+
+// RemoteFilterActionList contains a list of RemoteFilterAction
+type RemoteFilterActionList struct {
+ metav1.TypeMeta `json:",inline"`
+ metav1.ListMeta `json:"metadata,omitempty"`
+ Items []RemoteFilterAction `json:"items"`
+}
+
+func init() {
+ SchemeBuilder.Register(&RemoteFilterAction{}, &RemoteFilterActionList{})
+}
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/zz_generated.deepcopy.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/zz_generated.deepcopy.go
new file mode 100644
index 00000000..9fb59405
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/zz_generated.deepcopy.go
@@ -0,0 +1,260 @@
+// +build !ignore_autogenerated
+
+// Code generated by operator-sdk. DO NOT EDIT.
+
+package v1alpha1
+
+import (
+ v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ 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 *KafkaConfig) DeepCopyInto(out *KafkaConfig) {
+ *out = *in
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KafkaConfig.
+func (in *KafkaConfig) DeepCopy() *KafkaConfig {
+ if in == nil {
+ return nil
+ }
+ out := new(KafkaConfig)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *Metadata) DeepCopyInto(out *Metadata) {
+ *out = *in
+ if in.Labels != nil {
+ in, out := &in.Labels, &out.Labels
+ *out = make([]string, len(*in))
+ copy(*out, *in)
+ }
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Metadata.
+func (in *Metadata) DeepCopy() *Metadata {
+ if in == nil {
+ return nil
+ }
+ out := new(Metadata)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *PrometheusRemoteEndpoint) DeepCopyInto(out *PrometheusRemoteEndpoint) {
+ *out = *in
+ out.TypeMeta = in.TypeMeta
+ in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
+ in.Spec.DeepCopyInto(&out.Spec)
+ out.Status = in.Status
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusRemoteEndpoint.
+func (in *PrometheusRemoteEndpoint) DeepCopy() *PrometheusRemoteEndpoint {
+ if in == nil {
+ return nil
+ }
+ out := new(PrometheusRemoteEndpoint)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *PrometheusRemoteEndpoint) 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 *PrometheusRemoteEndpointList) DeepCopyInto(out *PrometheusRemoteEndpointList) {
+ *out = *in
+ out.TypeMeta = in.TypeMeta
+ out.ListMeta = in.ListMeta
+ if in.Items != nil {
+ in, out := &in.Items, &out.Items
+ *out = make([]PrometheusRemoteEndpoint, len(*in))
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
+ }
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusRemoteEndpointList.
+func (in *PrometheusRemoteEndpointList) DeepCopy() *PrometheusRemoteEndpointList {
+ if in == nil {
+ return nil
+ }
+ out := new(PrometheusRemoteEndpointList)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *PrometheusRemoteEndpointList) 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 *PrometheusRemoteEndpointSpec) DeepCopyInto(out *PrometheusRemoteEndpointSpec) {
+ *out = *in
+ if in.FilterSelector != nil {
+ in, out := &in.FilterSelector, &out.FilterSelector
+ *out = new(v1.LabelSelector)
+ (*in).DeepCopyInto(*out)
+ }
+ out.QueueConfig = in.QueueConfig
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusRemoteEndpointSpec.
+func (in *PrometheusRemoteEndpointSpec) DeepCopy() *PrometheusRemoteEndpointSpec {
+ if in == nil {
+ return nil
+ }
+ out := new(PrometheusRemoteEndpointSpec)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *PrometheusRemoteEndpointStatus) DeepCopyInto(out *PrometheusRemoteEndpointStatus) {
+ *out = *in
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusRemoteEndpointStatus.
+func (in *PrometheusRemoteEndpointStatus) DeepCopy() *PrometheusRemoteEndpointStatus {
+ if in == nil {
+ return nil
+ }
+ out := new(PrometheusRemoteEndpointStatus)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *QueueConfig) DeepCopyInto(out *QueueConfig) {
+ *out = *in
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new QueueConfig.
+func (in *QueueConfig) DeepCopy() *QueueConfig {
+ if in == nil {
+ return nil
+ }
+ out := new(QueueConfig)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *RemoteFilterAction) DeepCopyInto(out *RemoteFilterAction) {
+ *out = *in
+ out.TypeMeta = in.TypeMeta
+ in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
+ in.Spec.DeepCopyInto(&out.Spec)
+ out.Status = in.Status
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoteFilterAction.
+func (in *RemoteFilterAction) DeepCopy() *RemoteFilterAction {
+ if in == nil {
+ return nil
+ }
+ out := new(RemoteFilterAction)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *RemoteFilterAction) 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 *RemoteFilterActionList) DeepCopyInto(out *RemoteFilterActionList) {
+ *out = *in
+ out.TypeMeta = in.TypeMeta
+ out.ListMeta = in.ListMeta
+ if in.Items != nil {
+ in, out := &in.Items, &out.Items
+ *out = make([]RemoteFilterAction, len(*in))
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
+ }
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoteFilterActionList.
+func (in *RemoteFilterActionList) DeepCopy() *RemoteFilterActionList {
+ if in == nil {
+ return nil
+ }
+ out := new(RemoteFilterActionList)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *RemoteFilterActionList) 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 *RemoteFilterActionSpec) DeepCopyInto(out *RemoteFilterActionSpec) {
+ *out = *in
+ if in.SourceLabels != nil {
+ in, out := &in.SourceLabels, &out.SourceLabels
+ *out = make([]string, len(*in))
+ copy(*out, *in)
+ }
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoteFilterActionSpec.
+func (in *RemoteFilterActionSpec) DeepCopy() *RemoteFilterActionSpec {
+ if in == nil {
+ return nil
+ }
+ out := new(RemoteFilterActionSpec)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *RemoteFilterActionStatus) DeepCopyInto(out *RemoteFilterActionStatus) {
+ *out = *in
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoteFilterActionStatus.
+func (in *RemoteFilterActionStatus) DeepCopy() *RemoteFilterActionStatus {
+ if in == nil {
+ return nil
+ }
+ out := new(RemoteFilterActionStatus)
+ in.DeepCopyInto(out)
+ return out
+}
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/zz_generated.openapi.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/zz_generated.openapi.go
new file mode 100644
index 00000000..ca4c9511
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/apis/onap/v1alpha1/zz_generated.openapi.go
@@ -0,0 +1,231 @@
+// +build !ignore_autogenerated
+
+// 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{
+ "./pkg/apis/onap/v1alpha1.PrometheusRemoteEndpoint": schema_pkg_apis_onap_v1alpha1_PrometheusRemoteEndpoint(ref),
+ "./pkg/apis/onap/v1alpha1.PrometheusRemoteEndpointSpec": schema_pkg_apis_onap_v1alpha1_PrometheusRemoteEndpointSpec(ref),
+ "./pkg/apis/onap/v1alpha1.PrometheusRemoteEndpointStatus": schema_pkg_apis_onap_v1alpha1_PrometheusRemoteEndpointStatus(ref),
+ "./pkg/apis/onap/v1alpha1.RemoteFilterAction": schema_pkg_apis_onap_v1alpha1_RemoteFilterAction(ref),
+ "./pkg/apis/onap/v1alpha1.RemoteFilterActionSpec": schema_pkg_apis_onap_v1alpha1_RemoteFilterActionSpec(ref),
+ "./pkg/apis/onap/v1alpha1.RemoteFilterActionStatus": schema_pkg_apis_onap_v1alpha1_RemoteFilterActionStatus(ref),
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_PrometheusRemoteEndpoint(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "PrometheusRemoteEndpoint is the Schema for the prometheusremoteendpoints API",
+ Type: []string{"object"},
+ 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("./pkg/apis/onap/v1alpha1.PrometheusRemoteEndpointSpec"),
+ },
+ },
+ "status": {
+ SchemaProps: spec.SchemaProps{
+ Ref: ref("./pkg/apis/onap/v1alpha1.PrometheusRemoteEndpointStatus"),
+ },
+ },
+ },
+ },
+ },
+ Dependencies: []string{
+ "./pkg/apis/onap/v1alpha1.PrometheusRemoteEndpointSpec", "./pkg/apis/onap/v1alpha1.PrometheusRemoteEndpointStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_PrometheusRemoteEndpointSpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "PrometheusRemoteEndpointSpec defines the desired state of PrometheusRemoteEndpoint",
+ Type: []string{"object"},
+ Properties: map[string]spec.Schema{
+ "adapterUrl": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "filterSelector": {
+ SchemaProps: spec.SchemaProps{
+ Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelector"),
+ },
+ },
+ "type": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "kafkaConfig": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "queueConfig": {
+ SchemaProps: spec.SchemaProps{
+ Ref: ref("./pkg/apis/onap/v1alpha1.QueueConfig"),
+ },
+ },
+ "remoteTimeout": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ },
+ Required: []string{"adapterUrl", "type"},
+ },
+ },
+ Dependencies: []string{
+ "./pkg/apis/onap/v1alpha1.QueueConfig", "k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelector"},
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_PrometheusRemoteEndpointStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "PrometheusRemoteEndpointStatus defines the observed state of PrometheusRemoteEndpoint",
+ Type: []string{"object"},
+ },
+ },
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_RemoteFilterAction(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "RemoteFilterAction is the Schema for the remotefilteractions API",
+ Type: []string{"object"},
+ 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("./pkg/apis/onap/v1alpha1.RemoteFilterActionSpec"),
+ },
+ },
+ "status": {
+ SchemaProps: spec.SchemaProps{
+ Ref: ref("./pkg/apis/onap/v1alpha1.RemoteFilterActionStatus"),
+ },
+ },
+ },
+ },
+ },
+ Dependencies: []string{
+ "./pkg/apis/onap/v1alpha1.RemoteFilterActionSpec", "./pkg/apis/onap/v1alpha1.RemoteFilterActionStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_RemoteFilterActionSpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "RemoteFilterActionSpec defines the desired state of RemoteFilterAction",
+ Type: []string{"object"},
+ Properties: map[string]spec.Schema{
+ "action": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "regex": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "sourceLabels": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"array"},
+ Items: &spec.SchemaOrArray{
+ Schema: &spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ },
+ },
+ },
+ "targetLabel": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ "replacement": {
+ SchemaProps: spec.SchemaProps{
+ Type: []string{"string"},
+ Format: "",
+ },
+ },
+ },
+ },
+ },
+ }
+}
+
+func schema_pkg_apis_onap_v1alpha1_RemoteFilterActionStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
+ return common.OpenAPIDefinition{
+ Schema: spec.Schema{
+ SchemaProps: spec.SchemaProps{
+ Description: "RemoteFilterActionStatus defines the observed state of RemoteFilterAction",
+ Type: []string{"object"},
+ },
+ },
+ }
+}
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/add_prometheusremoteendpoint.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/add_prometheusremoteendpoint.go
new file mode 100644
index 00000000..6576d8c9
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/add_prometheusremoteendpoint.go
@@ -0,0 +1,10 @@
+package controller
+
+import (
+ "remote-config-operator/pkg/controller/prometheusremoteendpoint"
+)
+
+func init() {
+ // AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
+ AddToManagerFuncs = append(AddToManagerFuncs, prometheusremoteendpoint.Add)
+}
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/controller.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/controller.go
new file mode 100644
index 00000000..7c069f3e
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-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
+}
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/prometheusremoteendpoint/prometheusremoteendpoint_controller.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/prometheusremoteendpoint/prometheusremoteendpoint_controller.go
new file mode 100644
index 00000000..2d78a43f
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/prometheusremoteendpoint/prometheusremoteendpoint_controller.go
@@ -0,0 +1,254 @@
+package prometheusremoteendpoint
+
+import (
+ "context"
+ "encoding/json"
+ "strconv"
+
+ onapv1alpha1 "remote-config-operator/pkg/apis/onap/v1alpha1"
+
+ monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
+ logr "github.com/go-logr/logr"
+ corev1 "k8s.io/api/core/v1"
+ "k8s.io/apimachinery/pkg/api/errors"
+ "k8s.io/apimachinery/pkg/runtime"
+ "k8s.io/apimachinery/pkg/types"
+ remoteconfigutils "remote-config-operator/pkg/controller/utils"
+ "sigs.k8s.io/controller-runtime/pkg/client"
+ "sigs.k8s.io/controller-runtime/pkg/controller"
+ "sigs.k8s.io/controller-runtime/pkg/handler"
+ logf "sigs.k8s.io/controller-runtime/pkg/log"
+ "sigs.k8s.io/controller-runtime/pkg/manager"
+ "sigs.k8s.io/controller-runtime/pkg/reconcile"
+ "sigs.k8s.io/controller-runtime/pkg/source"
+)
+
+var log = logf.Log.WithName("controller_prometheusremoteendpoint")
+
+// Add creates a new PrometheusRemoteEndpoint 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 &ReconcilePrometheusRemoteEndpoint{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
+ c, err := controller.New("prometheusremoteendpoint-controller", mgr, controller.Options{Reconciler: r})
+ if err != nil {
+ return err
+ }
+
+ // Watch for changes to primary resource PrometheusRemoteEndpoint
+
+ log.V(1).Info("Add watcher for primary resource PrometheusRemoteEndpoint")
+ err = c.Watch(&source.Kind{Type: &onapv1alpha1.PrometheusRemoteEndpoint{}}, &handler.EnqueueRequestForObject{})
+ if err != nil {
+ return err
+ }
+
+ log.V(1).Info("Add watcher for secondary resource RemoteFilterAction")
+ // 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 PrometheusRemoteEndpoint
+ err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{
+ IsController: true,
+ OwnerType: &onapv1alpha1.PrometheusRemoteEndpoint{},
+ })
+ if err != nil {
+ log.Error(err, "Error enqueuing requests due to remoteFilterAction changes")
+ return err
+ }
+
+ log.Info("Enqueued reconcile requests due to remoteFilterAction changes")
+ return nil
+}
+
+// blank assignment to verify that ReconcilePrometheusRemoteEndpoint implements reconcile.Reconciler
+var _ reconcile.Reconciler = &ReconcilePrometheusRemoteEndpoint{}
+
+// ReconcilePrometheusRemoteEndpoint reconciles a PrometheusRemoteEndpoint object
+type ReconcilePrometheusRemoteEndpoint 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 PrometheusRemoteEndpoint object and makes changes based on the state read
+// and what is in the PrometheusRemoteEndpoint.Spec
+
+// 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 *ReconcilePrometheusRemoteEndpoint) Reconcile(request reconcile.Request) (reconcile.Result, error) {
+ reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
+ reqLogger.Info("Reconciling PrometheusRemoteEndpoint")
+
+ // Fetch the PrometheusRemoteEndpoint instance
+ instance := &onapv1alpha1.PrometheusRemoteEndpoint{}
+ 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.Error(err, "PrometheusRemoteEndpoint object not found")
+ return reconcile.Result{}, nil
+ }
+ // Error reading the object - requeue the request.
+ reqLogger.Error(err, "Error reading PrometheusRemoteEndpoint object, Requeing ")
+ return reconcile.Result{}, err
+ }
+
+ isBeingDeleted := checkDeletionTimestamp(reqLogger, instance)
+ if isBeingDeleted {
+ //Delete Remote write
+ if err := r.processDeletionRequest(reqLogger, instance); err != nil {
+ reqLogger.Error(err, "Error processing deletion request")
+ return reconcile.Result{}, err
+ }
+ return reconcile.Result{}, nil
+ }
+
+ //Add finalizer for the CR object
+ if !remoteconfigutils.Contains(instance.GetFinalizers(), remoteconfigutils.RemoteConfigFinalizer) {
+ reqLogger.Info("Adding finalizer for PrometheusRemoteEndpoint")
+ if err := addFinalizer(reqLogger, instance); err != nil {
+ return reconcile.Result{}, err
+ }
+ err := r.client.Update(context.TODO(), instance)
+ if err != nil {
+ reqLogger.Error(err, "Unable to update instance")
+ return reconcile.Result{}, err
+ }
+ return reconcile.Result{}, nil
+ }
+
+ if err := r.processPatchRequest(reqLogger, instance); err != nil {
+ reqLogger.Error(err, "Error processing request")
+ return reconcile.Result{}, err
+ }
+ return reconcile.Result{}, nil
+}
+
+func (r *ReconcilePrometheusRemoteEndpoint) processPatchRequest(reqLogger logr.Logger, instance *onapv1alpha1.PrometheusRemoteEndpoint) error {
+
+ prom := &monitoringv1.Prometheus{}
+ if err1 := r.client.Get(context.TODO(), types.NamespacedName{Namespace: instance.Namespace, Name: instance.ObjectMeta.Labels["app"]}, prom); err1 != nil {
+ reqLogger.Error(err1, "Error getting prometheus")
+ return err1
+ }
+ reqLogger.Info("Found prometheus to update")
+
+ var patch []byte
+
+ rws := prom.Spec.RemoteWrite
+ adapterURL := instance.Spec.AdapterUrl
+
+ isUpdate := false
+ for i, spec := range rws {
+ if spec.URL == instance.Spec.AdapterUrl {
+ reqLogger.Info("Remote write already exists, updating it")
+ patch, _ = formPatch("replace", strconv.Itoa(i), adapterURL, instance, reqLogger)
+ isUpdate = true
+ break
+ }
+ }
+
+ if !isUpdate {
+ reqLogger.Info("Remote write does not exist, creating one...")
+ // rwsLength := len(rws)
+ patch, _ = formPatch("add", "-", adapterURL, instance, reqLogger)
+ }
+ patchErr := r.client.Patch(context.TODO(), prom, client.ConstantPatch(types.JSONPatchType, patch))
+ if patchErr != nil {
+ reqLogger.Error(patchErr, "Unable to process patch to prometheus")
+ return patchErr
+ }
+ reqLogger.Info("Patch merged")
+
+ return nil
+}
+
+func checkDeletionTimestamp(reqlogger logr.Logger, instance *onapv1alpha1.PrometheusRemoteEndpoint) bool {
+ isMarkedForDeletion := instance.GetDeletionTimestamp() != nil
+ return isMarkedForDeletion
+}
+
+func (r *ReconcilePrometheusRemoteEndpoint) processDeletionRequest(reqLogger logr.Logger, instance *onapv1alpha1.PrometheusRemoteEndpoint) error {
+ prom := &monitoringv1.Prometheus{}
+ if err := r.client.Get(context.TODO(), types.NamespacedName{Namespace: instance.Namespace, Name: instance.ObjectMeta.Labels["app"]}, prom); err != nil {
+ reqLogger.Error(err, "Error getting prometheus")
+ return err
+ }
+ reqLogger.Info("Found prometheus to update")
+
+ var patch []byte
+ adapterURL := instance.Spec.AdapterUrl
+
+ rws := prom.Spec.RemoteWrite
+ for i, spec := range rws {
+ if spec.URL == instance.Spec.AdapterUrl {
+ reqLogger.Info("Found remote write to be removed, removing it")
+ patch, _ = formPatch("remove", strconv.Itoa(i), adapterURL, instance, reqLogger)
+ break
+ }
+ }
+ patchErr := r.client.Patch(context.TODO(), prom, client.ConstantPatch(types.JSONPatchType, patch))
+ if patchErr != nil {
+ reqLogger.Error(patchErr, "Unable to process patch to prometheus")
+ return patchErr
+ }
+ reqLogger.Info("Patch merged, remote write removed")
+
+ //remove Finalizer after deletion
+ if remoteconfigutils.Contains(instance.GetFinalizers(), remoteconfigutils.RemoteConfigFinalizer) {
+ if err := removeFinalizer(reqLogger, instance); err != nil {
+ return err
+ }
+ err := r.client.Update(context.TODO(), instance)
+ if err != nil {
+ reqLogger.Error(err, "Unable to update instance")
+ return err
+ }
+ }
+ return nil
+}
+
+func addFinalizer(reqlogger logr.Logger, instance *onapv1alpha1.PrometheusRemoteEndpoint) error {
+ reqlogger.Info("Adding finalizer for the PrometheusRemoteEndpoint")
+ instance.SetFinalizers(append(instance.GetFinalizers(), remoteconfigutils.RemoteConfigFinalizer))
+ return nil
+}
+
+func removeFinalizer(reqlogger logr.Logger, instance *onapv1alpha1.PrometheusRemoteEndpoint) error {
+ reqlogger.Info("Removing finalizer for the PrometheusRemoteEndpoint")
+ instance.SetFinalizers(remoteconfigutils.Remove(instance.GetFinalizers(), remoteconfigutils.RemoteConfigFinalizer))
+ return nil
+}
+
+func formPatch(method string, index string, adapterURL string, instance *onapv1alpha1.PrometheusRemoteEndpoint, reqLogger logr.Logger) ([]byte, error) {
+ var err error
+ var mergePatch []byte
+ path := "/spec/remoteWrite/" + index
+ mergePatch, err = json.Marshal(map[string]interface{}{
+ "op": method,
+ "path": path,
+ "value": map[string]interface{}{
+ "url": adapterURL,
+ "remoteTimeout": instance.Spec.RemoteTimeout,
+ },
+ })
+ if err != nil {
+ reqLogger.Error(err, "Unable to form patch")
+ return nil, err
+ }
+ prependMergePatch := append([]byte{91}, mergePatch...)
+ finalMergePatch := append(prependMergePatch, 93)
+ return finalMergePatch, nil
+}
diff --git a/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/utils/remoteconfigutils.go b/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/utils/remoteconfigutils.go
new file mode 100644
index 00000000..8508a8e6
--- /dev/null
+++ b/vnfs/DAaaS/microservices/remote-config-operator/pkg/controller/utils/remoteconfigutils.go
@@ -0,0 +1,77 @@
+/*
+Copyright 2019 Intel Corporation.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package utils
+
+import (
+ "context"
+ "fmt"
+ "os"
+ onapv1alpha1 "remote-config-operator/pkg/apis/onap/v1alpha1"
+ "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+ defaultWatchLabel = "remote=m3db1"
+ WatchLabelsEnvVar = "WATCH_LABELS"
+ RemoteConfigFinalizer = "finalizer.remoteConfig.onap.org"
+)
+
+// GetWatchLabels returns the labels the operator should be watching for changes
+func GetWatchLabels() (string, error) {
+ labelSelector, found := os.LookupEnv(WatchLabelsEnvVar)
+ if !found {
+ return defaultWatchLabel, fmt.Errorf("%s must be set", WatchLabelsEnvVar)
+ }
+ return labelSelector, nil
+}
+
+// GetPrometheusRemoteEndpoint returns the prometheusRemoteEndpoint instance in the namespace ns
+func GetPrometheusRemoteEndpoint(rc client.Client, ns string) (*onapv1alpha1.PrometheusRemoteEndpoint, error) {
+ // Get the PrometheusRemoteEndpoint instance in current namespace to rebuild conf.
+ preList := &onapv1alpha1.PrometheusRemoteEndpointList{}
+ preOpts := []client.ListOption{
+ client.InNamespace("edge1"),
+ client.MatchingLabels{"remote": "m3db1"},
+ }
+
+ err := rc.List(context.TODO(), preList, preOpts...)
+ if err != nil {
+ return nil, err
+ }
+ if preList.Items == nil || len(preList.Items) == 0 {
+ return nil, err
+ }
+ prometheusRemoteEndpoint := &preList.Items[0]
+ return prometheusRemoteEndpoint, nil
+}
+
+// Contains checks if a string is contained in a list of strings
+func Contains(list []string, s string) bool {
+ for _, v := range list {
+ if v == s {
+ return true
+ }
+ }
+ return false
+}
+
+// Remove checks and removes a string from a list of strings
+func Remove(list []string, s string) []string {
+ for i, v := range list {
+ if v == s {
+ list = append(list[:i], list[i+1:]...)
+ }
+ }
+ return list
+}