@@ -68,8 +68,9 @@ func main() {
6868	// Setup a Manager, note that this not yet engages clusters, only makes them available. 
6969	entryLog .Info ("Setting up manager" )
7070	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 {},
7374	}
7475	mgr , err  :=  manager .New (
7576		cfg ,
@@ -85,18 +86,18 @@ func main() {
8586		func (ctx  context.Context , req  ctrl.Request ) (ctrl.Result , error ) {
8687			log  :=  log .FromContext (ctx )
8788
88- 			cluster , err  :=  mgr .GetCluster (ctx , req .ClusterName )
89+ 			cl , err  :=  mgr .GetCluster (ctx , req .ClusterName )
8990			if  err  !=  nil  {
9091				return  reconcile.Result {}, err 
9192			}
92- 			client  :=  cluster .GetClient ()
93+ 			client  :=  cl .GetClient ()
9394
9495			// Retrieve the pod from the cluster. 
9596			pod  :=  & corev1.Pod {}
9697			if  err  :=  client .Get (ctx , req .NamespacedName , pod ); err  !=  nil  {
9798				return  reconcile.Result {}, err 
9899			}
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 )
100101
101102			// Print any annotations that start with fleet. 
102103			for  k , v  :=  range  pod .Labels  {
@@ -170,6 +171,7 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
170171			}
171172			k .lock .RLock ()
172173			if  _ , ok  :=  k .clusters [clusterName ]; ok  {
174+ 				k .lock .RUnlock ()
173175				continue 
174176			}
175177			k .lock .RUnlock ()
@@ -185,7 +187,8 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
185187				k .log .Info ("failed to create rest config" , "error" , err )
186188				return  false , nil  // keep going 
187189			}
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 ... )
189192			if  err  !=  nil  {
190193				k .log .Info ("failed to create cluster" , "error" , err )
191194				return  false , nil  // keep going 
@@ -245,6 +248,8 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
245248				delete (k .clusters , name )
246249				delete (k .cancelFns , name )
247250				k .lock .Unlock ()
251+ 
252+ 				k .log .Info ("Cluster removed" , "cluster" , name )
248253			}
249254		}
250255
0 commit comments