mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
fix: map and slice create style
This commit is contained in:
parent
bcea98234f
commit
35c26f48e4
@ -77,7 +77,7 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
|
|||||||
printer.Printf("[upgrade] Fetching available versions to upgrade to\n")
|
printer.Printf("[upgrade] Fetching available versions to upgrade to\n")
|
||||||
|
|
||||||
// Collect the upgrades kubeadm can do in this list
|
// Collect the upgrades kubeadm can do in this list
|
||||||
upgrades := []Upgrade{}
|
var upgrades []Upgrade
|
||||||
|
|
||||||
// Get the cluster version
|
// Get the cluster version
|
||||||
clusterVersionStr, clusterVersion, err := versionGetterImpl.ClusterVersion()
|
clusterVersionStr, clusterVersion, err := versionGetterImpl.ClusterVersion()
|
||||||
|
@ -137,7 +137,7 @@ func TestGetAvailableUpgrades(t *testing.T) {
|
|||||||
stableVersion: v1Y0.String(),
|
stableVersion: v1Y0.String(),
|
||||||
},
|
},
|
||||||
beforeDNSVersion: fakeCurrentCoreDNSVersion,
|
beforeDNSVersion: fakeCurrentCoreDNSVersion,
|
||||||
expectedUpgrades: []Upgrade{},
|
expectedUpgrades: nil,
|
||||||
allowExperimental: false,
|
allowExperimental: false,
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
@ -342,7 +342,7 @@ func TestGetAvailableUpgrades(t *testing.T) {
|
|||||||
latestVersion: v1Z0alpha2.String(),
|
latestVersion: v1Z0alpha2.String(),
|
||||||
},
|
},
|
||||||
beforeDNSVersion: fakeCurrentCoreDNSVersion,
|
beforeDNSVersion: fakeCurrentCoreDNSVersion,
|
||||||
expectedUpgrades: []Upgrade{},
|
expectedUpgrades: nil,
|
||||||
allowExperimental: true,
|
allowExperimental: true,
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
|
@ -226,7 +226,7 @@ func controlPlaneNodesReady(client clientset.Interface, _ *kubeadmapi.ClusterCon
|
|||||||
|
|
||||||
// staticPodManifestHealth makes sure the required static pods are presents
|
// staticPodManifestHealth makes sure the required static pods are presents
|
||||||
func staticPodManifestHealth(_ clientset.Interface, _ *kubeadmapi.ClusterConfiguration) error {
|
func staticPodManifestHealth(_ clientset.Interface, _ *kubeadmapi.ClusterConfiguration) error {
|
||||||
nonExistentManifests := []string{}
|
var nonExistentManifests []string
|
||||||
for _, component := range constants.ControlPlaneComponents {
|
for _, component := range constants.ControlPlaneComponents {
|
||||||
manifestFile := constants.GetStaticPodFilepath(component, constants.GetStaticPodDirectory())
|
manifestFile := constants.GetStaticPodFilepath(component, constants.GetStaticPodDirectory())
|
||||||
if _, err := os.Stat(manifestFile); os.IsNotExist(err) {
|
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
|
// getNotReadyNodes returns a string slice of nodes in the cluster that are NotReady
|
||||||
func getNotReadyNodes(nodes []v1.Node) []string {
|
func getNotReadyNodes(nodes []v1.Node) []string {
|
||||||
notReadyNodes := []string{}
|
var notReadyNodes []string
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
for _, condition := range node.Status.Conditions {
|
for _, condition := range node.Status.Conditions {
|
||||||
if condition.Type == v1.NodeReady && condition.Status != v1.ConditionTrue {
|
if condition.Type == v1.NodeReady && condition.Status != v1.ConditionTrue {
|
||||||
|
@ -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
|
// 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 {
|
func detectTooOldKubelets(newK8sVersion *version.Version, kubeletVersions map[string]uint16) error {
|
||||||
tooOldKubeletVersions := []string{}
|
var tooOldKubeletVersions []string
|
||||||
for versionStr := range kubeletVersions {
|
for versionStr := range kubeletVersions {
|
||||||
|
|
||||||
kubeletVersion, err := version.ParseSemantic(versionStr)
|
kubeletVersion, err := version.ParseSemantic(versionStr)
|
||||||
|
@ -48,7 +48,7 @@ import (
|
|||||||
// 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, patchesDir string, dryRun bool, out io.Writer) error {
|
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
|
// 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
|
// 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.
|
// moveFiles moves files from one directory to another.
|
||||||
func moveFiles(files map[string]string) error {
|
func moveFiles(files map[string]string) error {
|
||||||
filesToRecover := map[string]string{}
|
filesToRecover := make(map[string]string, len(files))
|
||||||
for from, to := range files {
|
for from, to := range files {
|
||||||
if err := os.Rename(from, to); err != nil {
|
if err := os.Rename(from, to); err != nil {
|
||||||
return rollbackFiles(filesToRecover, err)
|
return rollbackFiles(filesToRecover, err)
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
versionutil "k8s.io/apimachinery/pkg/util/version"
|
versionutil "k8s.io/apimachinery/pkg/util/version"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
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
|
// computeKubeletVersions returns a string-int map that describes how many nodes are of a specific version
|
||||||
func computeKubeletVersions(nodes []v1.Node) map[string]uint16 {
|
func computeKubeletVersions(nodes []v1.Node) map[string]uint16 {
|
||||||
kubeletVersions := map[string]uint16{}
|
kubeletVersions := make(map[string]uint16)
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
kver := node.Status.NodeInfo.KubeletVersion
|
kver := node.Status.NodeInfo.KubeletVersion
|
||||||
if _, found := kubeletVersions[kver]; !found {
|
if _, found := kubeletVersions[kver]; !found {
|
||||||
|
Loading…
Reference in New Issue
Block a user