mirror of
https://github.com/rancher/rke.git
synced 2025-04-27 19:25:44 +00:00
Merge pull request #2564 from superseb/golangcilint_v0401
Use golangci-lint v1.40.1
This commit is contained in:
commit
ff49352399
47
.golangci.json
Normal file
47
.golangci.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"linters": {
|
||||
"disable-all": true,
|
||||
"enable": [
|
||||
"govet",
|
||||
"revive",
|
||||
"goimports",
|
||||
"misspell",
|
||||
"ineffassign",
|
||||
"gofmt"
|
||||
]
|
||||
},
|
||||
"linters-settings": {
|
||||
"govet": {
|
||||
"check-shadowing": false
|
||||
},
|
||||
"gofmt": {
|
||||
"simplify": false
|
||||
}
|
||||
},
|
||||
"run": {
|
||||
"skip-dirs": [
|
||||
"vendor",
|
||||
"tests",
|
||||
"pkg/client",
|
||||
"pkg/generated"
|
||||
],
|
||||
"tests": false,
|
||||
"timeout": "10m"
|
||||
},
|
||||
"issues": {
|
||||
"exclude-rules": [
|
||||
{
|
||||
"linters": "govet",
|
||||
"text": "^(nilness|structtag)"
|
||||
},
|
||||
{
|
||||
"linters": "revive",
|
||||
"text": "should have comment"
|
||||
},
|
||||
{
|
||||
"linters": "revive",
|
||||
"text": "should be of the form"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -11,8 +11,9 @@ RUN apt-get update && \
|
||||
ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm=armv6l GOLANG_ARCH_arm64=arm64 GOLANG_ARCH=GOLANG_ARCH_${ARCH} \
|
||||
GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash
|
||||
|
||||
RUN wget -O - https://storage.googleapis.com/golang/go1.16.4.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local && \
|
||||
go get golang.org/x/lint/golint
|
||||
RUN wget -O - https://storage.googleapis.com/golang/go1.16.4.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local
|
||||
|
||||
RUN curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.40.1
|
||||
|
||||
ENV DOCKER_URL_amd64=https://get.docker.com/builds/Linux/x86_64/docker-1.10.3 \
|
||||
DOCKER_URL_arm=https://github.com/rancher/docker/releases/download/v1.10.3-ros1/docker-1.10.3_arm \
|
||||
|
@ -2,9 +2,10 @@ package addons
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"k8s.io/client-go/transport"
|
||||
"strconv"
|
||||
|
||||
"k8s.io/client-go/transport"
|
||||
|
||||
"github.com/rancher/rke/k8s"
|
||||
"github.com/rancher/rke/templates"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -525,10 +525,7 @@ func (c *Cluster) doAddonDelete(ctx context.Context, resourceName string, isCrit
|
||||
return err
|
||||
}
|
||||
|
||||
if err := k8s.DeleteK8sSystemJob(deleteJob, k8sClient, c.AddonJobTimeout); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k8s.DeleteK8sSystemJob(deleteJob, k8sClient, c.AddonJobTimeout)
|
||||
|
||||
}
|
||||
|
||||
@ -562,10 +559,7 @@ func (c *Cluster) StoreAddonConfigMap(ctx context.Context, addonYaml string, add
|
||||
}
|
||||
|
||||
func (c *Cluster) ApplySystemAddonExecuteJob(addonJob string, addonUpdated bool) error {
|
||||
if err := k8s.ApplyK8sSystemJob(addonJob, c.LocalKubeConfigPath, c.K8sWrapTransport, c.AddonJobTimeout, addonUpdated); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k8s.ApplyK8sSystemJob(addonJob, c.LocalKubeConfigPath, c.K8sWrapTransport, c.AddonJobTimeout, addonUpdated)
|
||||
}
|
||||
|
||||
func (c *Cluster) deployIngress(ctx context.Context, data map[string]interface{}) error {
|
||||
|
@ -186,7 +186,7 @@ func GetClusterCertsFromNodes(ctx context.Context, kubeCluster *Cluster) (map[st
|
||||
log.Infof(ctx, "[certificates] Fetching kubernetes certificates from nodes")
|
||||
var err error
|
||||
backupHosts := hosts.GetUniqueHostList(kubeCluster.EtcdHosts, kubeCluster.ControlPlaneHosts, nil)
|
||||
certificates := map[string]pki.CertificatePKI{}
|
||||
var certificates map[string]pki.CertificatePKI
|
||||
for _, host := range backupHosts {
|
||||
certificates, err = pki.FetchCertificatesFromHost(ctx, kubeCluster.EtcdHosts, host, kubeCluster.SystemImages.Alpine, kubeCluster.LocalKubeConfigPath, kubeCluster.PrivateRegistriesMap)
|
||||
if certificates != nil {
|
||||
|
@ -514,10 +514,7 @@ func parseIngressConfig(clusterFile string, rkeConfig *v3.RancherKubernetesEngin
|
||||
if err := parseIngressExtraVolumes(ingressMap, rkeConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := parseIngressExtraVolumeMounts(ingressMap, rkeConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return parseIngressExtraVolumeMounts(ingressMap, rkeConfig)
|
||||
}
|
||||
|
||||
func parseDaemonSetUpdateStrategy(updateStrategyField interface{}) (*v3.DaemonSetUpdateStrategy, error) {
|
||||
@ -1100,10 +1097,7 @@ func RestartClusterPods(ctx context.Context, kubeCluster *Cluster) error {
|
||||
return util.ErrList(errList)
|
||||
})
|
||||
}
|
||||
if err := errgrp.Wait(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return errgrp.Wait()
|
||||
}
|
||||
|
||||
func IsLegacyKubeAPI(ctx context.Context, kubeCluster *Cluster) (bool, error) {
|
||||
|
@ -335,11 +335,7 @@ func (c *Cluster) updateEncryptionProvider(ctx context.Context, keys []*encrypti
|
||||
if err := c.UpdateClusterCurrentState(ctx, fullState); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := services.RestartKubeAPIWithHealthcheck(ctx, c.ControlPlaneHosts, c.LocalConnDialerFactory, c.Certificates); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return services.RestartKubeAPIWithHealthcheck(ctx, c.ControlPlaneHosts, c.LocalConnDialerFactory, c.Certificates)
|
||||
}
|
||||
|
||||
func (c *Cluster) DeployEncryptionProviderFile(ctx context.Context) error {
|
||||
@ -525,7 +521,7 @@ func resolveCustomEncryptionConfig(clusterFile string) (string, *apiserverconfig
|
||||
var r map[string]interface{}
|
||||
err = ghodssyaml.Unmarshal([]byte(clusterFile), &r)
|
||||
if err != nil {
|
||||
return clusterFile, nil, fmt.Errorf("error unmarshalling: %v", err)
|
||||
return clusterFile, nil, fmt.Errorf("error unmarshalling clusterfile: %v", err)
|
||||
}
|
||||
services, ok := r["services"].(map[string]interface{})
|
||||
if services == nil || !ok {
|
||||
@ -544,6 +540,9 @@ func resolveCustomEncryptionConfig(clusterFile string) (string, *apiserverconfig
|
||||
if ok && customConfig != nil {
|
||||
delete(sec, "custom_config")
|
||||
newClusterFile, err := ghodssyaml.Marshal(r)
|
||||
if err != nil {
|
||||
return clusterFile, nil, fmt.Errorf("error marshalling clusterfile: %v", err)
|
||||
}
|
||||
c, err := parseCustomConfig(customConfig)
|
||||
return string(newClusterFile), c, err
|
||||
}
|
||||
|
@ -61,10 +61,7 @@ func (c *Cluster) DeployRestoreCerts(ctx context.Context, clusterCerts map[strin
|
||||
return util.ErrList(errList)
|
||||
})
|
||||
}
|
||||
if err := errgrp.Wait(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return errgrp.Wait()
|
||||
}
|
||||
|
||||
func (c *Cluster) DeployStateFile(ctx context.Context, stateFilePath, snapshotName string) error {
|
||||
@ -92,10 +89,7 @@ func (c *Cluster) DeployStateFile(ctx context.Context, stateFilePath, snapshotNa
|
||||
return util.ErrList(errList)
|
||||
})
|
||||
}
|
||||
if err := errgrp.Wait(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return errgrp.Wait()
|
||||
}
|
||||
|
||||
func (c *Cluster) GetStateFileFromSnapshot(ctx context.Context, snapshotName string) (string, error) {
|
||||
|
@ -456,6 +456,9 @@ func (c *Cluster) doAciDeploy(ctx context.Context, data map[string]interface{})
|
||||
}
|
||||
podIPStart, podIPEnd := cidr.AddressRange(clusterCIDR)
|
||||
_, staticExternalSubnet, err := net.ParseCIDR(c.Network.Options[AciStaticExternalSubnet])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
staticServiceIPStart, staticServiceIPEnd := cidr.AddressRange(staticExternalSubnet)
|
||||
_, svcGraphSubnet, err := net.ParseCIDR(c.Network.Options[AciServiceGraphSubnet])
|
||||
if err != nil {
|
||||
|
@ -116,10 +116,7 @@ func reconcileControl(ctx context.Context, currentCluster, kubeCluster *Cluster,
|
||||
if len(cpToDelete) == len(currentCluster.ControlPlaneHosts) {
|
||||
log.Infof(ctx, "[reconcile] Deleting all current controlplane nodes, skipping deleting from k8s cluster")
|
||||
// rebuilding local admin config to enable saving cluster state
|
||||
if err := rebuildLocalAdminConfig(ctx, kubeCluster); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return rebuildLocalAdminConfig(ctx, kubeCluster)
|
||||
}
|
||||
for _, toDeleteHost := range cpToDelete {
|
||||
if err := cleanControlNode(ctx, kubeCluster, currentCluster, toDeleteHost); err != nil {
|
||||
@ -127,10 +124,7 @@ func reconcileControl(ctx context.Context, currentCluster, kubeCluster *Cluster,
|
||||
}
|
||||
}
|
||||
// rebuilding local admin config to enable saving cluster state
|
||||
if err := rebuildLocalAdminConfig(ctx, kubeCluster); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return rebuildLocalAdminConfig(ctx, kubeCluster)
|
||||
}
|
||||
|
||||
func reconcileHost(ctx context.Context, toDeleteHost *hosts.Host, worker, etcd bool, cluster *Cluster) error {
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/rancher/rke/pki"
|
||||
"github.com/rancher/rke/services"
|
||||
"github.com/rancher/rke/util"
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
)
|
||||
|
||||
@ -308,11 +308,7 @@ func validateServicesOptions(c *Cluster) error {
|
||||
}
|
||||
|
||||
// validate etcd s3 backup backend configurations
|
||||
if err := validateEtcdBackupOptions(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return validateEtcdBackupOptions(c)
|
||||
}
|
||||
|
||||
func validateEtcdBackupOptions(c *Cluster) error {
|
||||
@ -436,10 +432,7 @@ func validateSystemImages(c *Cluster) error {
|
||||
if err := validateMetricsImages(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateIngressImages(c); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return validateIngressImages(c)
|
||||
}
|
||||
|
||||
func validateKubernetesImages(c *Cluster) error {
|
||||
|
16
cmd/util.go
16
cmd/util.go
@ -84,11 +84,7 @@ func getKubeconfigFile(ctx *cli.Context) error {
|
||||
}
|
||||
kubeCluster, _ := tempCluster.GetClusterState(context.Background(), clusterState)
|
||||
|
||||
if err := cluster.RebuildKubeconfig(context.Background(), kubeCluster); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return cluster.RebuildKubeconfig(context.Background(), kubeCluster)
|
||||
}
|
||||
|
||||
func getStateFile(ctx *cli.Context) error {
|
||||
@ -128,7 +124,13 @@ func getStateFile(ctx *cli.Context) error {
|
||||
logrus.Infof("Successfully connected to server using kubeconfig, retrieved server version [%s]", serverVersion)
|
||||
// Retrieve full-cluster-state configmap
|
||||
k8sClient, err := k8s.NewClient(localKubeConfig, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfgMap, err := k8s.GetConfigMap(k8sClient, cluster.FullStateConfigMapName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
clusterData := cfgMap.Data[cluster.FullStateConfigMapName]
|
||||
rkeFullState := &cluster.FullState{}
|
||||
if err = json.Unmarshal([]byte(clusterData), rkeFullState); err != nil {
|
||||
@ -180,6 +182,10 @@ func RetrieveClusterStateConfigMap(
|
||||
}
|
||||
rkeFullState, err = cluster.StringToFullState(ctx, stateFile)
|
||||
|
||||
if err != nil {
|
||||
return APIURL, caCrt, clientCert, clientKey, nil, err
|
||||
}
|
||||
|
||||
// Move current state file
|
||||
stateFilePath := cluster.GetStateFilePath(flags.ClusterFilePath, flags.ConfigDir)
|
||||
err = util.ReplaceFileWithBackup(stateFilePath, "rkestate")
|
||||
|
@ -107,10 +107,7 @@ func DeployStateOnPlaneHost(ctx context.Context, host *hosts.Host, stateDownload
|
||||
return err
|
||||
}
|
||||
|
||||
if err := docker.DoRemoveContainer(ctx, host.DClient, StateDeployerContainerName, host.Address); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return docker.DoRemoveContainer(ctx, host.DClient, StateDeployerContainerName, host.Address)
|
||||
}
|
||||
|
||||
func doRunDeployer(ctx context.Context, host *hosts.Host, containerEnv []string, certDownloaderImage string, prsMap map[string]v3.PrivateRegistry) error {
|
||||
|
@ -5,16 +5,5 @@ cd $(dirname $0)/..
|
||||
|
||||
echo Running validation
|
||||
|
||||
PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin|data)' | sed -e 's!^!./!' -e 's!$!/...!')"
|
||||
|
||||
echo Running: go vet
|
||||
go vet ${PACKAGES}
|
||||
echo Running: golint
|
||||
for i in ${PACKAGES}; do
|
||||
if [ -n "$(golint $i | grep -v 'should have comment.*or be unexported' | tee /dev/stderr)" ]; then
|
||||
failed=true
|
||||
fi
|
||||
done
|
||||
test -z "$failed"
|
||||
echo Running: go fmt
|
||||
test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"
|
||||
echo Running: golangci-lint
|
||||
golangci-lint run
|
||||
|
@ -198,10 +198,7 @@ func startNewControlHost(ctx context.Context, runHost *hosts.Host, localConnDial
|
||||
if err := doDeployControlHost(ctx, runHost, localConnDialerFactory, prsMap, cpNodePlanMap[runHost.Address].Processes, alpineImage, certMap); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := doDeployWorkerPlaneHost(ctx, runHost, localConnDialerFactory, prsMap, cpNodePlanMap[runHost.Address].Processes, certMap, updateWorkersOnly, alpineImage); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return doDeployWorkerPlaneHost(ctx, runHost, localConnDialerFactory, prsMap, cpNodePlanMap[runHost.Address].Processes, certMap, updateWorkersOnly, alpineImage)
|
||||
}
|
||||
|
||||
func checkHostUpgradable(ctx context.Context, runHost *hosts.Host, cpNodePlanMap map[string]v3.RKEConfigNodePlan) (bool, bool, error) {
|
||||
@ -239,10 +236,7 @@ func upgradeControlHost(ctx context.Context, kubeClient *kubernetes.Clientset, h
|
||||
if err := CheckNodeReady(kubeClient, host, ControlRole); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := k8s.CordonUncordon(kubeClient, host.HostnameOverride, false); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k8s.CordonUncordon(kubeClient, host.HostnameOverride, false)
|
||||
}
|
||||
|
||||
func RemoveControlPlane(ctx context.Context, controlHosts []*hosts.Host, force bool) error {
|
||||
|
@ -206,10 +206,7 @@ func upgradeWorkerHost(ctx context.Context, kubeClient *kubernetes.Clientset, ru
|
||||
return err
|
||||
}
|
||||
// uncordon node
|
||||
if err := k8s.CordonUncordon(kubeClient, runHost.HostnameOverride, false); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k8s.CordonUncordon(kubeClient, runHost.HostnameOverride, false)
|
||||
}
|
||||
|
||||
func doDeployWorkerPlaneHost(ctx context.Context, host *hosts.Host, localConnDialerFactory hosts.DialerFactory, prsMap map[string]v3.PrivateRegistry, processMap map[string]v3.Process, certMap map[string]pki.CertificatePKI, updateWorkersOnly bool, alpineImage string) error {
|
||||
|
@ -21,7 +21,7 @@ type RancherKubernetesEngineConfig struct {
|
||||
Addons string `yaml:"addons" json:"addons,omitempty"`
|
||||
// List of urls or paths for addons
|
||||
AddonsInclude []string `yaml:"addons_include" json:"addonsInclude,omitempty"`
|
||||
// List of images used internally for proxy, cert downlaod and kubedns
|
||||
// List of images used internally for proxy, cert download and kubedns
|
||||
SystemImages RKESystemImages `yaml:"system_images" json:"systemImages,omitempty"`
|
||||
// SSH Private Key Path
|
||||
SSHKeyPath string `yaml:"ssh_key_path" json:"sshKeyPath,omitempty" norman:"nocreate,noupdate"`
|
||||
@ -33,7 +33,7 @@ type RancherKubernetesEngineConfig struct {
|
||||
Authorization AuthzConfig `yaml:"authorization" json:"authorization,omitempty"`
|
||||
// Enable/disable strict docker version checking
|
||||
IgnoreDockerVersion *bool `yaml:"ignore_docker_version" json:"ignoreDockerVersion" norman:"default=true"`
|
||||
// Kubernetes version to use (if kubernetes image is specifed, image version takes precedence)
|
||||
// Kubernetes version to use (if kubernetes image is specified, image version takes precedence)
|
||||
Version string `yaml:"kubernetes_version" json:"kubernetesVersion,omitempty"`
|
||||
// List of private registries and their credentials
|
||||
PrivateRegistries []PrivateRegistry `yaml:"private_registries" json:"privateRegistries,omitempty"`
|
||||
|
Loading…
Reference in New Issue
Block a user