Merge pull request #84626 from hwdef/fix-staticcheck1

cmd/kubeadm/app: fix staticcheck warning
This commit is contained in:
Kubernetes Prow Robot 2019-11-01 10:21:40 -07:00 committed by GitHub
commit 529d5dd4b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 29 deletions

View File

@ -32,7 +32,6 @@ import (
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/copycerts"
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
@ -80,7 +79,7 @@ func newCmdCertsUtility(out io.Writer) *cobra.Command {
}
cmd.AddCommand(newCmdCertsRenewal())
cmd.AddCommand(newCmdCertsExpiration(out, kubeadmconstants.KubernetesDir))
cmd.AddCommand(newCmdCertsExpiration(out, constants.KubernetesDir))
cmd.AddCommand(NewCmdCertificateKey())
return cmd
}
@ -112,7 +111,7 @@ func newCmdCertsRenewal() *cobra.Command {
RunE: cmdutil.SubCmdRunE("renew"),
}
cmd.AddCommand(getRenewSubCommands(kubeadmconstants.KubernetesDir)...)
cmd.AddCommand(getRenewSubCommands(constants.KubernetesDir)...)
return cmd
}

View File

@ -28,7 +28,6 @@ import (
"github.com/spf13/cobra"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
kubeconfigphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubeconfig"
"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
@ -266,7 +265,7 @@ func TestRunRenewCommands(t *testing.T) {
func TestRenewUsingCSR(t *testing.T) {
tmpDir := testutil.SetupTempDir(t)
defer os.RemoveAll(tmpDir)
cert := &certs.KubeadmCertEtcdServer
cert := &certsphase.KubeadmCertEtcdServer
cfg := testutil.GetDefaultInternalConfig(t)
cfg.CertificatesDir = tmpDir

View File

@ -31,7 +31,6 @@ import (
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
@ -58,7 +57,7 @@ var (
// NewCmdDiff returns the cobra command for `kubeadm upgrade diff`
func NewCmdDiff(out io.Writer) *cobra.Command {
flags := &diffFlags{
kubeConfigPath: kubeadmconstants.GetAdminKubeConfigPath(),
kubeConfigPath: constants.GetAdminKubeConfigPath(),
out: out,
}

View File

@ -29,7 +29,6 @@ import (
phases "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/upgrade/node"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
)
@ -130,7 +129,7 @@ func newNodeData(cmd *cobra.Command, args []string, options *nodeOptions) (*node
// isControlPlane checks if a node is a control-plane node by looking up
// the kube-apiserver manifest file
isControlPlaneNode := true
filepath := kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.KubeAPIServer, kubeadmconstants.GetStaticPodDirectory())
filepath := constants.GetStaticPodFilepath(constants.KubeAPIServer, constants.GetStaticPodDirectory())
if _, err := os.Stat(filepath); os.IsNotExist(err) {
isControlPlaneNode = false
}

View File

@ -32,7 +32,6 @@ import (
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
controlplanephase "k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
etcdphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/etcd"
"k8s.io/kubernetes/cmd/kubeadm/app/util"
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
@ -464,7 +463,7 @@ func StaticPodControlPlane(client clientset.Interface, waiter apiclient.Waiter,
// Write the updated static Pod manifests into the temporary directory
fmt.Printf("[upgrade/staticpods] Writing new Static Pod manifests to %q\n", pathMgr.TempManifestDir())
err = controlplanephase.CreateInitStaticPodManifestFiles(pathMgr.TempManifestDir(), pathMgr.KustomizeDir(), cfg)
err = controlplane.CreateInitStaticPodManifestFiles(pathMgr.TempManifestDir(), pathMgr.KustomizeDir(), cfg)
if err != nil {
return errors.Wrap(err, "error creating init static pod manifest files")
}

View File

@ -35,7 +35,6 @@ import (
certutil "k8s.io/client-go/util/cert"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal"
controlplanephase "k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
@ -432,7 +431,7 @@ func TestStaticPodControlPlane(t *testing.T) {
moveFileFunc: func(oldPath, newPath string) error {
return os.Rename(oldPath, newPath)
},
skipKubeConfig: kubeadmconstants.SchedulerKubeConfigFileName,
skipKubeConfig: constants.SchedulerKubeConfigFileName,
expectedErr: true,
manifestShouldChange: false,
},
@ -446,7 +445,7 @@ func TestStaticPodControlPlane(t *testing.T) {
moveFileFunc: func(oldPath, newPath string) error {
return os.Rename(oldPath, newPath)
},
skipKubeConfig: kubeadmconstants.AdminKubeConfigFileName,
skipKubeConfig: constants.AdminKubeConfigFileName,
expectedErr: true,
manifestShouldChange: false,
},
@ -488,9 +487,9 @@ func TestStaticPodControlPlane(t *testing.T) {
}
for _, kubeConfig := range []string{
kubeadmconstants.AdminKubeConfigFileName,
kubeadmconstants.SchedulerKubeConfigFileName,
kubeadmconstants.ControllerManagerKubeConfigFileName,
constants.AdminKubeConfigFileName,
constants.SchedulerKubeConfigFileName,
constants.ControllerManagerKubeConfigFileName,
} {
if rt.skipKubeConfig == kubeConfig {
continue
@ -743,14 +742,14 @@ func TestRenewCertsByComponent(t *testing.T) {
name: "all CA exist, should be rotated for scheduler",
component: constants.KubeScheduler,
kubeConfigShouldExist: []string{
kubeadmconstants.SchedulerKubeConfigFileName,
constants.SchedulerKubeConfigFileName,
},
},
{
name: "all CA exist, should be rotated for controller manager",
component: constants.KubeControllerManager,
kubeConfigShouldExist: []string{
kubeadmconstants.ControllerManagerKubeConfigFileName,
constants.ControllerManagerKubeConfigFileName,
},
},
{
@ -850,7 +849,7 @@ func TestRenewCertsByComponent(t *testing.T) {
t.Errorf("couldn't load new certificate %q: %v", kubeCert.Name, err)
continue
}
oldSerial, _ := certMaps[kubeCert.Name]
oldSerial := certMaps[kubeCert.Name]
shouldBeRenewed := true
if test.certsShouldBeRenewed != nil {
@ -876,7 +875,7 @@ func TestRenewCertsByComponent(t *testing.T) {
if err != nil {
t.Fatalf("error reading embedded certs from %s: %v", kubeConfig, err)
}
oldSerial, _ := certMaps[kubeConfig]
oldSerial := certMaps[kubeConfig]
if oldSerial.Cmp(newCerts[0].SerialNumber) == 0 {
t.Errorf("certifitate %v was not reissued", kubeConfig)
}

View File

@ -121,20 +121,14 @@ func (sysd SystemdInitSystem) ServiceExists(service string) bool {
args := []string{"status", service}
outBytes, _ := exec.Command("systemctl", args...).Output()
output := string(outBytes)
if strings.Contains(output, "Loaded: not-found") {
return false
}
return true
return !strings.Contains(output, "Loaded: not-found")
}
// ServiceIsEnabled ensures the service is enabled to start on each boot.
func (sysd SystemdInitSystem) ServiceIsEnabled(service string) bool {
args := []string{"is-enabled", service}
err := exec.Command("systemctl", args...).Run()
if err != nil {
return false
}
return true
return err == nil
}
// ServiceIsActive will check is the service is "active". In the case of