From f0618e9133292aceac4e13fd0149f0f1961ba377 Mon Sep 17 00:00:00 2001 From: Varsha Varadarajan Date: Fri, 28 Jun 2019 08:33:20 -0400 Subject: [PATCH] Fix golint errors. --- checks/all/all.go | 4 ++++ checks/basic/unused_pv.go | 2 +- checks/diagnostic.go | 36 +++++++++++++++++++++++++----------- checks/registry.go | 2 ++ kube/objects.go | 8 +++----- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/checks/all/all.go b/checks/all/all.go index 6675d49..0294332 100644 --- a/checks/all/all.go +++ b/checks/all/all.go @@ -3,8 +3,12 @@ package all import ( + // Side-effect import to get all the checks in basic package registered. _ "github.com/digitalocean/clusterlint/checks/basic" + // Side-effect import to get all the checks in doks package registered. _ "github.com/digitalocean/clusterlint/checks/doks" + // Side-effect import to get all the checks in noop package registered. _ "github.com/digitalocean/clusterlint/checks/noop" + // Side-effect import to get all the checks in security package registered. _ "github.com/digitalocean/clusterlint/checks/security" ) diff --git a/checks/basic/unused_pv.go b/checks/basic/unused_pv.go index d4d0106..9c1234a 100644 --- a/checks/basic/unused_pv.go +++ b/checks/basic/unused_pv.go @@ -19,7 +19,7 @@ func (pv *unusedPVCheck) Name() string { } // Groups returns a list of group names this check should be part of. -func (pvh *unusedPVCheck) Groups() []string { +func (pv *unusedPVCheck) Groups() []string { return []string{"basic"} } diff --git a/checks/diagnostic.go b/checks/diagnostic.go index 6cbdb14..78f0cca 100644 --- a/checks/diagnostic.go +++ b/checks/diagnostic.go @@ -20,19 +20,33 @@ func (d Diagnostic) String() string { d.Kind, d.Object.Name, d.Message) } +// Severity identifies the level of priority for each diagnostic. type Severity string + +// Kind represents the kind of k8s object the diagnoatic is about type Kind string const ( - Error Severity = "error" - Warning Severity = "warning" - Suggestion Severity = "suggestion" - Pod Kind = "pod" - PodTemplate Kind = "pod template" - PersistentVolumeClaim Kind = "persistent volume claim" - ConfigMap Kind = "config map" - Service Kind = "service" - Secret Kind = "secret" - ServiceAccount Kind = "service account" - PersistentVolume Kind = "persistent volume" + // Error means that the diagnostic message should be fixed immediately + Error Severity = "error" + // Warning indicates that the diagnostic should be fixed but okay to ignore in some special cases + Warning Severity = "warning" + // Suggestion means that a user need not implement it, but is in line with the recommended best practices + Suggestion Severity = "suggestion" + // Pod identifies Kubernetes objects of kind `pod` + Pod Kind = "pod" + // PodTemplate identifies Kubernetes objects of kind `pod template` + PodTemplate Kind = "pod template" + // PersistentVolumeClaim identifies Kubernetes objects of kind `persistent volume claim` + PersistentVolumeClaim Kind = "persistent volume claim" + // ConfigMap identifies Kubernetes objects of kind `config map` + ConfigMap Kind = "config map" + // Service identifies Kubernetes objects of kind `service` + Service Kind = "service" + // Secret identifies Kubernetes objects of kind `secret` + Secret Kind = "secret" + // ServiceAccount identifies Kubernetes objects of kind `service account` + ServiceAccount Kind = "service account" + // PersistentVolume identifies Kubernetes objects of kind `persistent volume` + PersistentVolume Kind = "persistent volume" ) diff --git a/checks/registry.go b/checks/registry.go index 754add6..93c7069 100644 --- a/checks/registry.go +++ b/checks/registry.go @@ -85,6 +85,8 @@ func GetGroup(name string) []Check { return ret } +// Get retrieves the specified check from the registry, +// throws an error if not found func Get(name string) (Check, error) { registry.mu.RLock() defer registry.mu.RUnlock() diff --git a/kube/objects.go b/kube/objects.go index eefec51..178d944 100644 --- a/kube/objects.go +++ b/kube/objects.go @@ -25,11 +25,6 @@ type Objects struct { LimitRanges *corev1.LimitRangeList } -type Object struct { - TypeInfo *metav1.TypeMeta - ObjectInfo *metav1.ObjectMeta -} - // Client encapsulates a client for a Kubernetes cluster. type Client struct { kubeClient kubernetes.Interface @@ -100,6 +95,9 @@ func (c *Client) FetchObjects() (*Objects, error) { return objects, nil } +// NewClient builds a kubernetes client to interact with the live cluster. +// The kube config file path and the context must be specified for the client +// If not specified, defaults are assumed - configPath: ~/.kube/config, configContext: current context func NewClient(configPath, configContext string) (*Client, error) { var config *rest.Config var err error