Skip to content

Commit

Permalink
Merge pull request #1 from ivanape/sttts-cluster-support
Browse files Browse the repository at this point in the history
✨Fleet example changes
  • Loading branch information
sttts committed May 28, 2024
2 parents 56e0c2b + a9d3c00 commit d51d3e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions examples/fleet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ func main() {
// Setup a Manager, note that this not yet engages clusters, only makes them available.
entryLog.Info("Setting up manager")
provider := &KindClusterProvider{
log: log.Log.WithName("kind-cluster-provider"),
clusters: map[string]cluster.Cluster{},
log: log.Log.WithName("kind-cluster-provider"),
clusters: map[string]cluster.Cluster{},
cancelFns: map[string]context.CancelFunc{},
}
mgr, err := manager.New(
cfg,
Expand All @@ -85,18 +86,18 @@ func main() {
func(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)

cluster, err := mgr.GetCluster(ctx, req.ClusterName)
cl, err := mgr.GetCluster(ctx, req.ClusterName)
if err != nil {
return reconcile.Result{}, err
}
client := cluster.GetClient()
client := cl.GetClient()

// Retrieve the pod from the cluster.
pod := &corev1.Pod{}
if err := client.Get(ctx, req.NamespacedName, pod); err != nil {
return reconcile.Result{}, err
}
log.Info("Reconciling pod", "name", pod.Name, "uuid", pod.UID)
log.Info("Reconciling pod", "cluster", cl.Name(), "ns", pod.GetNamespace(), "name", pod.Name, "uuid", pod.UID)

// Print any annotations that start with fleet.
for k, v := range pod.Labels {
Expand Down Expand Up @@ -170,6 +171,7 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
}
k.lock.RLock()
if _, ok := k.clusters[clusterName]; ok {
k.lock.RUnlock()
continue
}
k.lock.RUnlock()
Expand All @@ -185,7 +187,8 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
k.log.Info("failed to create rest config", "error", err)
return false, nil // keep going
}
cl, err := cluster.New(cfg, k.Options...)
clOptions := append([]cluster.Option{cluster.WithName(clusterName)}, k.Options...)
cl, err := cluster.New(cfg, clOptions...)
if err != nil {
k.log.Info("failed to create cluster", "error", err)
return false, nil // keep going
Expand Down Expand Up @@ -245,6 +248,8 @@ func (k *KindClusterProvider) Run(ctx context.Context, mgr manager.Manager) erro
delete(k.clusters, name)
delete(k.cancelFns, name)
k.lock.Unlock()

k.log.Info("Cluster removed", "cluster", name)
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ func (cm *controllerManager) Engage(ctx context.Context, cl cluster.Cluster) err
cm.engagedClustersLock.RUnlock()
return nil
}
cm.engagedClustersLock.RUnlock()

// add early because any engaged runnable could access it
cm.engagedClustersLock.Lock()
Expand Down

0 comments on commit d51d3e4

Please sign in to comment.