mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Clean up kubeadm.
These are based on recommendation from [staticcheck](http://staticcheck.io/). - Remove unused struct fields - Remove unused function - Remove unused variables - Remove unused constants. - Miscellaneous cleanups
This commit is contained in:
parent
5189f24a75
commit
a2b0cb62a1
@ -117,7 +117,6 @@ type initData struct {
|
|||||||
dryRunDir string
|
dryRunDir string
|
||||||
externalCA bool
|
externalCA bool
|
||||||
client clientset.Interface
|
client clientset.Interface
|
||||||
waiter apiclient.Waiter
|
|
||||||
outputWriter io.Writer
|
outputWriter io.Writer
|
||||||
uploadCerts bool
|
uploadCerts bool
|
||||||
certificateKey string
|
certificateKey string
|
||||||
|
@ -138,7 +138,6 @@ var _ phases.JoinData = &joinData{}
|
|||||||
// this data is shared across all the phases that are included in the workflow.
|
// this data is shared across all the phases that are included in the workflow.
|
||||||
type joinData struct {
|
type joinData struct {
|
||||||
cfg *kubeadmapi.JoinConfiguration
|
cfg *kubeadmapi.JoinConfiguration
|
||||||
skipTokenPrint bool
|
|
||||||
initCfg *kubeadmapi.InitConfiguration
|
initCfg *kubeadmapi.InitConfiguration
|
||||||
tlsBootstrapCfg *clientcmdapi.Config
|
tlsBootstrapCfg *clientcmdapi.Config
|
||||||
clientSet *clientset.Clientset
|
clientSet *clientset.Clientset
|
||||||
@ -187,7 +186,7 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
|||||||
} else {
|
} else {
|
||||||
// otherwise, if the node joined as a worker node;
|
// otherwise, if the node joined as a worker node;
|
||||||
// outputs the join done message and exit
|
// outputs the join done message and exit
|
||||||
fmt.Fprintf(data.outputWriter, joinWorkerNodeDoneMsg)
|
fmt.Fprint(data.outputWriter, joinWorkerNodeDoneMsg)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// We accept the control-plane location as an optional positional argument
|
// We accept the control-plane location as an optional positional argument
|
||||||
|
@ -100,7 +100,6 @@ func TestCompileManifests(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
manifest string
|
manifest string
|
||||||
data interface{}
|
data interface{}
|
||||||
expected bool
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "KubeProxyConfigMap19",
|
name: "KubeProxyConfigMap19",
|
||||||
|
@ -376,7 +376,7 @@ func TestWriteKeyFilesIfNotExist(t *testing.T) {
|
|||||||
t.Fatalf("Failed to marshal expected private key: %v", err)
|
t.Fatalf("Failed to marshal expected private key: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(resultingKeyPEM, expectedKeyPEM) != 0 {
|
if !bytes.Equal(resultingKeyPEM, expectedKeyPEM) {
|
||||||
t.Error("created key does not match expected key")
|
t.Error("created key does not match expected key")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -736,7 +736,6 @@ func TestNewCSR(t *testing.T) {
|
|||||||
func TestCreateCertificateFilesMethods(t *testing.T) {
|
func TestCreateCertificateFilesMethods(t *testing.T) {
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
setupFunc func(cfg *kubeadmapi.InitConfiguration) error
|
|
||||||
createFunc func(cfg *kubeadmapi.InitConfiguration) error
|
createFunc func(cfg *kubeadmapi.InitConfiguration) error
|
||||||
expectedFiles []string
|
expectedFiles []string
|
||||||
externalEtcd bool
|
externalEtcd bool
|
||||||
|
@ -521,12 +521,8 @@ func TestGetHostPathVolumesForTheControlPlane(t *testing.T) {
|
|||||||
mounts := getHostPathVolumesForTheControlPlane(rt.cfg)
|
mounts := getHostPathVolumesForTheControlPlane(rt.cfg)
|
||||||
|
|
||||||
// Avoid unit test errors when the flexvolume is mounted
|
// Avoid unit test errors when the flexvolume is mounted
|
||||||
if _, ok := mounts.volumes[kubeadmconstants.KubeControllerManager][flexvolumeDirVolumeName]; ok {
|
|
||||||
delete(mounts.volumes[kubeadmconstants.KubeControllerManager], flexvolumeDirVolumeName)
|
delete(mounts.volumes[kubeadmconstants.KubeControllerManager], flexvolumeDirVolumeName)
|
||||||
}
|
|
||||||
if _, ok := mounts.volumeMounts[kubeadmconstants.KubeControllerManager][flexvolumeDirVolumeName]; ok {
|
|
||||||
delete(mounts.volumeMounts[kubeadmconstants.KubeControllerManager], flexvolumeDirVolumeName)
|
delete(mounts.volumeMounts[kubeadmconstants.KubeControllerManager], flexvolumeDirVolumeName)
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(mounts.volumes, rt.vol) {
|
if !reflect.DeepEqual(mounts.volumes, rt.vol) {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"failed getHostPathVolumesForTheControlPlane:\n\texpected: %v\n\t actual: %v",
|
"failed getHostPathVolumesForTheControlPlane:\n\texpected: %v\n\t actual: %v",
|
||||||
@ -632,7 +628,7 @@ func TestAddExtraHostPathMounts(t *testing.T) {
|
|||||||
if *vol.HostPath.Type != v1.HostPathType(hostMount.PathType) {
|
if *vol.HostPath.Type != v1.HostPathType(hostMount.PathType) {
|
||||||
t.Errorf("Expected to host path type %q", hostMount.PathType)
|
t.Errorf("Expected to host path type %q", hostMount.PathType)
|
||||||
}
|
}
|
||||||
volMount, _ := mounts.volumeMounts["component"][volumeName]
|
volMount := mounts.volumeMounts["component"][volumeName]
|
||||||
if volMount.Name != volumeName {
|
if volMount.Name != volumeName {
|
||||||
t.Errorf("Expected volume mount name %q", volumeName)
|
t.Errorf("Expected volume mount name %q", volumeName)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func MarkControlPlane(client clientset.Interface, controlPlaneName string, taint
|
|||||||
|
|
||||||
fmt.Printf("[mark-control-plane] Marking the node %s as control-plane by adding the label \"%s=''\"\n", controlPlaneName, constants.LabelNodeRoleMaster)
|
fmt.Printf("[mark-control-plane] Marking the node %s as control-plane by adding the label \"%s=''\"\n", controlPlaneName, constants.LabelNodeRoleMaster)
|
||||||
|
|
||||||
if taints != nil && len(taints) > 0 {
|
if len(taints) > 0 {
|
||||||
taintStrs := []string{}
|
taintStrs := []string{}
|
||||||
for _, taint := range taints {
|
for _, taint := range taints {
|
||||||
taintStrs = append(taintStrs, taint.ToString())
|
taintStrs = append(taintStrs, taint.ToString())
|
||||||
|
@ -19,7 +19,6 @@ package upgrade
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
@ -41,8 +40,6 @@ import (
|
|||||||
dryrunutil "k8s.io/kubernetes/cmd/kubeadm/app/util/dryrun"
|
dryrunutil "k8s.io/kubernetes/cmd/kubeadm/app/util/dryrun"
|
||||||
)
|
)
|
||||||
|
|
||||||
var expiry = 180 * 24 * time.Hour
|
|
||||||
|
|
||||||
// PerformPostUpgradeTasks runs nearly the same functions as 'kubeadm init' would do
|
// PerformPostUpgradeTasks runs nearly the same functions as 'kubeadm init' would do
|
||||||
// Note that the mark-control-plane phase is left out, not needed, and no token is created as that doesn't belong to the upgrade
|
// Note that the mark-control-plane phase is left out, not needed, and no token is created as that doesn't belong to the upgrade
|
||||||
func PerformPostUpgradeTasks(client clientset.Interface, cfg *kubeadmapi.InitConfiguration, newK8sVer *version.Version, dryRun bool) error {
|
func PerformPostUpgradeTasks(client clientset.Interface, cfg *kubeadmapi.InitConfiguration, newK8sVer *version.Version, dryRun bool) error {
|
||||||
|
@ -45,13 +45,6 @@ func GetCgroupDriverDocker(execer utilsexec.Interface) (string, error) {
|
|||||||
return strings.TrimSuffix(driver, "\n"), nil
|
return strings.TrimSuffix(driver, "\n"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateCgroupDriver(driver string) error {
|
|
||||||
if driver != CgroupDriverCgroupfs && driver != CgroupDriverSystemd {
|
|
||||||
return errors.Errorf("unknown cgroup driver %q", driver)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func callDockerInfo(execer utilsexec.Interface) (string, error) {
|
func callDockerInfo(execer utilsexec.Interface) (string, error) {
|
||||||
out, err := execer.Command("docker", "info", "-f", "{{.CgroupDriver}}").Output()
|
out, err := execer.Command("docker", "info", "-f", "{{.CgroupDriver}}").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -29,17 +29,6 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
controlPlaneV1beta1YAML = "testdata/conversion/controlplane/v1beta1.yaml"
|
|
||||||
controlPlaneV1beta1YAMLNonLinux = "testdata/conversion/controlplane/v1beta1_non_linux.yaml"
|
|
||||||
controlPlaneInternalYAML = "testdata/conversion/controlplane/internal.yaml"
|
|
||||||
controlPlaneInternalYAMLNonLinux = "testdata/conversion/controlplane/internal_non_linux.yaml"
|
|
||||||
controlPlaneIncompleteYAML = "testdata/defaulting/controlplane/incomplete.yaml"
|
|
||||||
controlPlaneDefaultedYAML = "testdata/defaulting/controlplane/defaulted.yaml"
|
|
||||||
controlPlaneDefaultedYAMLNonLinux = "testdata/defaulting/controlplane/defaulted_non_linux.yaml"
|
|
||||||
controlPlaneInvalidYAML = "testdata/validation/invalid_controlplanecfg.yaml"
|
|
||||||
)
|
|
||||||
|
|
||||||
func diff(expected, actual []byte) string {
|
func diff(expected, actual []byte) string {
|
||||||
// Write out the diff
|
// Write out the diff
|
||||||
var diffBytes bytes.Buffer
|
var diffBytes bytes.Buffer
|
||||||
|
@ -109,9 +109,7 @@ func (runtime *CRIRuntime) ListKubeContainers() ([]string, error) {
|
|||||||
return nil, errors.Wrapf(err, "output: %s, error", string(out))
|
return nil, errors.Wrapf(err, "output: %s, error", string(out))
|
||||||
}
|
}
|
||||||
pods := []string{}
|
pods := []string{}
|
||||||
for _, pod := range strings.Fields(string(out)) {
|
pods = append(pods, strings.Fields(string(out))...)
|
||||||
pods = append(pods, pod)
|
|
||||||
}
|
|
||||||
return pods, nil
|
return pods, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,10 @@ package system
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidationResultType is type of the validation result. Different validation results
|
// ValidationResultType is type of the validation result. Different validation results
|
||||||
@ -38,9 +39,9 @@ type color int32
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
red color = 31
|
red color = 31
|
||||||
green = 32
|
green color = 32
|
||||||
yellow = 33
|
yellow color = 33
|
||||||
white = 37
|
white color = 37
|
||||||
)
|
)
|
||||||
|
|
||||||
func colorize(s string, c color) string {
|
func colorize(s string, c color) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user