Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Fleet example changes #1

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an anti-pattern for structural logging. Just add "ns", pod.Namespace.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)


// 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...)
ivanape marked this conversation as resolved.
Show resolved Hide resolved
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()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great find! but don't we need both? RUnlock on return, and RUnlock for the else case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I missed that. I have also update the fleet example with the same error here.


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