From 852276fbac724870cfb2763a25f0ca2acc04622e Mon Sep 17 00:00:00 2001 From: futuretea <1913508671@qq.com> Date: Tue, 19 Sep 2023 19:03:26 +0800 Subject: [PATCH] Fix lint Signed-off-by: futuretea <1913508671@qq.com> --- internal/graph/graph.go | 1 + internal/graph/kubernetes.go | 14 ++++++++++---- internal/printers/printers_humanreadable.go | 10 ++++++++++ pkg/cmd/helm/helm.go | 4 +++- pkg/cmd/lineage/lineage.go | 4 +++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/internal/graph/graph.go b/internal/graph/graph.go index 6d1595a..467bb6c 100644 --- a/internal/graph/graph.go +++ b/internal/graph/graph.go @@ -307,6 +307,7 @@ func ResolveDependents(m meta.RESTMapper, objects []unstructuredv1.Unstructured, // resolveDeps resolves all dependencies or dependents of the provided objects // and returns a relationship tree. +// //nolint:funlen,gocognit,gocyclo func resolveDeps(m meta.RESTMapper, objects []unstructuredv1.Unstructured, uids []types.UID, depsIsDependencies bool) (NodeMap, error) { if len(uids) == 0 { diff --git a/internal/graph/kubernetes.go b/internal/graph/kubernetes.go index 9931fe6..59cfed7 100644 --- a/internal/graph/kubernetes.go +++ b/internal/graph/kubernetes.go @@ -1,7 +1,6 @@ package graph import ( - "k8s.io/klog/v2" "strings" lhv1beta2 "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2" @@ -24,6 +23,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apiserver/pkg/authentication/serviceaccount" "k8s.io/apiserver/pkg/authentication/user" + "k8s.io/klog/v2" apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" kubevirtv1 "kubevirt.io/api/core/v1" ) @@ -209,6 +209,7 @@ func getClusterRoleRelationships(n *Node) (*RelationshipMap, error) { // getClusterRoleBindingRelationships returns a map of relationships that this // ClusterRoleBinding has with other objects, based on what was referenced in // its manifest. +// //nolint:gocognit func getClusterRoleBindingRelationships(n *Node) (*RelationshipMap, error) { var crb rbacv1.ClusterRoleBinding @@ -313,6 +314,7 @@ func getCSIStorageCapacityRelationships(n *Node) (*RelationshipMap, error) { // getEventRelationships returns a map of relationships that this Event has with // other objects, based on what was referenced in its manifest. +// //nolint:unparam func getEventRelationships(n *Node) (*RelationshipMap, error) { result := newRelationshipMap() @@ -335,6 +337,7 @@ func getEventRelationships(n *Node) (*RelationshipMap, error) { // getIngressRelationships returns a map of relationships that this Ingress has // with other objects, based on what was referenced in its manifest. +// //nolint:funlen,gocognit func getIngressRelationships(n *Node) (*RelationshipMap, error) { var ref ObjectReference @@ -603,9 +606,9 @@ func getPersistentVolumeClaimRelationships(n *Node) (*RelationshipMap, error) { } } - if imageId := pvc.Annotations["harvesterhci.io/imageId"]; imageId != "" { - klog.V(4).Infof("Found imageId %s in PVC %s/%s", imageId, pvc.Namespace, pvc.Name) - nn := strings.SplitN(imageId, "/", 2) + if imageID := pvc.Annotations["harvesterhci.io/imageId"]; imageID != "" { + klog.V(4).Infof("Found imageId %s in PVC %s/%s", imageID, pvc.Namespace, pvc.Name) + nn := strings.SplitN(imageID, "/", 2) ref = ObjectReference{Kind: "VirtualMachineImage", Name: nn[1], Namespace: nn[0]} result.AddDependentByKey(ref.Key(), RelationshipPersistentVolumeClaimVMImage) } @@ -757,6 +760,7 @@ func getVMIRelationships(n *Node) (*RelationshipMap, error) { // getPodRelationships returns a map of relationships that this Pod has with // other objects, based on what was referenced in its manifest. +// //nolint:funlen,gocognit func getPodRelationships(n *Node) (*RelationshipMap, error) { var pod corev1.Pod @@ -970,6 +974,7 @@ func getRoleRelationships(n *Node) (*RelationshipMap, error) { // getRoleBindingRelationships returns a map of relationships that this // RoleBinding has with other objects, based on what was referenced in its // manifest. +// //nolint:funlen,gocognit func getRoleBindingRelationships(n *Node) (*RelationshipMap, error) { var rb rbacv1.RoleBinding @@ -1164,6 +1169,7 @@ func getValidatingWebhookConfigurationRelationships(n *Node) (*RelationshipMap, // getVolumeAttachmentRelationships returns a map of relationships that this // VolumeAttachment has with other objects, based on what was referenced in its // manifest. +// //nolint:funlen,nestif func getVolumeAttachmentRelationships(n *Node) (*RelationshipMap, error) { var va storagev1.VolumeAttachment diff --git a/internal/printers/printers_humanreadable.go b/internal/printers/printers_humanreadable.go index 83eadd7..f01d3f1 100644 --- a/internal/printers/printers_humanreadable.go +++ b/internal/printers/printers_humanreadable.go @@ -186,6 +186,7 @@ func getAPIServiceReadyStatus(u *unstructuredv1.Unstructured) (string, string, e // getDaemonSetReadyStatus returns the ready & status value of a DaemonSet // which is based off the table cell values computed by printDaemonSet from // https://github.com/kubernetes/kubernetes/blob/v1.22.1/pkg/printers/internalversion/printers.go. +// //nolint:unparam func getDaemonSetReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var ds appsv1.DaemonSet @@ -203,6 +204,7 @@ func getDaemonSetReadyStatus(u *unstructuredv1.Unstructured) (string, string, er // getDeploymentReadyStatus returns the ready & status value of a Deployment // which is based off the table cell values computed by printDeployment from // https://github.com/kubernetes/kubernetes/blob/v1.22.1/pkg/printers/internalversion/printers.go. +// //nolint:unparam func getDeploymentReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var deploy appsv1.Deployment @@ -218,6 +220,7 @@ func getDeploymentReadyStatus(u *unstructuredv1.Unstructured) (string, string, e } // getEventCoreReadyStatus returns the ready & status value of a Event. +// //nolint:unparam func getEventCoreReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var status string @@ -236,6 +239,7 @@ func getEventCoreReadyStatus(u *unstructuredv1.Unstructured) (string, string, er } // getEventReadyStatus returns the ready & status value of a Event.events.k8s.io. +// //nolint:unparam func getEventReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var status string @@ -256,6 +260,7 @@ func getEventReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) // getPodReadyStatus returns the ready & status value of a Pod which is based // off the table cell values computed by printPod from // https://github.com/kubernetes/kubernetes/blob/v1.22.1/pkg/printers/internalversion/printers.go. +// //nolint:funlen,gocognit,gocyclo func getPodReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var pod corev1.Pod @@ -336,6 +341,7 @@ func getPodReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { // getPodDisruptionBudgetReadyStatus returns the ready & status value of a // PodDisruptionBudget. +// //nolint:unparam func getPodDisruptionBudgetReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var pdb policyv1.PodDisruptionBudget @@ -358,6 +364,7 @@ func getPodDisruptionBudgetReadyStatus(u *unstructuredv1.Unstructured) (string, // getReplicaSetReadyStatus returns the ready & status value of a ReplicaSet // which is based off the table cell values computed by printReplicaSet from // https://github.com/kubernetes/kubernetes/blob/v1.22.1/pkg/printers/internalversion/printers.go. +// //nolint:unparam func getReplicaSetReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var rs appsv1.ReplicaSet @@ -376,6 +383,7 @@ func getReplicaSetReadyStatus(u *unstructuredv1.Unstructured) (string, string, e // ReplicationController which is based off the table cell values computed by // printReplicationController from // https://github.com/kubernetes/kubernetes/blob/v1.22.1/pkg/printers/internalversion/printers.go. +// //nolint:unparam func getReplicationControllerReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var rc corev1.ReplicationController @@ -393,6 +401,7 @@ func getReplicationControllerReadyStatus(u *unstructuredv1.Unstructured) (string // getStatefulSetReadyStatus returns the ready & status value of a StatefulSet // which is based off the table cell values computed by printStatefulSet from // https://github.com/kubernetes/kubernetes/blob/v1.22.1/pkg/printers/internalversion/printers.go. +// //nolint:unparam func getStatefulSetReadyStatus(u *unstructuredv1.Unstructured) (string, string, error) { var sts appsv1.StatefulSet @@ -436,6 +445,7 @@ func getVolumeAttachmentReadyStatus(u *unstructuredv1.Unstructured) (string, str } // nodeToTableRow converts the provided node into a table row. +// //nolint:funlen,gocognit,goconst func nodeToTableRow(node *graph.Node, rset graph.RelationshipSet, namePrefix string, showGroupFn func(kind string) bool) metav1.TableRow { var name, ready, status, age string diff --git a/pkg/cmd/helm/helm.go b/pkg/cmd/helm/helm.go index 230371c..233bdb9 100644 --- a/pkg/cmd/helm/helm.go +++ b/pkg/cmd/helm/helm.go @@ -3,10 +3,11 @@ package helm import ( "context" "fmt" - "k8s.io/kubectl/pkg/util/completion" "os" "strings" + "k8s.io/kubectl/pkg/util/completion" + "github.com/spf13/cobra" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/release" @@ -187,6 +188,7 @@ func (o *CmdOptions) Validate() error { } // Run implements all the necessary functionality for the helm command. +// //nolint:funlen,gocognit,gocyclo func (o *CmdOptions) Run() error { ctx := context.Background() diff --git a/pkg/cmd/lineage/lineage.go b/pkg/cmd/lineage/lineage.go index 85bc983..afd3dc6 100644 --- a/pkg/cmd/lineage/lineage.go +++ b/pkg/cmd/lineage/lineage.go @@ -3,9 +3,10 @@ package lineage import ( "context" "fmt" - "k8s.io/kubectl/pkg/util/completion" "strings" + "k8s.io/kubectl/pkg/util/completion" + "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/types" "k8s.io/cli-runtime/pkg/genericclioptions" @@ -189,6 +190,7 @@ func (o *CmdOptions) Validate() error { } // Run implements all the necessary functionality for the lineage command. +// //nolint:funlen func (o *CmdOptions) Run() error { ctx := context.Background()