-
Notifications
You must be signed in to change notification settings - Fork 289
/
controller_manager_context.go
108 lines (82 loc) · 3.2 KB
/
controller_manager_context.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
/*
Copyright 2019 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 context
import (
"context"
"sync"
"time"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/record"
)
// ControllerManagerContext is the context of the controller that owns the
// controllers.
type ControllerManagerContext struct {
context.Context
// Namespace is the namespace in which the resource is located responsible
// for running the controller manager.
Namespace string
// Name is the name of the controller manager.
Name string
// LeaderElectionID is the information used to identify the object
// responsible for synchronizing leader election.
LeaderElectionID string
// LeaderElectionNamespace is the namespace in which the LeaderElection
// object is located.
LeaderElectionNamespace string
// WatchNamespace is the namespace the controllers watch for changes. If
// no value is specified then all namespaces are watched.
WatchNamespace string
// Client is the controller manager's client.
Client client.Client
// Logger is the controller manager's logger.
Logger logr.Logger
// Recorder is used to record events.
Recorder record.Recorder
// Scheme is the controller manager's API scheme.
Scheme *runtime.Scheme
// MaxConcurrentReconciles is the maximum number of recocnile requests this
// controller will receive concurrently.
MaxConcurrentReconciles int
// Username is the username for the account used to access remote vSphere
// endpoints.
Username string
// Password is the password for the account used to access remote vSphere
// endpoints.
Password string
// EnableKeepAlive is a session feature to enable keep alive handler
// for better load management on vSphere api server
EnableKeepAlive bool
// KeepAliveDuration is the idle time interval in between send() requests
// in keepalive handler
KeepAliveDuration time.Duration
// NetworkProvider is the network provider used by Supervisor based clusters
NetworkProvider string
genericEventCache sync.Map
}
// String returns ControllerManagerName.
func (c *ControllerManagerContext) String() string {
return c.Name
}
// GetGenericEventChannelFor returns a generic event channel for a resource
// specified by the provided GroupVersionKind.
func (c *ControllerManagerContext) GetGenericEventChannelFor(gvk schema.GroupVersionKind) chan event.GenericEvent {
if val, ok := c.genericEventCache.Load(gvk); ok {
return val.(chan event.GenericEvent)
}
val, _ := c.genericEventCache.LoadOrStore(gvk, make(chan event.GenericEvent))
return val.(chan event.GenericEvent)
}