This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 532
/
controller.go
118 lines (103 loc) · 4.11 KB
/
controller.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
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package managed
import (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/kubernetes-sigs/federation-v2/pkg/apis/core/typeconfig"
"github.com/kubernetes-sigs/federation-v2/pkg/controller/dnsendpoint"
"github.com/kubernetes-sigs/federation-v2/pkg/controller/federatedcluster"
"github.com/kubernetes-sigs/federation-v2/pkg/controller/ingressdns"
"github.com/kubernetes-sigs/federation-v2/pkg/controller/schedulingmanager"
"github.com/kubernetes-sigs/federation-v2/pkg/controller/servicedns"
"github.com/kubernetes-sigs/federation-v2/pkg/controller/status"
"github.com/kubernetes-sigs/federation-v2/pkg/controller/sync"
"github.com/kubernetes-sigs/federation-v2/pkg/controller/util"
"github.com/kubernetes-sigs/federation-v2/test/common"
)
// ControllerFixture manages a federation controller for testing.
type ControllerFixture struct {
stopChan chan struct{}
}
// NewSyncControllerFixture initializes a new sync controller fixture.
func NewSyncControllerFixture(tl common.TestLogger, controllerConfig *util.ControllerConfig, typeConfig typeconfig.Interface, namespacePlacement *metav1.APIResource) *ControllerFixture {
f := &ControllerFixture{
stopChan: make(chan struct{}),
}
err := sync.StartFederationSyncController(controllerConfig, f.stopChan, typeConfig, namespacePlacement)
if err != nil {
tl.Fatalf("Error starting sync controller: %v", err)
}
if typeConfig.GetEnableStatus() {
err := status.StartFederationStatusController(controllerConfig, f.stopChan, typeConfig)
if err != nil {
tl.Fatalf("Error starting status controller: %v", err)
}
}
return f
}
// NewServiceDNSControllerFixture initializes a new service-dns controller fixture.
func NewServiceDNSControllerFixture(tl common.TestLogger, config *util.ControllerConfig) *ControllerFixture {
f := &ControllerFixture{
stopChan: make(chan struct{}),
}
err := servicedns.StartController(config, f.stopChan)
if err != nil {
tl.Fatalf("Error starting service dns controller: %v", err)
}
err = dnsendpoint.StartServiceDNSEndpointController(config, f.stopChan)
if err != nil {
tl.Fatalf("Error starting service dns endpoint controller: %v", err)
}
return f
}
// NewIngressDNSControllerFixture initializes a new ingress-dns controller fixture.
func NewIngressDNSControllerFixture(tl common.TestLogger, config *util.ControllerConfig) *ControllerFixture {
f := &ControllerFixture{
stopChan: make(chan struct{}),
}
err := ingressdns.StartController(config, f.stopChan)
if err != nil {
tl.Fatalf("Error starting ingress dns controller: %v", err)
}
err = dnsendpoint.StartIngressDNSEndpointController(config, f.stopChan)
if err != nil {
tl.Fatalf("Error starting ingress dns endpoint controller: %v", err)
}
return f
}
// NewClusterControllerFixture initializes a new cluster controller fixture.
func NewClusterControllerFixture(config *util.ControllerConfig) *ControllerFixture {
f := &ControllerFixture{
stopChan: make(chan struct{}),
}
monitorPeriod := 1 * time.Second
federatedcluster.StartClusterController(config, f.stopChan, monitorPeriod)
return f
}
func NewSchedulerControllerFixture(tl common.TestLogger, config *util.ControllerConfig) (*ControllerFixture, *schedulingmanager.SchedulerController) {
f := &ControllerFixture{
stopChan: make(chan struct{}),
}
controller, err := schedulingmanager.StartSchedulerController(config, f.stopChan)
if err != nil {
tl.Fatalf("Error starting scheduler controller: %v", err)
}
return f, controller
}
func (f *ControllerFixture) TearDown(tl common.TestLogger) {
if f.stopChan != nil {
close(f.stopChan)
f.stopChan = nil
}
}