Skip to content

Commit 52c56b2

Browse files
ryanzhang-ossRyan Zhang
andauthored
adjust log levels to make production debug reliable (#307)
Co-authored-by: Ryan Zhang <zhangryan@microsoft.com>
1 parent b085bed commit 52c56b2

File tree

14 files changed

+95
-95
lines changed

14 files changed

+95
-95
lines changed

pkg/authtoken/providers/azure/azure_msi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (a *azureAuthTokenProvider) FetchToken(ctx context.Context) (interfaces.Aut
3636
token := interfaces.AuthToken{}
3737
opts := &azidentity.ManagedIdentityCredentialOptions{ID: azidentity.ClientID(a.clientID)}
3838

39-
klog.V(5).InfoS("FetchToken", "client ID", a.clientID)
39+
klog.V(2).InfoS("FetchToken", "client ID", a.clientID)
4040
credential, err := azidentity.NewManagedIdentityCredential(opts)
4141
if err != nil {
4242
return token, errors.Wrap(err, "failed to create managed identity cred")
@@ -46,7 +46,7 @@ func (a *azureAuthTokenProvider) FetchToken(ctx context.Context) (interfaces.Aut
4646
func(err error) bool {
4747
return ctx.Err() == nil
4848
}, func() error {
49-
klog.V(5).InfoS("GetToken start", "credential", credential)
49+
klog.V(2).InfoS("GetToken start", "credential", credential)
5050
azToken, err = credential.GetToken(ctx, policy.TokenRequestOptions{
5151
Scopes: []string{aksScope},
5252
})

pkg/authtoken/providers/secret/k8s_secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func New(secretName, namespace string) (interfaces.AuthTokenProvider, error) {
4343
}
4444

4545
func (s *secretAuthTokenProvider) FetchToken(ctx context.Context) (interfaces.AuthToken, error) {
46-
klog.V(3).InfoS("fetching token from secret", "secret", klog.KRef(s.secretName, s.secretNamespace))
46+
klog.V(2).InfoS("fetching token from secret", "secret", klog.KRef(s.secretName, s.secretNamespace))
4747
token := interfaces.AuthToken{}
4848
secret, err := s.fetchSecret(ctx)
4949
if err != nil {

pkg/authtoken/token_refresher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var (
4545
)
4646

4747
func (at *Refresher) callFetchToken(ctx context.Context) (interfaces.AuthToken, error) {
48-
klog.V(5).InfoS("FetchToken start")
48+
klog.V(2).InfoS("FetchToken start")
4949
deadline := time.Now().Add(DefaultRefreshDuration)
5050
fetchTokenContext, cancel := context.WithDeadline(ctx, deadline)
5151
defer cancel()
@@ -67,7 +67,7 @@ func (at *Refresher) RefreshToken(ctx context.Context) error {
6767
continue
6868
}
6969

70-
klog.V(5).InfoS("WriteToken start")
70+
klog.V(2).InfoS("WriteToken start")
7171
err = at.writer.WriteToken(token)
7272
if err != nil {
7373
klog.ErrorS(err, "Failed to WriteToken")

pkg/authtoken/token_writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ func (w *Writer) WriteToken(token interfaces.AuthToken) error {
5555
if err != nil {
5656
return errors.Wrap(err, "cannot write the refresh token")
5757
}
58-
klog.V(3).InfoS("token has been saved to the file successfully")
58+
klog.V(2).InfoS("token has been saved to the file successfully")
5959
return nil
6060
}

pkg/controllers/clusterresourceplacement/cluster_selector.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ func (r *Reconciler) selectClusters(placement *fleetv1alpha1.ClusterResourcePlac
3535
if err != nil {
3636
return nil, err
3737
}
38-
klog.V(4).InfoS("we select all the available clusters in the fleet without a policy",
38+
klog.V(2).InfoS("we select all the available clusters in the fleet without a policy",
3939
"placement", placement.Name, "clusters", clusterNames)
4040
return
4141
}
4242
// a fix list of clusters set
4343
if len(placement.Spec.Policy.ClusterNames) != 0 {
44-
klog.V(4).InfoS("use the cluster names provided as the list of cluster we select",
44+
klog.V(2).InfoS("use the cluster names provided as the list of cluster we select",
4545
"placement", placement.Name, "clusters", placement.Spec.Policy.ClusterNames)
4646
clusterNames, err = r.getClusters(placement.Spec.Policy.ClusterNames)
4747
if err != nil {
@@ -56,7 +56,7 @@ func (r *Reconciler) selectClusters(placement *fleetv1alpha1.ClusterResourcePlac
5656
if err != nil {
5757
return nil, err
5858
}
59-
klog.V(4).InfoS("we select all the available clusters in the fleet without a cluster affinity",
59+
klog.V(2).InfoS("we select all the available clusters in the fleet without a cluster affinity",
6060
"placement", placement.Name, "clusters", clusterNames)
6161
return
6262
}
@@ -71,13 +71,13 @@ func (r *Reconciler) selectClusters(placement *fleetv1alpha1.ClusterResourcePlac
7171
if err != nil {
7272
return nil, errors.Wrap(err, fmt.Sprintf("selector = %v", clusterSelector.LabelSelector))
7373
}
74-
klog.V(4).InfoS("selector matches some cluster", "clusterNum", len(matchClusters), "placement", placement.Name, "selector", clusterSelector.LabelSelector)
74+
klog.V(2).InfoS("selector matches some cluster", "clusterNum", len(matchClusters), "placement", placement.Name, "selector", clusterSelector.LabelSelector)
7575
for _, clusterName := range matchClusters {
7676
selectedClusters[clusterName] = true
7777
}
7878
}
7979
for cluster := range selectedClusters {
80-
klog.V(4).InfoS("matched a cluster", "cluster", cluster, "placement", placement.Name)
80+
klog.V(2).InfoS("matched a cluster", "cluster", cluster, "placement", placement.Name)
8181
clusterNames = append(clusterNames, cluster)
8282
}
8383
return clusterNames, nil

pkg/controllers/clusterresourceplacement/placement_controller.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, key controller.QueueKey) (ct
9292
return r.removeAllWorks(ctx, placementOld)
9393
}
9494

95-
klog.V(3).InfoS("Successfully selected clusters", "placement", placementOld.Name, "number of clusters", len(selectedClusters))
95+
klog.V(2).InfoS("Successfully selected clusters", "placement", placementOld.Name, "number of clusters", len(selectedClusters))
9696

9797
// select the new resources and record the result in the placementNew status
9898
manifests, scheduleErr := r.selectResources(ctx, placementNew)
@@ -107,7 +107,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, key controller.QueueKey) (ct
107107
klog.V(2).InfoS("No resources match the placement", "placement", placeRef)
108108
return r.removeAllWorks(ctx, placementOld)
109109
}
110-
klog.V(3).InfoS("Successfully selected resources", "placement", placementOld.Name, "number of resources", len(manifests))
110+
klog.V(2).InfoS("Successfully selected resources", "placement", placementOld.Name, "number of resources", len(manifests))
111111

112112
// persist union of the all the selected resources and clusters between placementNew and placementOld so that we won't
113113
// get orphaned resource/cluster if the reconcile loops stops between work creation and the placement status persisted
@@ -118,7 +118,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, key controller.QueueKey) (ct
118118
_ = r.Client.Status().Update(ctx, placementOld, client.FieldOwner(utils.PlacementFieldManagerName))
119119
return ctrl.Result{}, scheduleErr
120120
}
121-
klog.V(3).InfoS("Successfully persisted the intermediate scheduling result", "placement", placementOld.Name,
121+
klog.V(2).InfoS("Successfully persisted the intermediate scheduling result", "placement", placementOld.Name,
122122
"totalClusters", totalCluster, "totalResources", totalResources)
123123
// pick up the new version so placementNew can continue to update
124124
placementNew.SetResourceVersion(placementOld.GetResourceVersion())
@@ -131,7 +131,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, key controller.QueueKey) (ct
131131
_ = r.Client.Status().Update(ctx, placementOld, client.FieldOwner(utils.PlacementFieldManagerName))
132132
return ctrl.Result{}, scheduleErr
133133
}
134-
klog.V(3).InfoS("Successfully scheduled work resources", "placement", placementOld.Name, "number of clusters", len(selectedClusters))
134+
klog.V(2).InfoS("Successfully scheduled work resources", "placement", placementOld.Name, "number of clusters", len(selectedClusters))
135135

136136
// go through the existing cluster list and remove work from no longer scheduled clusters.
137137
removed, scheduleErr := r.removeStaleWorks(ctx, placementNew.GetName(), placementOld.Status.TargetClusters, placementNew.Status.TargetClusters)
@@ -144,7 +144,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, key controller.QueueKey) (ct
144144
_ = r.Client.Status().Update(ctx, placementOld, client.FieldOwner(utils.PlacementFieldManagerName))
145145
return ctrl.Result{}, scheduleErr
146146
}
147-
klog.V(3).InfoS("Successfully removed work resources from previously selected clusters", "placement", placementOld.Name, "removed clusters", removed)
147+
klog.V(2).InfoS("Successfully removed work resources from previously selected clusters", "placement", placementOld.Name, "removed clusters", removed)
148148

149149
// the schedule has succeeded, so we now can use the placementNew status that contains all the newly selected cluster and resources
150150
r.updatePlacementScheduledCondition(placementNew, nil)
@@ -157,7 +157,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, key controller.QueueKey) (ct
157157
_ = r.Client.Status().Update(ctx, placementNew, client.FieldOwner(utils.PlacementFieldManagerName))
158158
return ctrl.Result{}, applyErr
159159
}
160-
klog.V(3).InfoS("Successfully collected work resources status from all selected clusters",
160+
klog.V(2).InfoS("Successfully collected work resources status from all selected clusters",
161161
"placement", placementOld.Name, "number of clusters", len(selectedClusters), "hasPending", hasPending,
162162
"numberFailedPlacement", len(placementNew.Status.FailedResourcePlacements))
163163

@@ -182,7 +182,7 @@ func (r *Reconciler) removeAllWorks(ctx context.Context, placement *fleetv1alpha
182182
klog.ErrorS(removeErr, "failed to remove all the work resources from previously selected clusters", "placement", placeRef)
183183
return ctrl.Result{}, removeErr
184184
}
185-
klog.V(3).InfoS("Successfully removed work resources from previously selected clusters",
185+
klog.V(2).InfoS("Successfully removed work resources from previously selected clusters",
186186
"placement", placeRef, "number of removed clusters", removed)
187187
placement.Status.TargetClusters = nil
188188
placement.Status.SelectedResources = nil
@@ -262,7 +262,7 @@ func (r *Reconciler) updatePlacementScheduledCondition(placement *fleetv1alpha1.
262262
ObservedGeneration: placement.Generation,
263263
})
264264
if schedCond == nil || schedCond.Status != metav1.ConditionTrue {
265-
klog.V(3).InfoS("successfully scheduled all selected resources to their clusters", "placement", placementRef)
265+
klog.V(2).InfoS("successfully scheduled all selected resources to their clusters", "placement", placementRef)
266266
r.Recorder.Event(placement, corev1.EventTypeNormal, "ResourceScheduled", "successfully scheduled all selected resources to their clusters")
267267
}
268268
} else {
@@ -293,7 +293,7 @@ func (r *Reconciler) updatePlacementAppliedCondition(placement *fleetv1alpha1.Cl
293293
Message: "Successfully applied resources to member clusters",
294294
ObservedGeneration: placement.Generation,
295295
})
296-
klog.V(3).InfoS("successfully applied all selected resources", "placement", placementRef)
296+
klog.V(2).InfoS("successfully applied all selected resources", "placement", placementRef)
297297
if preAppliedCond == nil || preAppliedCond.Status != metav1.ConditionTrue {
298298
r.Recorder.Event(placement, corev1.EventTypeNormal, "ResourceApplied", "successfully applied all selected resources")
299299
}
@@ -305,7 +305,7 @@ func (r *Reconciler) updatePlacementAppliedCondition(placement *fleetv1alpha1.Cl
305305
Message: applyErr.Error(),
306306
ObservedGeneration: placement.Generation,
307307
})
308-
klog.V(3).InfoS("Some selected resources are still waiting to be applied", "placement", placementRef)
308+
klog.V(2).InfoS("Some selected resources are still waiting to be applied", "placement", placementRef)
309309
if preAppliedCond == nil || preAppliedCond.Status == metav1.ConditionTrue {
310310
r.Recorder.Event(placement, corev1.EventTypeWarning, "ResourceApplyPending", "Some applied resources are now waiting to be applied to the member cluster")
311311
}
@@ -318,7 +318,7 @@ func (r *Reconciler) updatePlacementAppliedCondition(placement *fleetv1alpha1.Cl
318318
Message: applyErr.Error(),
319319
ObservedGeneration: placement.Generation,
320320
})
321-
klog.V(3).InfoS("failed to apply some selected resources", "placement", placementRef)
321+
klog.V(2).InfoS("failed to apply some selected resources", "placement", placementRef)
322322
if preAppliedCond == nil || preAppliedCond.Status != metav1.ConditionFalse {
323323
r.Recorder.Event(placement, corev1.EventTypeWarning, "ResourceApplyFailed", "failed to apply some selected resources")
324324
}

pkg/controllers/clusterresourceplacement/resource_selector.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (r *Reconciler) selectResources(ctx context.Context, placement *fleetv1alph
4747
Namespace: unstructuredObj.GetNamespace(),
4848
}
4949
placement.Status.SelectedResources = append(placement.Status.SelectedResources, res)
50-
klog.V(4).InfoS("selected one resource ", "placement", placement.Name, "resource", res)
50+
klog.V(2).InfoS("selected one resource ", "placement", placement.Name, "resource", res)
5151
manifest, err := generateManifest(unstructuredObj)
5252
if err != nil {
5353
return nil, err
@@ -68,7 +68,7 @@ func (r *Reconciler) gatherSelectedResource(ctx context.Context, placement *flee
6868
}
6969

7070
if r.DisabledResourceConfig.IsResourceDisabled(gvk) {
71-
klog.V(4).InfoS("Skip select resource", "group version kind", gvk.String())
71+
klog.V(2).InfoS("Skip select resource", "group version kind", gvk.String())
7272
continue
7373
}
7474
var objs []runtime.Object
@@ -105,7 +105,7 @@ func (r *Reconciler) gatherSelectedResource(ctx context.Context, placement *flee
105105

106106
// fetchClusterScopedResources retrieve the objects based on the selector.
107107
func (r *Reconciler) fetchClusterScopedResources(ctx context.Context, selector fleetv1alpha1.ClusterResourceSelector, placeName string) ([]runtime.Object, error) {
108-
klog.V(4).InfoS("start to fetch the cluster scoped resources by the selector", "selector", selector)
108+
klog.V(2).InfoS("start to fetch the cluster scoped resources by the selector", "selector", selector)
109109
gk := schema.GroupKind{
110110
Group: selector.Group,
111111
Kind: selector.Kind,
@@ -138,7 +138,7 @@ func (r *Reconciler) fetchClusterScopedResources(ctx context.Context, selector f
138138
uObj := obj.DeepCopyObject().(*unstructured.Unstructured)
139139
if uObj.GetDeletionTimestamp() != nil {
140140
// skip a to be deleted namespace
141-
klog.V(4).InfoS("skip the deleting cluster scoped resources by the selector",
141+
klog.V(2).InfoS("skip the deleting cluster scoped resources by the selector",
142142
"selector", selector, "placeName", placeName, "resource name", uObj.GetName())
143143
return []runtime.Object{}, nil
144144
}
@@ -165,7 +165,7 @@ func (r *Reconciler) fetchClusterScopedResources(ctx context.Context, selector f
165165
uObj := objects[i].DeepCopyObject().(*unstructured.Unstructured)
166166
if uObj.GetDeletionTimestamp() != nil {
167167
// skip a to be deleted namespace
168-
klog.V(4).InfoS("skip the deleting cluster scoped resources by the selector",
168+
klog.V(2).InfoS("skip the deleting cluster scoped resources by the selector",
169169
"selector", selector, "placeName", placeName, "resource name", uObj.GetName())
170170
continue
171171
}
@@ -177,7 +177,7 @@ func (r *Reconciler) fetchClusterScopedResources(ctx context.Context, selector f
177177

178178
// fetchNamespaceResources retrieve all the objects for a ClusterResourceSelector that is for namespace.
179179
func (r *Reconciler) fetchNamespaceResources(ctx context.Context, selector fleetv1alpha1.ClusterResourceSelector, placeName string) ([]runtime.Object, error) {
180-
klog.V(4).InfoS("start to fetch the namespace resources by the selector", "selector", selector)
180+
klog.V(2).InfoS("start to fetch the namespace resources by the selector", "selector", selector)
181181
var resources []runtime.Object
182182

183183
if len(selector.Name) != 0 {
@@ -229,7 +229,7 @@ func (r *Reconciler) fetchAllResourcesInOneNamespace(ctx context.Context, namesp
229229
return nil, errors.New(fmt.Sprintf("namespace %s is not allowed to propagate", namespaceName))
230230
}
231231

232-
klog.V(4).InfoS("start to fetch all the resources inside a namespace", "namespace", namespaceName)
232+
klog.V(2).InfoS("start to fetch all the resources inside a namespace", "namespace", namespaceName)
233233
// select the namespace object itself
234234
obj, err := r.InformerManager.Lister(utils.NamespaceGVR).Get(namespaceName)
235235
if err != nil {
@@ -239,7 +239,7 @@ func (r *Reconciler) fetchAllResourcesInOneNamespace(ctx context.Context, namesp
239239
nameSpaceObj := obj.DeepCopyObject().(*unstructured.Unstructured)
240240
if nameSpaceObj.GetDeletionTimestamp() != nil {
241241
// skip a to be deleted namespace
242-
klog.V(4).InfoS("skip the deleting namespace resources by the selector",
242+
klog.V(2).InfoS("skip the deleting namespace resources by the selector",
243243
"placeName", placeName, "namespace", namespaceName)
244244
return resources, nil
245245
}
@@ -285,7 +285,7 @@ func (r *Reconciler) shouldSelectResource(gvr schema.GroupVersionResource) bool
285285
}
286286
for _, gvk := range gvks {
287287
if r.DisabledResourceConfig.IsResourceDisabled(gvk) {
288-
klog.V(4).InfoS("Skip watch resource", "group version kind", gvk.String())
288+
klog.V(2).InfoS("Skip watch resource", "group version kind", gvk.String())
289289
return false
290290
}
291291
}

pkg/controllers/clusterresourceplacement/work_propagation.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (r *Reconciler) scheduleWork(ctx context.Context, placement *fleetv1alpha1.
100100
}
101101
existingHash := curWork.GetAnnotations()[SpecHashAnnotationKey]
102102
if existingHash == specHash || reflect.DeepEqual(curWork.Spec.Workload.Manifests, workerSpec.Workload.Manifests) {
103-
klog.V(4).InfoS("skip updating work spec as its identical",
103+
klog.V(2).InfoS("skip updating work spec as its identical",
104104
"member cluster namespace", memberClusterNsName, "work name", workName, "number of manifests", len(manifests))
105105
continue
106106
}
@@ -113,13 +113,13 @@ func (r *Reconciler) scheduleWork(ctx context.Context, placement *fleetv1alpha1.
113113
allErr = append(allErr, errors.Wrap(updateErr, fmt.Sprintf("failed to update the work obj %s in namespace %s", workName, memberClusterNsName)))
114114
continue
115115
}
116-
klog.V(3).InfoS("updated work spec with manifests",
116+
klog.V(2).InfoS("updated work spec with manifests",
117117
"member cluster namespace", memberClusterNsName, "work name", workName, "number of manifests", len(manifests))
118118
}
119119
if changed {
120120
klog.V(2).InfoS("Applied all work to the selected cluster namespaces", "placement", klog.KObj(placement), "number of clusters", len(memberClusterNames))
121121
} else {
122-
klog.V(3).InfoS("Nothing new to apply for the cluster resource placement", "placement", klog.KObj(placement), "number of clusters", len(memberClusterNames))
122+
klog.V(2).InfoS("Nothing new to apply for the cluster resource placement", "placement", klog.KObj(placement), "number of clusters", len(memberClusterNames))
123123
}
124124

125125
return apiErrors.NewAggregate(allErr)
@@ -166,7 +166,7 @@ func (r *Reconciler) collectAllManifestsStatus(placement *fleetv1alpha1.ClusterR
166166
work, err := r.getResourceBinding(memberClusterNsName, workName)
167167
if err != nil {
168168
if apierrors.IsNotFound(err) {
169-
klog.V(3).InfoS("the work change has not shown up in the cache yet",
169+
klog.V(2).InfoS("the work change has not shown up in the cache yet",
170170
"work", klog.KRef(memberClusterNsName, workName), "cluster", cluster)
171171
hasPending = true
172172
continue
@@ -177,19 +177,19 @@ func (r *Reconciler) collectAllManifestsStatus(placement *fleetv1alpha1.ClusterR
177177
appliedCond := meta.FindStatusCondition(work.Status.Conditions, workapi.ConditionTypeApplied)
178178
if appliedCond == nil {
179179
hasPending = true
180-
klog.V(4).InfoS("the work is never picked up by the member cluster",
180+
klog.V(2).InfoS("the work is never picked up by the member cluster",
181181
"work", klog.KObj(work), "cluster", cluster)
182182
continue
183183
}
184184
if appliedCond.ObservedGeneration < work.GetGeneration() {
185185
hasPending = true
186-
klog.V(4).InfoS("the update of the work is not picked up by the member cluster yet",
186+
klog.V(2).InfoS("the update of the work is not picked up by the member cluster yet",
187187
"work", klog.KObj(work), "cluster", cluster, "work generation", work.GetGeneration(),
188188
"applied generation", appliedCond.ObservedGeneration)
189189
continue
190190
}
191191
if appliedCond.Status == metav1.ConditionTrue {
192-
klog.V(4).InfoS("the work is applied successfully by the member cluster",
192+
klog.V(2).InfoS("the work is applied successfully by the member cluster",
193193
"work", klog.KObj(work), "cluster", cluster)
194194
continue
195195
}
@@ -204,7 +204,7 @@ func (r *Reconciler) collectAllManifestsStatus(placement *fleetv1alpha1.ClusterR
204204
appliedCond = meta.FindStatusCondition(manifestCondition.Conditions, workapi.ConditionTypeApplied)
205205
// collect if there is an explicit fail
206206
if appliedCond != nil && appliedCond.Status != metav1.ConditionTrue {
207-
klog.V(3).InfoS("find a failed to apply manifest", "member cluster namespace", memberClusterNsName,
207+
klog.V(2).InfoS("find a failed to apply manifest", "member cluster namespace", memberClusterNsName,
208208
"manifest name", manifestCondition.Identifier.Name, "group", manifestCondition.Identifier.Group,
209209
"version", manifestCondition.Identifier.Version, "kind", manifestCondition.Identifier.Kind)
210210
placement.Status.FailedResourcePlacements = append(placement.Status.FailedResourcePlacements, fleetv1alpha1.FailedResourcePlacement{

0 commit comments

Comments
 (0)