-
Notifications
You must be signed in to change notification settings - Fork 107
/
chartmuseum.go
124 lines (101 loc) · 3.76 KB
/
chartmuseum.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package harbor
import (
"context"
"net/url"
goharborv1alpha2 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha2"
harbormetav1 "github.com/goharbor/harbor-operator/apis/meta/v1alpha1"
"github.com/goharbor/harbor-operator/controllers"
"github.com/goharbor/harbor-operator/pkg/graph"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (r *Reconciler) AddChartMuseumConfigurations(ctx context.Context, harbor *goharborv1alpha2.Harbor, tlsIssuer InternalTLSIssuer) (ChartMuseumInternalCertificate, error) {
if harbor.Spec.ChartMuseum == nil {
return nil, nil
}
certificate, err := r.AddChartMuseumInternalCertificate(ctx, harbor, tlsIssuer)
if err != nil {
return nil, errors.Wrap(err, "certificate")
}
return certificate, nil
}
type ChartMuseumInternalCertificate graph.Resource
func (r *Reconciler) AddChartMuseumInternalCertificate(ctx context.Context, harbor *goharborv1alpha2.Harbor, tlsIssuer InternalTLSIssuer) (ChartMuseumInternalCertificate, error) {
cert, err := r.GetInternalTLSCertificate(ctx, harbor, harbormetav1.ChartMuseumTLS)
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 ChartMuseumInternalCertificate(certRes), nil
}
const (
ChartMuseumAuthenticationUsername = "chart_controller"
)
type ChartMuseum graph.Resource
func (r *Reconciler) AddChartMuseum(ctx context.Context, harbor *goharborv1alpha2.Harbor, certificate ChartMuseumInternalCertificate, coreSecret CoreSecret) (ChartMuseum, error) {
if harbor.Spec.ChartMuseum == nil {
return nil, nil
}
chartmuseum, err := r.GetChartMuseum(ctx, harbor)
if err != nil {
return nil, errors.Wrap(err, "get")
}
chartmuseumRes, err := r.AddBasicResource(ctx, chartmuseum, certificate, coreSecret)
return ChartMuseum(chartmuseumRes), errors.Wrap(err, "add")
}
func (r *Reconciler) GetChartMuseum(ctx context.Context, harbor *goharborv1alpha2.Harbor) (*goharborv1alpha2.ChartMuseum, error) {
name := r.NormalizeName(ctx, harbor.GetName())
namespace := harbor.GetNamespace()
basicAuthRef := r.NormalizeName(ctx, harbor.GetName(), controllers.Core.String(), "secret")
debug := harbor.Spec.LogLevel == harbormetav1.HarborDebug
redis := harbor.Spec.RedisConnection(harbormetav1.ChartMuseumRedis)
publicURL, err := url.Parse(harbor.Spec.ExternalURL)
if err != nil {
return nil, errors.Wrap(err, "cannot parseexternalURL")
}
chartServerURL := ""
if harbor.Spec.ChartMuseum.AbsoluteURL {
chartServerURL = publicURL.String()
}
publicURL.Path += "/chartrepo"
maxStorageObjects := int64(0)
parallelLimit := int32(0)
tls := harbor.Spec.InternalTLS.GetComponentTLSSpec(r.GetInternalTLSCertificateSecretName(ctx, harbor, harbormetav1.ChartMuseumTLS))
return &goharborv1alpha2.ChartMuseum{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: goharborv1alpha2.ChartMuseumSpec{
ComponentSpec: harbor.Spec.ChartMuseum.ComponentSpec,
Authentication: goharborv1alpha2.ChartMuseumAuthSpec{
AnonymousGet: false,
BasicAuthRef: basicAuthRef,
},
Server: goharborv1alpha2.ChartMuseumServerSpec{
TLS: tls,
},
Cache: goharborv1alpha2.ChartMuseumCacheSpec{
Redis: &redis,
},
Chart: goharborv1alpha2.ChartMuseumChartSpec{
AllowOvewrite: &varTrue,
Storage: goharborv1alpha2.ChartMuseumChartStorageSpec{
ChartMuseumChartStorageDriverSpec: r.ChartMuseumStorage(ctx, harbor),
MaxStorageObjects: &maxStorageObjects,
},
Index: goharborv1alpha2.ChartMuseumChartIndexSpec{
ParallelLimit: ¶llelLimit,
},
URL: chartServerURL,
},
Log: goharborv1alpha2.ChartMuseumLogSpec{
Debug: debug,
JSON: true,
},
},
}, nil
}