-
Notifications
You must be signed in to change notification settings - Fork 98
/
configmap.go
46 lines (36 loc) · 1.37 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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package merger
import (
"fmt"
"github.com/DataDog/datadog-operator/controllers/datadogagent/dependencies"
"github.com/DataDog/datadog-operator/pkg/kubernetes"
corev1 "k8s.io/api/core/v1"
)
// ConfigMapManager is used to manage configmap resources.
type ConfigMapManager interface {
AddConfigMap(name, namespace string, data map[string]string) error
}
// NewConfigMapManager returns a new ConfigMapManager instance
func NewConfigMapManager(store dependencies.StoreClient) ConfigMapManager {
manager := &configMapManagerImpl{
store: store,
}
return manager
}
// configMapManagerImpl is used to manage configmap resources.
type configMapManagerImpl struct {
store dependencies.StoreClient
}
// AddConfigMap creates or updates a kubernetes network policy
func (m *configMapManagerImpl) AddConfigMap(name, namespace string, data map[string]string) error {
obj, _ := m.store.GetOrCreate(kubernetes.ConfigMapKind, namespace, name)
cm, ok := obj.(*corev1.ConfigMap)
if !ok {
return fmt.Errorf("unable to get from the store the ConfigMap %s/%s", namespace, name)
}
cm.Data = data
return m.store.AddOrUpdate(kubernetes.ConfigMapKind, cm)
}