Skip to content

Commit

Permalink
Fleet example changes
Browse files Browse the repository at this point in the history
Signed-off-by: Iván Álvarez <ivanape@inditex.com>
  • Loading branch information
ivanape committed May 24, 2024
1 parent 56e0c2b commit 9ce51b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 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(fmt.Sprintf("Retrieved pod %s:>%s/%s", cl.Name(), pod.Namespace, pod.Name))

// Print any annotations that start with fleet.
for k, v := range pod.Labels {
Expand Down Expand Up @@ -185,7 +186,10 @@ 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...)
// Copy provider options and append the cluster name
clOptions := append(k.Options, cluster.WithName(clusterName))

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
2 changes: 1 addition & 1 deletion pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,9 @@ func (cm *controllerManager) Engage(ctx context.Context, cl cluster.Cluster) err
// be reentrant via noop
cm.engagedClustersLock.RLock()
if _, ok := cm.engagedClusters[cl.Name()]; ok {
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 9ce51b8

Please sign in to comment.