/
configmap.go
55 lines (42 loc) · 1.6 KB
/
configmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Copyright 2019 Red Hat, Inc.
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 controllerutils
import (
"context"
"fmt"
"github.com/openshift/certman-operator/config"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// GetConfig retrieves config from kubernetes and returns a ConfigMap object.
func GetConfig(kubeClient client.Client) (*corev1.ConfigMap, error) {
cm := &corev1.ConfigMap{}
err := kubeClient.Get(context.TODO(), types.NamespacedName{Name: config.OperatorName, Namespace: config.OperatorNamespace}, cm)
if err != nil {
return nil, err
}
return cm, nil
}
// After instantiating a configmap object, GetDefaultNotificationEmailAddress validates
// if there is a default email address present or not.
func GetDefaultNotificationEmailAddress(kubeClient client.Client) (string, error) {
cm, err := GetConfig(kubeClient)
if err != nil {
return "", err
}
if cm.Data["default_notification_email_address"] == "" {
return "", fmt.Errorf("Default notification email not found in configmap.")
}
return cm.Data["default_notification_email_address"], nil
}