-
Notifications
You must be signed in to change notification settings - Fork 107
/
harbor.go
80 lines (68 loc) · 2.69 KB
/
harbor.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
package harbor
import (
"context"
"time"
goharborv1alpha2 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha2"
"github.com/goharbor/harbor-operator/pkg/config"
commonCtrl "github.com/goharbor/harbor-operator/pkg/controller"
"github.com/goharbor/harbor-operator/pkg/event-filter/class"
certv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha2"
"github.com/ovh/configstore"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller"
)
const (
DefaultRequeueWait = 2 * time.Second
)
// Reconciler reconciles a Harbor object.
type Reconciler struct {
*commonCtrl.Controller
}
// +kubebuilder:rbac:groups=goharbor.io,resources=harbors,verbs=get;list;watch
// +kubebuilder:rbac:groups=goharbor.io,resources=harbors/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=goharbor.io,resources=chartmuseums;cores;jobservices;notaryservers;notarysigners;portals;registries;registrycontrollers;trivies,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=cert-manager.io,resources=issuers;certificates,verbs=get;list;watch;create;update;patch;delete
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
err := r.Controller.SetupWithManager(ctx, mgr)
if err != nil {
return errors.Wrap(err, "cannot setup common controller")
}
className, err := r.ConfigStore.GetItemValue(config.HarborClassKey)
if err != nil {
return errors.Wrap(err, "cannot get harbor class")
}
concurrentReconcile, err := r.ConfigStore.GetItemValueInt(config.ReconciliationKey)
if err != nil {
return errors.Wrap(err, "cannot get concurrent reconcile")
}
return ctrl.NewControllerManagedBy(mgr).
WithEventFilter(&class.Filter{
ClassName: className,
}).
For(r.NewEmpty(ctx)).
Owns(&goharborv1alpha2.ChartMuseum{}).
Owns(&goharborv1alpha2.Core{}).
Owns(&goharborv1alpha2.JobService{}).
Owns(&goharborv1alpha2.Portal{}).
Owns(&goharborv1alpha2.Registry{}).
Owns(&goharborv1alpha2.RegistryController{}).
Owns(&goharborv1alpha2.NotaryServer{}).
Owns(&goharborv1alpha2.NotarySigner{}).
Owns(&corev1.Secret{}).
Owns(&certv1.Issuer{}).
Owns(&certv1.Certificate{}).
Owns(&netv1.Ingress{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: int(concurrentReconcile),
}).
Complete(r)
}
func New(ctx context.Context, name string, configStore *configstore.Store) (commonCtrl.Reconciler, error) {
r := &Reconciler{}
r.Controller = commonCtrl.NewController(ctx, name, r, configStore)
return r, nil
}