2 Copyright 2019 Intel Corporation.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software
8 distributed under the License is distributed on an "AS IS" BASIS,
9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 See the License for the specific language governing permissions and
11 limitations under the License.
20 onapv1alpha1 "remote-config-operator/pkg/apis/onap/v1alpha1"
21 "sigs.k8s.io/controller-runtime/pkg/client"
25 defaultWatchLabel = "remote=m3db1"
26 WatchLabelsEnvVar = "WATCH_LABELS"
27 RemoteConfigFinalizer = "finalizer.remoteConfig.onap.org"
30 // GetWatchLabels returns the labels the operator should be watching for changes
31 func GetWatchLabels() (string, error) {
32 labelSelector, found := os.LookupEnv(WatchLabelsEnvVar)
34 return defaultWatchLabel, fmt.Errorf("%s must be set", WatchLabelsEnvVar)
36 return labelSelector, nil
39 // GetPrometheusRemoteEndpoint returns the prometheusRemoteEndpoint instance in the namespace ns
40 func GetPrometheusRemoteEndpoint(rc client.Client, ns string) (*onapv1alpha1.PrometheusRemoteEndpoint, error) {
41 // Get the PrometheusRemoteEndpoint instance in current namespace to rebuild conf.
42 preList := &onapv1alpha1.PrometheusRemoteEndpointList{}
43 preOpts := []client.ListOption{
44 client.InNamespace("edge1"),
45 client.MatchingLabels{"remote": "m3db1"},
48 err := rc.List(context.TODO(), preList, preOpts...)
52 if preList.Items == nil || len(preList.Items) == 0 {
55 prometheusRemoteEndpoint := &preList.Items[0]
56 return prometheusRemoteEndpoint, nil
59 // Contains checks if a string is contained in a list of strings
60 func Contains(list []string, s string) bool {
61 for _, v := range list {
69 // Remove checks and removes a string from a list of strings
70 func Remove(list []string, s string) []string {
71 for i, v := range list {
73 list = append(list[:i], list[i+1:]...)