fix: map and slice create style

This commit is contained in:
demoManito 2022-09-05 17:07:45 +08:00
parent bcea98234f
commit 35c26f48e4
6 changed files with 10 additions and 10 deletions

View File

@ -77,7 +77,7 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
printer.Printf("[upgrade] Fetching available versions to upgrade to\n")
// Collect the upgrades kubeadm can do in this list
upgrades := []Upgrade{}
var upgrades []Upgrade
// Get the cluster version
clusterVersionStr, clusterVersion, err := versionGetterImpl.ClusterVersion()

View File

@ -137,7 +137,7 @@ func TestGetAvailableUpgrades(t *testing.T) {
stableVersion: v1Y0.String(),
},
beforeDNSVersion: fakeCurrentCoreDNSVersion,
expectedUpgrades: []Upgrade{},
expectedUpgrades: nil,
allowExperimental: false,
errExpected: false,
},
@ -342,7 +342,7 @@ func TestGetAvailableUpgrades(t *testing.T) {
latestVersion: v1Z0alpha2.String(),
},
beforeDNSVersion: fakeCurrentCoreDNSVersion,
expectedUpgrades: []Upgrade{},
expectedUpgrades: nil,
allowExperimental: true,
errExpected: false,
},

View File

@ -226,7 +226,7 @@ func controlPlaneNodesReady(client clientset.Interface, _ *kubeadmapi.ClusterCon
// staticPodManifestHealth makes sure the required static pods are presents
func staticPodManifestHealth(_ clientset.Interface, _ *kubeadmapi.ClusterConfiguration) error {
nonExistentManifests := []string{}
var nonExistentManifests []string
for _, component := range constants.ControlPlaneComponents {
manifestFile := constants.GetStaticPodFilepath(component, constants.GetStaticPodDirectory())
if _, err := os.Stat(manifestFile); os.IsNotExist(err) {
@ -241,7 +241,7 @@ func staticPodManifestHealth(_ clientset.Interface, _ *kubeadmapi.ClusterConfigu
// getNotReadyNodes returns a string slice of nodes in the cluster that are NotReady
func getNotReadyNodes(nodes []v1.Node) []string {
notReadyNodes := []string{}
var notReadyNodes []string
for _, node := range nodes {
for _, condition := range node.Status.Conditions {
if condition.Type == v1.NodeReady && condition.Status != v1.ConditionTrue {

View File

@ -169,7 +169,7 @@ func detectUnstableVersionError(newK8sVersion *version.Version, newK8sVersionStr
// detectTooOldKubelets errors out if the kubelet versions are so old that an unsupported skew would happen if the cluster was upgraded
func detectTooOldKubelets(newK8sVersion *version.Version, kubeletVersions map[string]uint16) error {
tooOldKubeletVersions := []string{}
var tooOldKubeletVersions []string
for versionStr := range kubeletVersions {
kubeletVersion, err := version.ParseSemantic(versionStr)

View File

@ -48,7 +48,7 @@ import (
// 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
func PerformPostUpgradeTasks(client clientset.Interface, cfg *kubeadmapi.InitConfiguration, patchesDir string, dryRun bool, out io.Writer) error {
errs := []error{}
var errs []error
// Upload currently used configuration to the cluster
// Note: This is done right in the beginning of cluster initialization; as we might want to make other phases
@ -191,7 +191,7 @@ func GetKubeletDir(dryRun bool) (string, error) {
// moveFiles moves files from one directory to another.
func moveFiles(files map[string]string) error {
filesToRecover := map[string]string{}
filesToRecover := make(map[string]string, len(files))
for from, to := range files {
if err := os.Rename(from, to); err != nil {
return rollbackFiles(filesToRecover, err)

View File

@ -21,7 +21,7 @@ import (
"github.com/pkg/errors"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
versionutil "k8s.io/apimachinery/pkg/util/version"
clientset "k8s.io/client-go/kubernetes"
@ -105,7 +105,7 @@ func (g *KubeVersionGetter) KubeletVersions() (map[string]uint16, error) {
// computeKubeletVersions returns a string-int map that describes how many nodes are of a specific version
func computeKubeletVersions(nodes []v1.Node) map[string]uint16 {
kubeletVersions := map[string]uint16{}
kubeletVersions := make(map[string]uint16)
for _, node := range nodes {
kver := node.Status.NodeInfo.KubeletVersion
if _, found := kubeletVersions[kver]; !found {