forked from goharbor/harbor-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configs.go
77 lines (65 loc) · 2.06 KB
/
configs.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package registry
import (
"context"
"crypto/sha256"
"fmt"
goharborv1 "github.com/plotly/harbor-operator/apis/goharbor.io/v1beta1"
conftemplate "github.com/plotly/harbor-operator/pkg/config/template"
"github.com/plotly/harbor-operator/pkg/resources/checksum"
"github.com/plotly/harbor-operator/pkg/utils/strings"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
ConfigName = "config.yml"
RegistryCtlName = "registryctl"
)
func (r *Reconciler) GetConfigMap(ctx context.Context, registry *goharborv1.Registry) (*corev1.ConfigMap, error) {
templateConfig, err := r.ConfigStore.GetItemValue(conftemplate.ConfigTemplateKey)
if err != nil {
return nil, errors.Wrap(err, "cannot get template")
}
content, err := r.GetTemplatedConfig(ctx, templateConfig, registry)
if err != nil {
return nil, err
}
name := r.NormalizeName(ctx, registry.GetName())
namespace := registry.GetNamespace()
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: map[string]string{
checksum.GetStaticID("template"): fmt.Sprintf("%x", sha256.Sum256([]byte(templateConfig))),
},
},
BinaryData: map[string][]byte{
ConfigName: content,
},
}, nil
}
func (r *Reconciler) GetCtlConfigMap(ctx context.Context, registryCtl *goharborv1.RegistryController) (*corev1.ConfigMap, error) {
templateConfig, err := r.ConfigStore.GetItemValue(CtlConfigTemplateKey)
if err != nil {
return nil, errors.Wrap(err, "cannot get template")
}
content, err := r.GetTemplatedConfig(ctx, templateConfig, registryCtl)
if err != nil {
return nil, err
}
name := strings.NormalizeName(registryCtl.GetName(), RegistryCtlName)
namespace := registryCtl.GetNamespace()
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: map[string]string{
checksum.GetStaticID("template"): fmt.Sprintf("%x", sha256.Sum256([]byte(templateConfig))),
},
},
BinaryData: map[string][]byte{
ConfigName: content,
},
}, nil
}