/
resources.go
71 lines (58 loc) · 2.09 KB
/
resources.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
package notarysigner
import (
"context"
goharborv1 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1beta1"
harbormetav1 "github.com/goharbor/harbor-operator/apis/meta/v1alpha1"
serrors "github.com/goharbor/harbor-operator/pkg/controller/errors"
"github.com/goharbor/harbor-operator/pkg/graph"
"github.com/goharbor/harbor-operator/pkg/resources"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (r *Reconciler) NewEmpty(_ context.Context) resources.Resource {
return &goharborv1.NotarySigner{}
}
func (r *Reconciler) AddResources(ctx context.Context, resource resources.Resource) error {
notary, ok := resource.(*goharborv1.NotarySigner)
if !ok {
return serrors.UnrecoverrableError(errors.Errorf("%+v", resource), serrors.OperatorReason, "unable to add resource")
}
service, err := r.GetService(ctx, notary)
if err != nil {
return errors.Wrap(err, "cannot get service")
}
_, err = r.Controller.AddServiceToManage(ctx, service)
if err != nil {
return errors.Wrapf(err, "cannot add service %s", service.GetName())
}
var storageSecret graph.Resource
if notary.Spec.Storage.Postgres.PasswordRef != "" {
storageSecret, err = r.AddExternalTypedSecret(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: notary.Spec.Storage.Postgres.PasswordRef,
Namespace: notary.GetNamespace(),
},
}, harbormetav1.SecretTypePostgresql)
if err != nil {
return errors.Wrap(err, "cannot add migration secret")
}
}
configMap, err := r.GetConfigMap(ctx, notary)
if err != nil {
return errors.Wrap(err, "cannot get configMap")
}
configMapResource, err := r.Controller.AddConfigMapToManage(ctx, configMap, storageSecret)
if err != nil {
return errors.Wrapf(err, "cannot add configMap %s", configMap.GetName())
}
deployment, err := r.GetDeployment(ctx, notary)
if err != nil {
return errors.Wrap(err, "cannot get deployment")
}
_, err = r.Controller.AddDeploymentToManage(ctx, deployment, configMapResource)
if err != nil {
return errors.Wrapf(err, "cannot add deployment %s", deployment.GetName())
}
return nil
}