@@ -68,8 +68,9 @@ func main() {
68
68
// Setup a Manager, note that this not yet engages clusters, only makes them available.
69
69
entryLog .Info ("Setting up manager" )
70
70
provider := & KindClusterProvider {
71
- log : log .Log .WithName ("kind-cluster-provider" ),
72
- clusters : map [string ]cluster.Cluster {},
71
+ log : log .Log .WithName ("kind-cluster-provider" ),
72
+ clusters : map [string ]cluster.Cluster {},
73
+ cancelFns : map [string ]context.CancelFunc {},
73
74
}
74
75
mgr , err := manager .New (
75
76
cfg ,
@@ -85,18 +86,18 @@ func main() {
85
86
func (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
86
87
log := log .FromContext (ctx )
87
88
88
- cluster , err := mgr .GetCluster (ctx , req .ClusterName )
89
+ cl , err := mgr .GetCluster (ctx , req .ClusterName )
89
90
if err != nil {
90
91
return reconcile.Result {}, err
91
92
}
92
- client := cluster .GetClient ()
93
+ client := cl .GetClient ()
93
94
94
95
// Retrieve the pod from the cluster.
95
96
pod := & corev1.Pod {}
96
97
if err := client .Get (ctx , req .NamespacedName , pod ); err != nil {
97
98
return reconcile.Result {}, err
98
99
}
99
- log .Info ("Reconciling pod" , "name" , pod .Name , "uuid" , pod .UID )
100
+ log .Info ("Reconciling pod" , "cluster" , cl . Name (), "ns" , pod . GetNamespace (), " name" , pod .Name , "uuid" , pod .UID )
100
101
101
102
// Print any annotations that start with fleet.
102
103
for k , v := range pod .Labels {
@@ -170,6 +171,7 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
170
171
}
171
172
k .lock .RLock ()
172
173
if _ , ok := k .clusters [clusterName ]; ok {
174
+ k .lock .RUnlock ()
173
175
continue
174
176
}
175
177
k .lock .RUnlock ()
@@ -185,7 +187,8 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
185
187
k .log .Info ("failed to create rest config" , "error" , err )
186
188
return false , nil // keep going
187
189
}
188
- cl , err := cluster .New (cfg , k .Options ... )
190
+ clOptions := append ([]cluster.Option {cluster .WithName (clusterName )}, k .Options ... )
191
+ cl , err := cluster .New (cfg , clOptions ... )
189
192
if err != nil {
190
193
k .log .Info ("failed to create cluster" , "error" , err )
191
194
return false , nil // keep going
@@ -245,6 +248,8 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
245
248
delete (k .clusters , name )
246
249
delete (k .cancelFns , name )
247
250
k .lock .Unlock ()
251
+
252
+ k .log .Info ("Cluster removed" , "cluster" , name )
248
253
}
249
254
}
250
255
0 commit comments