Skip to content

Commit

Permalink
Refine logs with upper case (#3404)
Browse files Browse the repository at this point in the history
Signed-off-by: Lan Luo <luola@vmware.com>
  • Loading branch information
luolanzone committed Mar 24, 2022
1 parent 3c88bc2 commit c8a3544
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 56 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -43,7 +43,7 @@ func (v *memberClusterAnnounceValidator) Handle(ctx context.Context, req admissi
memberClusterAnnounce := &multiclusterv1alpha1.MemberClusterAnnounce{}
e := v.decoder.Decode(req, memberClusterAnnounce)
if e != nil {
klog.ErrorS(e, "error while decoding")
klog.ErrorS(e, "Error while decoding")
return admission.Errored(http.StatusBadRequest, e)
}

Expand Down
Expand Up @@ -25,7 +25,7 @@ import (
// CommonArea is an interface that provides access to the common area of a ClusterSet.
// Common Area of a ClusterSet is a Namespace in the leader cluster.
type CommonArea interface {
// Client grants read/write to the namespace of the cluster that is backing this CommonArea.
// Client grants read/write to the Namespace of the cluster that is backing this CommonArea.
client.Client

// GetClusterID returns the clusterID of the cluster accessed by this CommonArea.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -139,7 +139,7 @@ func NewRemoteCommonArea(clusterID common.ClusterID, clusterSetID common.Cluster
Namespace: clusterSetNamespace,
})
if err != nil {
klog.ErrorS(err, "error creating manager for RemoteCommonArea", "Cluster", clusterID)
klog.ErrorS(err, "Error creating manager for RemoteCommonArea", "Cluster", clusterID)
return nil, err
}

Expand Down Expand Up @@ -221,9 +221,8 @@ func (r *remoteCommonArea) SendMemberAnnounce() error {
// Add timestamp to force update on MemberClusterAnnounce. Leader cluster requires
// periodic updates to detect connectivity. Without this, no-op updates will be ignored.
localClusterMemberAnnounce.Annotations[TimestampAnnotationKey] = time.Now().String()
// do an update
if err := r.Update(context.TODO(), &localClusterMemberAnnounce, &client.UpdateOptions{}); err != nil {
klog.ErrorS(err, "error updating MemberClusterAnnounce", "Cluster", r.GetClusterID())
klog.ErrorS(err, "Error updating MemberClusterAnnounce", "Cluster", r.GetClusterID())
return err
}
} else {
Expand Down Expand Up @@ -341,7 +340,7 @@ func (r *remoteCommonArea) Start() (context.CancelFunc, error) {

func (r *remoteCommonArea) doMemberAnnounce() {
if err := r.SendMemberAnnounce(); err != nil {
klog.ErrorS(err, "error writing member announce", "Cluster", r.GetClusterID())
klog.ErrorS(err, "Error writing member announce", "Cluster", r.GetClusterID())
r.updateRemoteCommonAreaStatus(false, err)
} else {
r.updateRemoteCommonAreaStatus(true, nil)
Expand Down Expand Up @@ -383,7 +382,7 @@ func (r *remoteCommonArea) StartWatching() error {
)

if err := resImportReconciler.SetupWithManager(r.ClusterManager); err != nil {
klog.V(2).ErrorS(err, "error creating ResourceImport controller for RemoteCommonArea", "Cluster", r.ClusterID)
klog.V(2).ErrorS(err, "Error creating ResourceImport controller for RemoteCommonArea", "Cluster", r.ClusterID)
return fmt.Errorf("error creating ResourceImport controller for RemoteCommonArea: %v", err)
}

Expand All @@ -396,7 +395,7 @@ func (r *remoteCommonArea) StartWatching() error {
// the leader again, it starts the Manager again.
err := r.ClusterManager.Start(stopCtx)
if err != nil {
klog.ErrorS(err, "error starting ClusterManager for RemoteCommonArea", "Cluster", r.ClusterID)
klog.ErrorS(err, "Error starting ClusterManager for RemoteCommonArea", "Cluster", r.ClusterID)
}
klog.InfoS("Stopping ClusterManager for RemoteCommonArea", "Cluster", r.ClusterID)
}()
Expand Down
Expand Up @@ -115,7 +115,7 @@ func (r *ResourceImportReconciler) Reconcile(ctx context.Context, req ctrl.Reque
resImp = resImpObj.(multiclusterv1alpha1.ResourceImport)
} else {
// stale_controller will reconcile and clean up MC Service/ServiceImport, so it's ok to return nil here
klog.ErrorS(err, "no cached data for ResourceImport", "resourceimport", req.NamespacedName.String())
klog.ErrorS(err, "No cached data for ResourceImport", "resourceimport", req.NamespacedName.String())
return ctrl.Result{}, nil
}
}
Expand Down Expand Up @@ -158,22 +158,22 @@ func (r *ResourceImportReconciler) handleResImpUpdateForService(ctx context.Cont
// Here we will skip creating derived MC Service when a Service with the same name
// already exists but it not previously created by Importer.
if _, ok := svc.Annotations[common.AntreaMCServiceAnnotation]; !ok {
err := errors.New("unable to import Service which conflicts with existing one")
klog.ErrorS(err, "", "service", klog.KObj(svc))
err := errors.New("the Service conflicts with existing one")
klog.ErrorS(err, "Unable to import Service", "service", klog.KObj(svc))
return ctrl.Result{}, err
}
}
svcObj := getMCService(resImp)
if svcNotFound {
err := r.localClusterClient.Create(ctx, svcObj, &client.CreateOptions{})
if err != nil {
klog.ErrorS(err, "failed to create Service", "service", klog.KObj(svcObj))
klog.ErrorS(err, "Failed to create Service", "service", klog.KObj(svcObj))
return ctrl.Result{}, err
}
if err = r.localClusterClient.Get(ctx, svcName, svc); err != nil {
// Ignore the error here, and requeue the event again when both Service
// and ServiceImport are created later
klog.ErrorS(err, "failed to get latest imported Service", "service", klog.KObj(svc))
klog.ErrorS(err, "Failed to get latest imported Service", "service", klog.KObj(svc))
}
}

Expand All @@ -191,7 +191,7 @@ func (r *ResourceImportReconciler) handleResImpUpdateForService(ctx context.Cont
if svcImpNotFound {
err := r.localClusterClient.Create(ctx, svcImpObj, &client.CreateOptions{})
if err != nil {
klog.ErrorS(err, "failed to create ServiceImport", "serviceimport", klog.KObj(svcImpObj))
klog.ErrorS(err, "Failed to create ServiceImport", "serviceimport", klog.KObj(svcImpObj))
return ctrl.Result{}, err
}
r.installedResImports.Add(*resImp)
Expand All @@ -207,7 +207,7 @@ func (r *ResourceImportReconciler) handleResImpUpdateForService(ctx context.Cont
svc.Spec.Ports = svcObj.Spec.Ports
err = r.localClusterClient.Update(ctx, svc, &client.UpdateOptions{})
if err != nil {
klog.ErrorS(err, "failed to update imported Service", "service", svcName.String())
klog.ErrorS(err, "Failed to update imported Service", "service", svcName.String())
return ctrl.Result{}, err
}
r.installedResImports.Update(*resImp)
Expand All @@ -218,7 +218,7 @@ func (r *ResourceImportReconciler) handleResImpUpdateForService(ctx context.Cont
addAnnotation(svcImp, r.localClusterID)
err = r.localClusterClient.Update(ctx, svcImp, &client.UpdateOptions{})
if err != nil {
klog.ErrorS(err, "failed to update ServiceImport", "serviceimport", svcImpName.String())
klog.ErrorS(err, "Failed to update ServiceImport", "serviceimport", svcImpName.String())
return ctrl.Result{}, err
}
r.installedResImports.Update(*resImp)
Expand Down Expand Up @@ -277,8 +277,8 @@ func (r *ResourceImportReconciler) handleResImpUpdateForEndpoints(ctx context.Co
}
if !epNotFound {
if _, ok := ep.Annotations[common.AntreaMCServiceAnnotation]; !ok {
err := errors.New("unable to import Endpoints which conflicts with existing one")
klog.ErrorS(err, "", "endpoints", klog.KObj(ep))
err := errors.New("the Endpoints conflicts with existing one")
klog.ErrorS(err, "Unable to import Endpoints", "endpoints", klog.KObj(ep))
return ctrl.Result{}, err
}
}
Expand All @@ -292,7 +292,7 @@ func (r *ResourceImportReconciler) handleResImpUpdateForEndpoints(ctx context.Co
} else if apierrors.IsNotFound(err) {
newSubsets = resImp.Spec.Endpoints.Subsets
} else {
klog.ErrorS(err, "failed to get local Endpoint", "endpoint", epNamespaced.String())
klog.ErrorS(err, "Failed to get local Endpoint", "endpoint", epNamespaced.String())
return ctrl.Result{}, err
}
mcsEpObj := &corev1.Endpoints{
Expand All @@ -306,22 +306,22 @@ func (r *ResourceImportReconciler) handleResImpUpdateForEndpoints(ctx context.Co
if epNotFound {
err := r.localClusterClient.Create(ctx, mcsEpObj, &client.CreateOptions{})
if err != nil {
klog.ErrorS(err, "failed to create MCS Endpoints", "endpoints", klog.KObj(mcsEpObj), err)
klog.ErrorS(err, "Failed to create MCS Endpoints", "endpoints", klog.KObj(mcsEpObj), err)
return ctrl.Result{}, err
}
r.installedResImports.Add(*resImp)
return ctrl.Result{}, nil
}
if _, ok := ep.Annotations[common.AntreaMCServiceAnnotation]; !ok {
klog.InfoS("Endpoints has no desired annotation "+common.AntreaMCServiceAnnotation+", skip update", "endpoints", epNamespaced.String())
klog.InfoS("Endpoints has no desired annotation, skip update", "annotation", common.AntreaMCServiceAnnotation, "endpoints", epNamespaced.String())
return ctrl.Result{}, nil
}
// TODO: check label difference ?
if !apiequality.Semantic.DeepEqual(newSubsets, ep.Subsets) {
ep.Subsets = newSubsets
err = r.localClusterClient.Update(ctx, ep, &client.UpdateOptions{})
if err != nil {
klog.ErrorS(err, "failed to update MCS Endpoints", "endpoints", epNamespaced.String())
klog.ErrorS(err, "Failed to update MCS Endpoints", "endpoints", epNamespaced.String())
return ctrl.Result{}, err
}
r.installedResImports.Update(*resImp)
Expand All @@ -338,12 +338,12 @@ func (r *ResourceImportReconciler) handleResImpDeleteForEndpoints(ctx context.Co
ep := &corev1.Endpoints{}
err := r.localClusterClient.Get(ctx, epNamespaced, ep)
if err != nil {
klog.InfoS("unable to fetch imported Endpoints", "endpoints", epNamespaced.String(), "err", err)
klog.InfoS("Unable to fetch imported Endpoints", "endpoints", epNamespaced.String(), "err", err)
return ctrl.Result{}, client.IgnoreNotFound(err)
}
err = r.localClusterClient.Delete(ctx, ep, &client.DeleteOptions{})
if err != nil {
klog.InfoS("failed to delete imported Endpoints", "endpoints", epNamespaced.String(), "err", err)
klog.InfoS("Failed to delete imported Endpoints", "endpoints", epNamespaced.String(), "err", err)
return ctrl.Result{}, client.IgnoreNotFound(err)
}
return ctrl.Result{}, nil
Expand Down
Expand Up @@ -69,7 +69,6 @@ func (r *LeaderClusterSetReconciler) Reconcile(ctx context.Context, req ctrl.Req
if !errors.IsNotFound(err) {
return ctrl.Result{}, err
}
// if errors.IsNotFound(err)
klog.InfoS("Received ClusterSet delete", "config", klog.KObj(clusterSet))
for _, removedMember := range r.clusterSetConfig.Spec.Members {
r.StatusManager.RemoveMember(common.ClusterID(removedMember.ClusterID))
Expand Down Expand Up @@ -143,7 +142,7 @@ func (r *LeaderClusterSetReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&multiclusterv1alpha1.ClusterSet{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: 5, // TODO: Use a constant after merging with Lan's changes
MaxConcurrentReconciles: common.DefaultWorkerCount,
}).
Complete(r)
}
Expand Down Expand Up @@ -226,7 +225,7 @@ func (r *LeaderClusterSetReconciler) updateStatus() {
clusterSet := &multiclusterv1alpha1.ClusterSet{}
err := r.Get(context.TODO(), namespacedName, clusterSet)
if err != nil {
klog.ErrorS(err, "failed to read ClusterSet", "Name", namespacedName)
klog.ErrorS(err, "Failed to read ClusterSet", "Name", namespacedName)
}
status.Conditions = clusterSet.Status.Conditions
if (len(clusterSet.Status.Conditions) == 1 && clusterSet.Status.Conditions[0].Status != overallCondition.Status) ||
Expand All @@ -236,6 +235,6 @@ func (r *LeaderClusterSetReconciler) updateStatus() {
clusterSet.Status = status
err = r.Status().Update(context.TODO(), clusterSet)
if err != nil {
klog.ErrorS(err, "failed to update Status of ClusterSet", "Name", namespacedName)
klog.ErrorS(err, "Failed to update Status of ClusterSet", "Name", namespacedName)
}
}
Expand Up @@ -135,7 +135,7 @@ func (r *MemberClusterSetReconciler) updateMultiClusterSetOnMemberCluster(cluste
r.RemoteCommonAreaManager = commonarea.NewRemoteCommonAreaManager(r.clusterSetID, r.clusterID)
err := r.RemoteCommonAreaManager.Start()
if err != nil {
klog.ErrorS(err, "error starting RemoteCommonAreaManager")
klog.ErrorS(err, "Error starting RemoteCommonAreaManager")
r.RemoteCommonAreaManager = nil
r.clusterSetID = common.InvalidClusterSetID
r.clusterID = common.InvalidClusterID
Expand Down Expand Up @@ -277,7 +277,7 @@ func (r *MemberClusterSetReconciler) updateStatus() {
clusterSet := &multiclusterv1alpha1.ClusterSet{}
err := r.Get(context.TODO(), namespacedName, clusterSet)
if err != nil {
klog.ErrorS(err, "failed to read ClusterSet", "Name", namespacedName)
klog.ErrorS(err, "Failed to read ClusterSet", "Name", namespacedName)
}
status.Conditions = clusterSet.Status.Conditions
if (len(clusterSet.Status.Conditions) == 1 && clusterSet.Status.Conditions[0].Status != overallCondition.Status) ||
Expand All @@ -287,6 +287,6 @@ func (r *MemberClusterSetReconciler) updateStatus() {
clusterSet.Status = status
err = r.Status().Update(context.TODO(), clusterSet)
if err != nil {
klog.ErrorS(err, "failed to update Status of ClusterSet", "Name", namespacedName)
klog.ErrorS(err, "Failed to update Status of ClusterSet", "Name", namespacedName)
}
}
Expand Up @@ -136,9 +136,9 @@ func (r *ResourceExportReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return ctrl.Result{}, err
}
r.updateResourceExportStatus(&resExport, succeed)
klog.InfoS("Create ResourceImport successfully", "resourceimport", resImportName.String())
klog.V(2).InfoS("ResourceImport is created successfully", "resourceimport", resImportName.String())
} else if changed {
klog.InfoS("Update ResourceImport for ResoureExport", "resourceimport", resImportName.String(), "resourceexport", req.NamespacedName)
klog.V(2).InfoS("Updating ResourceImport for ResoureExport", "resourceimport", resImportName.String(), "resourceexport", req.NamespacedName)
if err = r.handleUpdateEvent(ctx, resImport, &resExport); err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -452,7 +452,7 @@ func (r *ResourceExportReconciler) updateResourceExportStatus(resExport *mcsv1al
}
err := r.Client.Status().Update(ctx, resExport)
if err != nil {
klog.ErrorS(err, "failed to update ResourceExport status", "resourceexport", klog.KObj(resExport))
klog.ErrorS(err, "Failed to update ResourceExport status", "resourceexport", klog.KObj(resExport))
}
}

Expand All @@ -467,7 +467,7 @@ func (r *ResourceExportReconciler) deleteResourceExport(resExport *mcsv1alpha1.R

// SetupWithManager sets up the controller with the Manager.
func (r *ResourceExportReconciler) SetupWithManager(mgr ctrl.Manager) error {
// ignore status update event via GenerationChangedPredicate
// Ignore status update event via GenerationChangedPredicate
instance := predicate.GenerationChangedPredicate{}
return ctrl.NewControllerManagedBy(mgr).
For(&mcsv1alpha1.ResourceExport{}).
Expand Down

0 comments on commit c8a3544

Please sign in to comment.