Skip to content

Commit

Permalink
Switch golangci-linter to whitelist mode (#713)
Browse files Browse the repository at this point in the history
Signed-off-by: Artiom Diomin <[email protected]>
  • Loading branch information
kron4eg authored and kubermatic-bot committed Oct 23, 2019
1 parent 0bb6aa6 commit 0ed7b26
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 57 deletions.
59 changes: 38 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
run:
issues-exit-code: 1
build-tags:
- e2e
skip-dirs:
- hack
- vendor
- pkg/apis/kubeadm

skip-files:
- zz_generated.*.go

linters:
enable-all: true
disable:
- funlen
disable-all: true
enable:
- bodyclose
- deadcode
- errcheck
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- dupl
- maligned
- megacheck
- lll
- prealloc
- gochecknoinits
- gochecknoglobals
- misspell
- nakedret
- staticcheck
- structcheck
- stylecheck
- unconvert
- unused
- varcheck

linters-settings:
govet:
check-shadowing: true
goimports:
local-prefixes: github.com/kubermatic/kubeone

issues:
exclude:
- "type name will be used as kubeone.KubeOneCluster by other packages, and that stutters; consider calling this Cluster"
- "don't use underscores in Go names; func SetDefaults_KubeOneCluster should be SetDefaultsKubeOneCluster"
- "don't use underscores in Go names; func SetDefaults_Hosts should be SetDefaultsHosts"
- "don't use underscores in Go names; func SetDefaults_APIEndpoints should be SetDefaultsAPIEndpoints"
- "don't use underscores in Go names; func SetDefaults_ClusterNetwork should be SetDefaultsClusterNetwork"
- "don't use underscores in Go names; func SetDefaults_Features should be SetDefaultsFeatures"
- "don't use underscores in Go names; func SetDefaults_MachineController should be SetDefaultsMachineController"
- "don't use underscores in Go names; func SetDefaults_SystemPackages should be SetDefaultsSystemPackages"
- "G101: Potential hardcoded credentials"
- "G106: Use of ssh InsecureIgnoreHostKey should be audited"
- "`defaultRetryBackoff` - `retries` always receives `3`"
- "`defaultRetryBackoff` - `retries` always receives `3`"
- "func SetDefaults_APIEndpoints should be SetDefaultsAPIEndpoints"
- "func SetDefaults_ClusterNetwork should be SetDefaultsClusterNetwork"
- "func SetDefaults_Features should be SetDefaultsFeatures"
- "func SetDefaults_Hosts should be SetDefaultsHosts"
- "func SetDefaults_KubeOneCluster should be SetDefaultsKubeOneCluster"
- "func SetDefaults_MachineController should be SetDefaultsMachineController"
- "func SetDefaults_SystemPackages should be SetDefaultsSystemPackages"
2 changes: 1 addition & 1 deletion pkg/apis/kubeone/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (h *HostConfig) SetLeader(leader bool) {

// CloudProviderInTree detects is there in-tree cloud provider implementation for specified provider.
// List of in-tree provider can be found here: https://github.com/kubernetes/kubernetes/tree/master/pkg/cloudprovider
func (p CloudProviderSpec) CloudProviderInTree() bool {
func (p CloudProviderSpec) CloudProviderInTree() bool { //nolint:stylecheck
switch p.Name {
case CloudProviderNameAWS, CloudProviderNameGCE, CloudProviderNameOpenStack:
return true
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/kubeone/scheme/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package scheme
import (
"github.com/kubermatic/kubeone/pkg/apis/kubeone"
"github.com/kubermatic/kubeone/pkg/apis/kubeone/v1alpha1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/kubeone/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ func ValidateFeatures(f kubeone.Features, fldPath *field.Path) field.ErrorList {
if f.OpenIDConnect != nil && f.OpenIDConnect.Enable {
allErrs = append(allErrs, ValidateOIDCConfig(f.OpenIDConnect.Config, fldPath.Child("openidConnect"))...)
}
allErrs = append(allErrs)
return allErrs
}

Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ func createAndPrintManifest(printOptions *printOptions) error {
}
if printOptions.EnableOpenIDConnect {
cfg.Set(yamled.Path{"features", "openidConnect", "enable"}, printOptions.EnableOpenIDConnect)

cfg.Set(yamled.Path{"features", "openidConnect", "config", "issuerUrl"}, "")
cfg.Set(yamled.Path{"features", "openidConnect", "config", "clientId"}, "")
cfg.Set(yamled.Path{"features", "openidConnect", "config", "usernameClaim"}, "")
Expand Down
6 changes: 3 additions & 3 deletions pkg/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
const (
// Variables that KubeOne (and Terraform) expect to see
AWSAccessKeyID = "AWS_ACCESS_KEY_ID"
AWSSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
AWSSecretAccessKey = "AWS_SECRET_ACCESS_KEY" //nolint:gosec
AzureClientID = "ARM_CLIENT_ID"
AzureClientSecret = "ARM_CLIENT_SECRET"
AzureClientSecret = "ARM_CLIENT_SECRET" //nolint:gosec
AzureTenantID = "ARM_TENANT_ID"
AzureSubscribtionID = "ARM_SUBSCRIPTION_ID"
DigitalOceanTokenKey = "DIGITALOCEAN_TOKEN"
Expand All @@ -56,7 +56,7 @@ const (

// Variables that machine-controller expects
AzureClientIDMC = "AZURE_CLIENT_ID"
AzureClientSecretMC = "AZURE_CLIENT_SECRET"
AzureClientSecretMC = "AZURE_CLIENT_SECRET" //nolint:gosec
AzureTenantIDMC = "AZURE_TENANT_ID"
AzureSubscribtionIDMC = "AZURE_SUBSCRIPTION_ID"
DigitalOceanTokenKeyMC = "DO_TOKEN"
Expand Down
1 change: 0 additions & 1 deletion pkg/installer/installation/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func destroyWorkers(s *state.State) error {
return false, nil
}
return true, nil

})
if lastErr != nil {
s.Logger.Warn("Unable to connect to the control plane API and destroy worker nodes")
Expand Down
2 changes: 1 addition & 1 deletion pkg/ssh/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func NewConnection(o Opts) (Connection, error) {
User: o.Username,
Timeout: o.Timeout,
Auth: authMethods,
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //nolint:gosec
}

targetHost := o.Hostname
Expand Down
4 changes: 2 additions & 2 deletions pkg/templates/machinecontroller/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package machinecontroller

import (
"context"
"crypto/rsa"
"crypto"
"crypto/x509"
"fmt"
"time"
Expand Down Expand Up @@ -299,7 +299,7 @@ func getServingCertVolume() corev1.Volume {

// tlsServingCertificate returns a secret with the machine-controller-webhook tls certificate
// func tlsServingCertificate(ca *triple.KeyPair) (*corev1.Secret, error) {
func tlsServingCertificate(caKey *rsa.PrivateKey, caCert *x509.Certificate) (*corev1.Secret, error) {
func tlsServingCertificate(caKey crypto.Signer, caCert *x509.Certificate) (*corev1.Secret, error) {
commonName := fmt.Sprintf("%s.%s.svc.cluster.local.", WebhookName, WebhookNamespace)
altdnsNames := []string{
commonName,
Expand Down
3 changes: 0 additions & 3 deletions pkg/upgrader/upgrade/kubernetes_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,10 @@ func upgradeKubernetesBinaries(s *state.State, node kubeoneapi.HostConfig) error
switch node.OperatingSystem {
case "ubuntu", "debian":
err = upgradeKubernetesBinariesDebian(s)

case "coreos":
err = upgradeKubernetesBinariesCoreOS(s)

case "centos":
err = upgradeKubernetesBinariesCentOS(s)

default:
err = errors.Errorf("'%s' is not a supported operating system", node.OperatingSystem)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/upgrader/upgrade/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package upgrade
import (
"context"

"github.com/pkg/errors"

kubeoneapi "github.com/kubermatic/kubeone/pkg/apis/kubeone"
"github.com/kubermatic/kubeone/pkg/ssh"
"github.com/kubermatic/kubeone/pkg/state"
"github.com/pkg/errors"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
1 change: 0 additions & 1 deletion pkg/yamled/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ func TestSetNewSubKey(t *testing.T) {
}

func TestSetNewDeepSubKey(t *testing.T) {

doc, expected := loadTestcase(t, "set-new-deep-sub-key.yaml")

doc.Set(Path{"root", "deep", "deeper", "reallyDeep", "newKey"}, "foo")
Expand Down
29 changes: 18 additions & 11 deletions test/e2e/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import (
dynclient "sigs.k8s.io/controller-runtime/pkg/client"
)

const (
clusterNetworkPodCIDR = "192.168.0.0/16"
clusterNetworkServiceCIDR = "172.16.0.0/12"
)

func TestClusterConformance(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -138,11 +143,13 @@ func TestClusterConformance(t *testing.T) {

// Create configuration manifest
t.Log("Creating KubeOneCluster manifest…")
var clusterNetworkPod string
var clusterNetworkService string
var (
clusterNetworkPod string
clusterNetworkService string
)
if tc.provider == provisioner.OpenStack {
clusterNetworkPod = "192.168.0.0/16"
clusterNetworkService = "172.16.0.0/12"
clusterNetworkPod = clusterNetworkPodCIDR
clusterNetworkService = clusterNetworkServiceCIDR
}
err = target.CreateConfig(testTargetVersion, tc.provider,
tc.providerExternal, clusterNetworkPod, clusterNetworkService)
Expand All @@ -158,9 +165,9 @@ func TestClusterConformance(t *testing.T) {
t.Log("Provisioning infrastructure using Terraform…")
args := []string{}
if osControlPlane != OperatingSystemDefault {
tfFlags, err := ControlPlaneImageFlags(tc.provider, osControlPlane)
if err != nil {
t.Fatalf("failed to discover control plane os image: %v", err)
tfFlags, errFlags := ControlPlaneImageFlags(tc.provider, osControlPlane)
if errFlags != nil {
t.Fatalf("failed to discover control plane os image: %v", errFlags)
}
args = append(args, tfFlags...)
}
Expand Down Expand Up @@ -203,16 +210,16 @@ func TestClusterConformance(t *testing.T) {
t.Log("Adding other control plane nodes to the load balancer…")
args = []string{}
if osControlPlane != OperatingSystemDefault {
tfFlags, err := ControlPlaneImageFlags(tc.provider, osControlPlane)
if err != nil {
t.Fatalf("failed to discover control plane os image: %v", err)
tfFlags, errFlags := ControlPlaneImageFlags(tc.provider, osControlPlane)
if errFlags != nil {
t.Fatalf("failed to discover control plane os image: %v", errFlags)
}
args = append(args, tfFlags...)
}
if osWorkers != OperatingSystemDefault {
args = append(args, "-var", fmt.Sprintf("worker_os=%s", osWorkers))
}
tf, err = pr.Provision(args...)
_, err = pr.Provision(args...)
if err != nil {
t.Fatalf("failed to provision the infrastructure: %v", err)
}
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/kubetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func NewKubetest(k8sVersion, kubetestDir string, envVars map[string]string) Kube
kubernetesVersion: k8sVersion,
envVars: envVars,
}

}

// Verify verifies the cluster
Expand Down Expand Up @@ -78,7 +77,6 @@ func (p *Kubetest) Verify(scenario string) error {

// getK8sBinaries retrieves kubernetes binaries for version
func getK8sBinaries(kubetestDir string, version string) error {

k8sPath := fmt.Sprintf("%s/kubernetes-%s", kubetestDir, version)
err := os.MkdirAll(k8sPath, 0755)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func verifyVersion(client dynclient.Client, namespace string, targetVersion stri

// Kubelet version check
for _, n := range nodes.Items {
kubeletVer, err := semver.NewVersion(n.Status.NodeInfo.KubeletVersion)
if err != nil {
return err
kubeletVer, errSemver := semver.NewVersion(n.Status.NodeInfo.KubeletVersion)
if errSemver != nil {
return errSemver
}
if reqVer.Compare(kubeletVer) != 0 {
return errors.Errorf("kubelet version mismatch: expected %v, got %v", reqVer.String(), kubeletVer.String())
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ func IsCommandAvailable(name string) bool {

// ExecuteCommand executes the given command
func ExecuteCommand(path, name string, arg []string, additionalEnv map[string]string) (string, error) {
var stdoutBuf, stderrBuf bytes.Buffer
var errStdout, errStderr error
var (
stdoutBuf, stderrBuf bytes.Buffer
errStdout, errStderr error
)

cmd := exec.Command(name, arg...)
if len(path) > 0 {
Expand Down Expand Up @@ -74,7 +76,6 @@ func ExecuteCommand(path, name string, arg []string, additionalEnv map[string]st
go func() {
_, errStdout = io.Copy(stdout, stdoutIn)
doneStdout <- struct{}{}

}()

go func() {
Expand All @@ -95,7 +96,7 @@ func ExecuteCommand(path, name string, arg []string, additionalEnv map[string]st
return "", errStderr
}

outStr := string(stdoutBuf.Bytes())
outStr := stdoutBuf.String()
return outStr, nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestClusterUpgrade(t *testing.T) {
// Run Terraform again for GCE to add nodes to the load balancer
if tc.provider == provisioner.GCE {
t.Log("Adding other control plane nodes to the load balancer…")
tf, err = pr.Provision()
_, err = pr.Provision()
if err != nil {
t.Fatalf("failed to provision the infrastructure: %v", err)
}
Expand Down

0 comments on commit 0ed7b26

Please sign in to comment.