/
types.go
138 lines (119 loc) · 4.55 KB
/
types.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
SPDX-License-Identifier: Apache-2.0
Copyright Contributors to the Submariner project.
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 controller
import (
"sync"
"time"
"github.com/submariner-io/admiral/pkg/federate"
"github.com/submariner-io/admiral/pkg/syncer"
"github.com/submariner-io/admiral/pkg/syncer/broker"
"github.com/submariner-io/admiral/pkg/watcher"
"github.com/submariner-io/admiral/pkg/workqueue"
"k8s.io/apimachinery/pkg/api/meta"
k8slabels "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
mcsv1a1 "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"
)
const (
exportFailedReason = "ExportFailed"
typeConflictReason = "ConflictingType"
portConflictReason = "ConflictingPorts"
)
var BrokerResyncPeriod = time.Minute * 2
type EndpointSliceListerFn func(selector k8slabels.Selector) []runtime.Object
type converter struct {
scheme *runtime.Scheme
}
type Controller struct {
clusterID string
globalnetEnabled bool
namespace string
serviceExportClient *ServiceExportClient
serviceExportSyncer syncer.Interface
endpointSliceController *EndpointSliceController
serviceSyncer syncer.Interface
serviceImportController *ServiceImportController
localServiceImportFederator federate.Federator
}
type AgentSpecification struct {
ClusterID string
Namespace string
Verbosity int
GlobalnetEnabled bool `split_words:"true"`
Uninstall bool
HaltOnCertError bool `split_words:"true"`
Debug bool
}
type ServiceImportAggregator struct {
clusterID string
converter converter
brokerClient dynamic.Interface
brokerNamespace string
}
// The ServiceImportController encapsulates two resource syncers; one that watches for local cluster ServiceImports
// from the submariner namespace and creates/updates the aggregated ServiceImport on the broker; the other that syncs
// aggregated ServiceImports from the broker to the local service namespace. It also creates a ServiceEndpointSliceController.
type ServiceImportController struct {
localClient dynamic.Interface
restMapper meta.RESTMapper
serviceImportAggregator *ServiceImportAggregator
serviceImportMigrator *ServiceImportMigrator
serviceExportClient *ServiceExportClient
localSyncer syncer.Interface
remoteSyncer syncer.Interface
endpointControllers sync.Map
clusterID string
localNamespace string
converter converter
globalIngressIPCache *globalIngressIPCache
localLHEndpointSliceLister EndpointSliceListerFn
}
// Each ServiceEndpointSliceController watches for the EndpointSlices that backs a Service and have a ServiceImport.
// It creates LH EndpointSlices corresponding to service EndpointSlices that are distributed to other clusters.
type ServiceEndpointSliceController struct {
clusterID string
serviceName string
serviceNamespace string
serviceImportSpec *mcsv1a1.ServiceImportSpec
publishNotReadyAddresses string
stopCh chan struct{}
stopOnce sync.Once
localClient dynamic.ResourceInterface
ingressIPClient dynamic.NamespaceableResourceInterface
globalIngressIPCache *globalIngressIPCache
epsSyncer syncer.Interface
federator federate.Federator
}
// EndpointSliceController encapsulates a syncer that syncs EndpointSlices to and from that broker.
type EndpointSliceController struct {
clusterID string
syncer *broker.Syncer
serviceImportAggregator *ServiceImportAggregator
serviceExportClient *ServiceExportClient
serviceSyncer syncer.Interface
conflictCheckWorkQueue workqueue.Interface
}
type ServiceExportClient struct {
dynamic.NamespaceableResourceInterface
converter
localSyncer syncer.Interface
}
type globalIngressIPCache struct {
sync.Mutex
byService sync.Map
byPod sync.Map
byEndpoints sync.Map
watcher watcher.Interface
}