Skip to content

Commit

Permalink
fix: go lint errors (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
luc99hen authored Dec 29, 2024
1 parent 2432e74 commit ea999d4
Show file tree
Hide file tree
Showing 30 changed files with 165 additions and 163 deletions.
12 changes: 7 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ run:

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
# default is "colored-line-number"
format: colored-line-number
formats:
- format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true
Expand All @@ -33,7 +32,10 @@ output:
# all available settings of specific linters
linters-settings:
gci:
local-prefixes: github.com/openyurtio
sections:
- standard
- prefix(github.com/openyurtio)
- default

linters:
disable-all: true
Expand All @@ -44,5 +46,5 @@ linters:
- ineffassign
- misspell
- unused
- vet
- govet
- staticcheck
8 changes: 4 additions & 4 deletions hack/make-rules/add_controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func Format(format string, args ...interface{}) string {
// Add creates a new ${KIND_FIRST_UPPER} Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(ctx context.Context, c *appconfig.CompletedConfig, mgr manager.Manager) error {
klog.Infof(Format("${KIND_ALL_LOWER}-controller add controller %s", controllerKind.String()))
klog.Info(Format("${KIND_ALL_LOWER}-controller add controller %s", controllerKind.String()))
return add(mgr, newReconciler(c, mgr))
}
Expand Down Expand Up @@ -475,7 +475,7 @@ func (r *Reconcile${KIND_FIRST_UPPER}) Reconcile(_ context.Context, request reco
// Note !!!!!!!!!!
// We strongly recommend use Format() to encapsulation because Format() can print logs by module
// @kadisi
klog.Infof(Format("Reconcile ${KIND_FIRST_UPPER} %s/%s", request.Namespace, request.Name))
klog.Info(Format("Reconcile ${KIND_FIRST_UPPER} %s/%s", request.Namespace, request.Name))
// Fetch the ${KIND_FIRST_UPPER} instance
instance := &${GROUP}${VERSION}.${KIND_FIRST_UPPER}{}
Expand All @@ -495,14 +495,14 @@ func (r *Reconcile${KIND_FIRST_UPPER}) Reconcile(_ context.Context, request reco
if instance.Spec.Foo != instance.Status.Foo {
instance.Status.Foo = instance.Spec.Foo
if err = r.Status().Update(context.TODO(), instance); err != nil {
klog.Errorf(Format("Update ${KIND_FIRST_UPPER} Status %s error %v", klog.KObj(instance), err))
klog.Error(Format("Update ${KIND_FIRST_UPPER} Status %s error %v", klog.KObj(instance), err))
return reconcile.Result{Requeue: true}, err
}
}
// Update Instance
//if err = r.Update(context.TODO(), instance); err != nil {
// klog.Errorf(Format("Update ${KIND_FIRST_UPPER} %s error %v", klog.KObj(instance), err))
// klog.Error(Format("Update ${KIND_FIRST_UPPER} %s error %v", klog.KObj(instance), err))
// return reconcile.Result{Requeue: true}, err
//}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (r *ReconcileDaemonpodupdater) Reconcile(_ context.Context, request reconci
// Note !!!!!!!!!!
// We strongly recommend use Format() to encapsulation because Format() can print logs by module
// @kadisi
klog.V(4).Infof(Format("Reconcile DaemonpodUpdater %s", request.Name))
klog.V(4).Info(Format("Reconcile DaemonpodUpdater %s", request.Name))

// Fetch the DaemonSet instance
instance := &appsv1.DaemonSet{}
Expand Down Expand Up @@ -240,17 +240,17 @@ func (r *ReconcileDaemonpodupdater) Reconcile(_ context.Context, request reconci
switch strings.ToLower(v) {
case strings.ToLower(OTAUpdate):
if err := r.otaUpdate(instance); err != nil {
klog.Errorf(Format("could not OTA update DaemonSet %v pod: %v", request.NamespacedName, err))
klog.Error(Format("could not OTA update DaemonSet %v pod: %v", request.NamespacedName, err))
return reconcile.Result{}, err
}

case strings.ToLower(AutoUpdate), strings.ToLower(AdvancedRollingUpdate):
if err := r.advancedRollingUpdate(instance); err != nil {
klog.Errorf(Format("could not advanced rolling update DaemonSet %v pod: %v", request.NamespacedName, err))
klog.Error(Format("could not advanced rolling update DaemonSet %v pod: %v", request.NamespacedName, err))
return reconcile.Result{}, err
}
default:
klog.Errorf(Format("Unknown update type for DaemonSet %v pod: %v", request.NamespacedName, v))
klog.Error(Format("Unknown update type for DaemonSet %v pod: %v", request.NamespacedName, v))
return reconcile.Result{}, fmt.Errorf("unknown update type %v", v)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Format(format string, args ...interface{}) string {
// Add creates a new PoolService Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(ctx context.Context, c *appconfig.CompletedConfig, mgr manager.Manager) error {
klog.Infof(Format("loadbalancerset-controller add controller %s", poolServicesControllerResource.String()))
klog.Info(Format("loadbalancerset-controller add controller %s", poolServicesControllerResource.String()))
r := newReconciler(c, mgr)

if _, err := r.mapper.KindFor(poolServicesControllerResource); err != nil {
Expand Down Expand Up @@ -144,7 +144,7 @@ func (r *ReconcileLoadBalancerSet) Reconcile(_ context.Context, request reconcil
// Note !!!!!!!!!!
// We strongly recommend use Format() to encapsulation because Format() can print logs by module
// @kadisi
klog.Infof(Format("Reconcile PoolService %s/%s", request.Namespace, request.Name))
klog.Info(Format("Reconcile PoolService %s/%s", request.Namespace, request.Name))

service := &corev1.Service{}
err := r.Get(context.TODO(), request.NamespacedName, service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Format(format string, args ...interface{}) string {
// Add creates a new NodeBucket Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(_ context.Context, cfg *appconfig.CompletedConfig, mgr manager.Manager) error {
klog.Infof(Format("nodebucket-controller add controller %s", controllerResource.String()))
klog.Info(Format("nodebucket-controller add controller %s", controllerResource.String()))
r := &ReconcileNodeBucket{
Client: yurtClient.GetClientByControllerNameOrDie(mgr, names.NodeBucketController),
maxNodesPerBucket: int(cfg.ComponentConfig.NodeBucketController.MaxNodesPerBucket),
Expand Down Expand Up @@ -168,7 +168,7 @@ type ReconcileNodeBucket struct {
// Reconcile reads that state of the cluster for a NodeBucket object and makes changes based on the state read
// and what is in the NodeBucket.Spec
func (r *ReconcileNodeBucket) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
klog.Infof(Format("Reconcile NodePool for NodeBuckets %s/%s", request.Namespace, request.Name))
klog.Info(Format("Reconcile NodePool for NodeBuckets %s/%s", request.Namespace, request.Name))

// 1. Fetch the NodePool instance
ins := &appsv1beta1.NodePool{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ func TestApplyNoExecuteTaints(t *testing.T) {
//node2, err := fakeNodeHandler.Get(ctx, "node2", metav1.GetOptions{})
node2, err := fakeNodeHandler.DelegateNodeHandler.Get(ctx, "node2", metav1.GetOptions{})
if err != nil {
t.Errorf("Can't get current node2...")
t.Error("Can't get current node2...")
return
}
if !taintutils.TaintExists(node2.Spec.Taints, NotReadyTaintTemplate) {
Expand All @@ -2358,7 +2358,7 @@ func TestApplyNoExecuteTaints(t *testing.T) {
//_, err = fakeNodeHandler.UpdateStatus(ctx, node2, metav1.UpdateOptions{})
_, err = fakeNodeHandler.DelegateNodeHandler.UpdateStatus(ctx, node2, metav1.UpdateOptions{})
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
return
}
//if err := nodeController.syncNodeStore(fakeNodeHandler); err != nil {
Expand Down Expand Up @@ -2512,7 +2512,7 @@ func TestApplyNoExecuteTaintsToNodesEnqueueTwice(t *testing.T) {
node0.Status = healthyNodeNewStatus
_, err = fakeNodeHandler.DelegateNodeHandler.UpdateStatus(ctx, node0, metav1.UpdateOptions{})
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
return
}

Expand Down Expand Up @@ -2750,12 +2750,12 @@ func TestSwapUnreachableNotReadyTaints(t *testing.T) {
node1.Status = healthyNodeNewStatus
_, err = fakeNodeHandler.DelegateNodeHandler.UpdateStatus(ctx, node0, metav1.UpdateOptions{})
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
return
}
_, err = fakeNodeHandler.DelegateNodeHandler.UpdateStatus(ctx, node1, metav1.UpdateOptions{})
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
return
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/yurtmanager/controller/nodepool/nodepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *ReconcileNodePool) Reconcile(ctx context.Context, req reconcile.Request
// Note !!!!!!!!!!
// We strongly recommend use Format() to encapsulation because Format() can print logs by module
// @kadisi
klog.Infof(Format("Reconcile NodePool %s", req.Name))
klog.Info(Format("Reconcile NodePool %s", req.Name))

var nodePool appsv1beta1.NodePool
// try to reconcile the NodePool object
Expand Down Expand Up @@ -156,7 +156,7 @@ func (r *ReconcileNodePool) Reconcile(ctx context.Context, req reconcile.Request
}
if updated {
if err := r.Update(ctx, &node); err != nil {
klog.Errorf(Format("Update Node %s error %v", node.Name, err))
klog.Error(Format("Update Node %s error %v", node.Name, err))
return ctrl.Result{}, err
}
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ func (e *EnqueueNodePoolForNode) Create(ctx context.Context, evt event.CreateEve
klog.Error(Format("could not assert runtime Object to v1.Node"))
return
}
klog.V(5).Infof(Format("will enqueue nodepool as node(%s) has been created",
klog.V(5).Info(Format("will enqueue nodepool as node(%s) has been created",
node.GetName()))
if np := node.Labels[projectinfo.GetNodePoolLabel()]; len(np) != 0 {
addNodePoolToWorkQueue(np, q)
return
}
klog.V(4).Infof(Format("node(%s) does not belong to any nodepool", node.GetName()))
klog.V(4).Info(Format("node(%s) does not belong to any nodepool", node.GetName()))
}

// Update implements EventHandler
func (e *EnqueueNodePoolForNode) Update(ctx context.Context, evt event.UpdateEvent,
q workqueue.RateLimitingInterface) {
newNode, ok := evt.ObjectNew.(*corev1.Node)
if !ok {
klog.Errorf(Format("could not assert runtime Object(%s) to v1.Node",
klog.Error(Format("could not assert runtime Object(%s) to v1.Node",
evt.ObjectNew.GetName()))
return
}
oldNode, ok := evt.ObjectOld.(*corev1.Node)
if !ok {
klog.Errorf(Format("could not assert runtime Object(%s) to v1.Node",
klog.Error(Format("could not assert runtime Object(%s) to v1.Node",
evt.ObjectOld.GetName()))
return
}
Expand All @@ -79,7 +79,7 @@ func (e *EnqueueNodePoolForNode) Update(ctx context.Context, evt event.UpdateEve
return
} else if len(oldNp) == 0 {
// add node to the new Pool
klog.V(4).Infof(Format("node(%s) is added into pool(%s)", newNode.Name, newNp))
klog.V(4).Info(Format("node(%s) is added into pool(%s)", newNode.Name, newNp))
addNodePoolToWorkQueue(newNp, q)
return
} else if oldNp != newNp {
Expand All @@ -92,7 +92,7 @@ func (e *EnqueueNodePoolForNode) Update(ctx context.Context, evt event.UpdateEve

// check node ready status
if isNodeReady(*newNode) != isNodeReady(*oldNode) {
klog.V(4).Infof(Format("Node ready status has been changed,"+
klog.V(4).Info(Format("Node ready status has been changed,"+
" will enqueue pool(%s) for node(%s)", newNp, newNode.GetName()))
addNodePoolToWorkQueue(newNp, q)
return
Expand All @@ -104,7 +104,7 @@ func (e *EnqueueNodePoolForNode) Update(ctx context.Context, evt event.UpdateEve
!reflect.DeepEqual(newNode.Annotations, oldNode.Annotations) ||
!reflect.DeepEqual(newNode.Spec.Taints, oldNode.Spec.Taints) {
// TODO only consider the pool related attributes
klog.V(5).Infof(Format("NodePool related attributes has been changed,will enqueue pool(%s) for node(%s)", newNp, newNode.Name))
klog.V(5).Info(Format("NodePool related attributes has been changed,will enqueue pool(%s) for node(%s)", newNp, newNode.Name))
addNodePoolToWorkQueue(newNp, q)
}
}
Expand All @@ -121,11 +121,11 @@ func (e *EnqueueNodePoolForNode) Delete(ctx context.Context, evt event.DeleteEve

np := node.Labels[projectinfo.GetNodePoolLabel()]
if len(np) == 0 {
klog.V(4).Infof(Format("A orphan node(%s) is removed", node.Name))
klog.V(4).Info(Format("A orphan node(%s) is removed", node.Name))
return
}
// enqueue the nodepool that the node belongs to
klog.V(4).Infof(Format("Will enqueue pool(%s) as node(%s) has been deleted",
klog.V(4).Info(Format("Will enqueue pool(%s) as node(%s) has been deleted",
np, node.GetName()))
addNodePoolToWorkQueue(np, q)
}
Expand Down
Loading

0 comments on commit ea999d4

Please sign in to comment.