-
Notifications
You must be signed in to change notification settings - Fork 107
/
portal.go
63 lines (49 loc) · 1.94 KB
/
portal.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
package harbor
import (
"context"
goharborv1alpha2 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha2"
harbormetav1 "github.com/goharbor/harbor-operator/apis/meta/v1alpha1"
"github.com/goharbor/harbor-operator/pkg/graph"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type Portal graph.Resource
func (r *Reconciler) AddPortal(ctx context.Context, harbor *goharborv1alpha2.Harbor, tlsIssuer InternalTLSIssuer) (PortalInternalCertificate, Portal, error) {
cert, err := r.AddPortalInternalCertificate(ctx, harbor, tlsIssuer)
if err != nil {
return nil, nil, errors.Wrap(err, "certificate")
}
portal, err := r.GetPortal(ctx, harbor)
if err != nil {
return nil, nil, errors.Wrap(err, "cannot get portal")
}
portalRes, err := r.AddBasicResource(ctx, portal, cert)
return cert, portalRes, errors.Wrap(err, "cannot add portal")
}
type PortalInternalCertificate graph.Resource
func (r *Reconciler) AddPortalInternalCertificate(ctx context.Context, harbor *goharborv1alpha2.Harbor, tlsIssuer InternalTLSIssuer) (PortalInternalCertificate, error) {
cert, err := r.GetInternalTLSCertificate(ctx, harbor, harbormetav1.PortalTLS)
if err != nil {
return nil, errors.Wrap(err, "get")
}
certRes, err := r.Controller.AddCertificateToManage(ctx, cert, tlsIssuer)
if err != nil {
return nil, errors.Wrap(err, "add")
}
return PortalInternalCertificate(certRes), nil
}
func (r *Reconciler) GetPortal(ctx context.Context, harbor *goharborv1alpha2.Harbor) (*goharborv1alpha2.Portal, error) {
name := r.NormalizeName(ctx, harbor.GetName())
namespace := harbor.GetNamespace()
tls := harbor.Spec.InternalTLS.GetComponentTLSSpec(r.GetInternalTLSCertificateSecretName(ctx, harbor, harbormetav1.PortalTLS))
return &goharborv1alpha2.Portal{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: goharborv1alpha2.PortalSpec{
ComponentSpec: harbor.Spec.Portal,
TLS: tls,
},
}, nil
}