@@ -23,6 +23,7 @@ import (
2323
2424 "github.com/blang/semver"
2525 "github.com/pkg/errors"
26+ oteltrace "go.opentelemetry.io/otel/trace"
2627 corev1 "k8s.io/api/core/v1"
2728 apierrors "k8s.io/apimachinery/pkg/api/errors"
2829 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -46,6 +47,7 @@ import (
4647 "sigs.k8s.io/cluster-api/feature"
4748 "sigs.k8s.io/cluster-api/internal/contract"
4849 "sigs.k8s.io/cluster-api/internal/util/ssa"
50+ traceutil "sigs.k8s.io/cluster-api/internal/util/trace"
4951 "sigs.k8s.io/cluster-api/util"
5052 "sigs.k8s.io/cluster-api/util/annotations"
5153 "sigs.k8s.io/cluster-api/util/collections"
@@ -75,6 +77,7 @@ type KubeadmControlPlaneReconciler struct {
7577 controller controller.Controller
7678 recorder record.EventRecorder
7779 Tracker * remote.ClusterCacheTracker
80+ TraceProvider oteltrace.TracerProvider
7881
7982 EtcdDialTimeout time.Duration
8083 EtcdCallTimeout time.Duration
@@ -94,6 +97,10 @@ type KubeadmControlPlaneReconciler struct {
9497}
9598
9699func (r * KubeadmControlPlaneReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
100+ if r .TraceProvider == nil {
101+ r .TraceProvider = oteltrace .NewNoopTracerProvider ()
102+ }
103+ tr := traceutil .Reconciler (r , r .TraceProvider , "kubeadmcontrolplane" , "KubeadmControlPlane" )
97104 c , err := ctrl .NewControllerManagedBy (mgr ).
98105 For (& controlplanev1.KubeadmControlPlane {}).
99106 Owns (& clusterv1.Machine {}).
@@ -108,7 +115,7 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
108115 predicates .ClusterUnpausedAndInfrastructureReady (ctrl .LoggerFrom (ctx )),
109116 ),
110117 ),
111- ).Build (r )
118+ ).Build (tr )
112119 if err != nil {
113120 return errors .Wrap (err , "failed setting up with a controller manager" )
114121 }
@@ -300,6 +307,9 @@ func (r *KubeadmControlPlaneReconciler) initControlPlaneScope(ctx context.Contex
300307}
301308
302309func patchKubeadmControlPlane (ctx context.Context , patchHelper * patch.Helper , kcp * controlplanev1.KubeadmControlPlane ) error {
310+ ctx , span := traceutil .Start (ctx , "patchKubeadmControlPlane" )
311+ defer span .End ()
312+
303313 // Always update the readyCondition by summarizing the state of other conditions.
304314 conditions .SetSummary (kcp ,
305315 conditions .WithConditions (
@@ -331,6 +341,9 @@ func patchKubeadmControlPlane(ctx context.Context, patchHelper *patch.Helper, kc
331341
332342// reconcile handles KubeadmControlPlane reconciliation.
333343func (r * KubeadmControlPlaneReconciler ) reconcile (ctx context.Context , controlPlane * internal.ControlPlane ) (res ctrl.Result , reterr error ) {
344+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.reconcile" )
345+ defer span .End ()
346+
334347 log := ctrl .LoggerFrom (ctx )
335348 log .Info ("Reconcile KubeadmControlPlane" )
336349
@@ -503,6 +516,9 @@ func (r *KubeadmControlPlaneReconciler) reconcileClusterCertificates(ctx context
503516// The implementation does not take non-control plane workloads into consideration. This may or may not change in the future.
504517// Please see https://github.com/kubernetes-sigs/cluster-api/issues/2064.
505518func (r * KubeadmControlPlaneReconciler ) reconcileDelete (ctx context.Context , controlPlane * internal.ControlPlane ) (ctrl.Result , error ) {
519+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.reconcileDelete" )
520+ defer span .End ()
521+
506522 log := ctrl .LoggerFrom (ctx )
507523 log .Info ("Reconcile KubeadmControlPlane deletion" )
508524
@@ -590,6 +606,9 @@ func (r *KubeadmControlPlaneReconciler) ClusterToKubeadmControlPlane(_ context.C
590606// Otherwise, fields would be co-owned by our "old" "manager" and "capi-kubeadmcontrolplane" and then we would not be
591607// able to e.g. drop labels and annotations.
592608func (r * KubeadmControlPlaneReconciler ) syncMachines (ctx context.Context , controlPlane * internal.ControlPlane ) error {
609+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.syncMachines" )
610+ defer span .End ()
611+
593612 patchHelpers := map [string ]* patch.Helper {}
594613 for machineName := range controlPlane .Machines {
595614 m := controlPlane .Machines [machineName ]
@@ -673,6 +692,9 @@ func (r *KubeadmControlPlaneReconciler) syncMachines(ctx context.Context, contro
673692// reconcileControlPlaneConditions is responsible of reconciling conditions reporting the status of static pods and
674693// the status of the etcd cluster.
675694func (r * KubeadmControlPlaneReconciler ) reconcileControlPlaneConditions (ctx context.Context , controlPlane * internal.ControlPlane ) (ctrl.Result , error ) {
695+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.reconcileControlPlaneConditions" )
696+ defer span .End ()
697+
676698 // If the cluster is not yet initialized, there is no way to connect to the workload cluster and fetch information
677699 // for updating conditions. Return early.
678700 if ! controlPlane .KCP .Status .Initialized {
@@ -702,6 +724,9 @@ func (r *KubeadmControlPlaneReconciler) reconcileControlPlaneConditions(ctx cont
702724//
703725// NOTE: this func uses KCP conditions, it is required to call reconcileControlPlaneConditions before this.
704726func (r * KubeadmControlPlaneReconciler ) reconcileEtcdMembers (ctx context.Context , controlPlane * internal.ControlPlane ) (ctrl.Result , error ) {
727+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.reconcileEtcdMembers" )
728+ defer span .End ()
729+
705730 log := ctrl .LoggerFrom (ctx )
706731
707732 // If etcd is not managed by KCP this is a no-op.
@@ -754,6 +779,9 @@ func (r *KubeadmControlPlaneReconciler) reconcileEtcdMembers(ctx context.Context
754779}
755780
756781func (r * KubeadmControlPlaneReconciler ) reconcileCertificateExpiries (ctx context.Context , controlPlane * internal.ControlPlane ) (ctrl.Result , error ) {
782+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.reconcileCertificateExpiries" )
783+ defer span .End ()
784+
757785 log := ctrl .LoggerFrom (ctx )
758786
759787 // Return if there are no KCP-owned control-plane machines.
@@ -824,6 +852,9 @@ func (r *KubeadmControlPlaneReconciler) reconcileCertificateExpiries(ctx context
824852}
825853
826854func (r * KubeadmControlPlaneReconciler ) adoptMachines (ctx context.Context , kcp * controlplanev1.KubeadmControlPlane , machines collections.Machines , cluster * clusterv1.Cluster ) error {
855+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.adoptMachines" )
856+ defer span .End ()
857+
827858 // We do an uncached full quorum read against the KCP to avoid re-adopting Machines the garbage collector just intentionally orphaned
828859 // See https://github.com/kubernetes/kubernetes/issues/42639
829860 uncached := controlplanev1.KubeadmControlPlane {}
@@ -901,6 +932,9 @@ func (r *KubeadmControlPlaneReconciler) adoptMachines(ctx context.Context, kcp *
901932}
902933
903934func (r * KubeadmControlPlaneReconciler ) adoptOwnedSecrets (ctx context.Context , kcp * controlplanev1.KubeadmControlPlane , currentOwner * bootstrapv1.KubeadmConfig , clusterName string ) error {
935+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.adoptOwnedSecrets" )
936+ defer span .End ()
937+
904938 secrets := corev1.SecretList {}
905939 if err := r .Client .List (ctx , & secrets , client .InNamespace (kcp .Namespace ), client.MatchingLabels {clusterv1 .ClusterNameLabel : clusterName }); err != nil {
906940 return errors .Wrap (err , "error finding secrets for adoption" )
@@ -937,6 +971,8 @@ func (r *KubeadmControlPlaneReconciler) adoptOwnedSecrets(ctx context.Context, k
937971
938972// ensureCertificatesOwnerRef ensures an ownerReference to the owner is added on the Secrets holding certificates.
939973func (r * KubeadmControlPlaneReconciler ) ensureCertificatesOwnerRef (ctx context.Context , certificates secret.Certificates , owner metav1.OwnerReference ) error {
974+ ctx , span := traceutil .Start (ctx , "kubeadmcontrolplane.Reconciler.ensureCertificatesOwnerRef" )
975+ defer span .End ()
940976 for _ , c := range certificates {
941977 if c .Secret == nil {
942978 continue
0 commit comments