Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golint to CI linters #725

Merged
merged 1 commit into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
linters:
enable:
- govet
- golint
- gofmt
- goimports
- structcheck
Expand Down
7 changes: 5 additions & 2 deletions cmd/clusterctl/clusterdeployer/clusterclient/clientfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sigs.k8s.io/cluster-api/cmd/clusterctl/clientcmd"
)

// Factory can create cluster clients
// Factory can create cluster clients.
type Factory interface {
NewClientFromKubeconfig(string) (Client, error)
NewCoreClientsetFromKubeconfigFile(string) (*kubernetes.Clientset, error)
Expand All @@ -30,14 +30,17 @@ type Factory interface {
type clientFactory struct {
}

func NewFactory() *clientFactory {
// NewFactory returns a new cluster client factory.
func NewFactory() *clientFactory { // nolint
return &clientFactory{}
}

// NewClientFromKubeConfig returns a new Client from the Kubeconfig passed as argument.
func (f *clientFactory) NewClientFromKubeconfig(kubeconfig string) (Client, error) {
return New(kubeconfig)
}

// NewCoreClientsetFromKubeconfigFile returns a new ClientSet from the Kubeconfig path passed as argument.
func (f *clientFactory) NewCoreClientsetFromKubeconfigFile(kubeconfigPath string) (*kubernetes.Clientset, error) {
return clientcmd.NewCoreClientSetForDefaultSearchPath(kubeconfigPath, clientcmd.NewConfigOverrides())
}
4 changes: 2 additions & 2 deletions cmd/clusterctl/clusterdeployer/clusterclient/clusterclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type client struct {

// New creates and returns a Client, the kubeconfig argument is expected to be the string representation
// of a valid kubeconfig.
func New(kubeconfig string) (*client, error) {
func New(kubeconfig string) (*client, error) { //nolint
f, err := createTempFile(kubeconfig)
if err != nil {
return nil, err
Expand Down Expand Up @@ -142,7 +142,7 @@ func (c *client) DeleteNamespace(namespaceName string) error {

// NewFromDefaultSearchPath creates and returns a Client. The kubeconfigFile argument is expected to be the path to a
// valid kubeconfig file.
func NewFromDefaultSearchPath(kubeconfigFile string, overrides tcmd.ConfigOverrides) (*client, error) {
func NewFromDefaultSearchPath(kubeconfigFile string, overrides tcmd.ConfigOverrides) (*client, error) { //nolint
c, err := clientcmd.NewClusterAPIClientForDefaultSearchPath(kubeconfigFile, overrides)
if err != nil {
return nil, err
Expand Down
30 changes: 15 additions & 15 deletions pkg/apis/cluster/v1alpha1/machineset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,39 +136,39 @@ type MachineSetStatus struct {

/// [MachineSetStatus]

func (machineSet *MachineSet) Validate() field.ErrorList {
func (m *MachineSet) Validate() field.ErrorList {
errors := field.ErrorList{}

// validate spec.selector and spec.template.labels
fldPath := field.NewPath("spec")
errors = append(errors, metav1validation.ValidateLabelSelector(&machineSet.Spec.Selector, fldPath.Child("selector"))...)
if len(machineSet.Spec.Selector.MatchLabels)+len(machineSet.Spec.Selector.MatchExpressions) == 0 {
errors = append(errors, field.Invalid(fldPath.Child("selector"), machineSet.Spec.Selector, "empty selector is not valid for MachineSet."))
errors = append(errors, metav1validation.ValidateLabelSelector(&m.Spec.Selector, fldPath.Child("selector"))...)
if len(m.Spec.Selector.MatchLabels)+len(m.Spec.Selector.MatchExpressions) == 0 {
errors = append(errors, field.Invalid(fldPath.Child("selector"), m.Spec.Selector, "empty selector is not valid for MachineSet."))
}
selector, err := metav1.LabelSelectorAsSelector(&machineSet.Spec.Selector)
selector, err := metav1.LabelSelectorAsSelector(&m.Spec.Selector)
if err != nil {
errors = append(errors, field.Invalid(fldPath.Child("selector"), machineSet.Spec.Selector, "invalid label selector."))
errors = append(errors, field.Invalid(fldPath.Child("selector"), m.Spec.Selector, "invalid label selector."))
} else {
labels := labels.Set(machineSet.Spec.Template.Labels)
labels := labels.Set(m.Spec.Template.Labels)
if !selector.Matches(labels) {
errors = append(errors, field.Invalid(fldPath.Child("template", "metadata", "labels"), machineSet.Spec.Template.Labels, "`selector` does not match template `labels`"))
errors = append(errors, field.Invalid(fldPath.Child("template", "metadata", "labels"), m.Spec.Template.Labels, "`selector` does not match template `labels`"))
}
}

return errors
}

// DefaultingFunction sets default MachineSet field values
func (obj *MachineSet) Default() {
log.Printf("Defaulting fields for MachineSet %s\n", obj.Name)
func (m *MachineSet) Default() {
log.Printf("Defaulting fields for MachineSet %s\n", m.Name)

if obj.Spec.Replicas == nil {
obj.Spec.Replicas = new(int32)
*obj.Spec.Replicas = 1
if m.Spec.Replicas == nil {
m.Spec.Replicas = new(int32)
*m.Spec.Replicas = 1
}

if len(obj.Namespace) == 0 {
obj.Namespace = metav1.NamespaceDefault
if len(m.Namespace) == 0 {
m.Namespace = metav1.NamespaceDefault
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/cluster/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ import (
)

var (
// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
SchemeGroupVersion = schema.GroupVersion{Group: "cluster.k8s.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}

// AddToScheme adds registered types to the builder.
// Required by pkg/client/...
// TODO(pwittrock): Remove this after removing pkg/client/...
AddToScheme = SchemeBuilder.AddToScheme
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmdrunner/cmd_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import (
"os/exec"
)

// Runner has one method that executes a command and returns stdout and stderr.
type Runner interface {
CombinedOutput(cmd string, args ...string) (output string, err error)
}

type realRunner struct {
}

func New() *realRunner {
// New returns a command runner.
func New() *realRunner { // nolint
return &realRunner{}
}

Expand Down