kubeadm: print warnings to stderr

This commit is contained in:
SataQiu 2022-01-11 23:08:59 +08:00
parent a0dfd958d5
commit 218b4dea9f
8 changed files with 20 additions and 14 deletions

View File

@ -22,6 +22,8 @@ import (
"fmt"
"strings"
"k8s.io/klog/v2"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
"k8s.io/kubernetes/cmd/kubeadm/app/preflight"
@ -50,7 +52,7 @@ func runPreflight(c workflow.RunData) error {
}
if !r.ForceReset() {
fmt.Println("[reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.")
klog.Warning("[reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.")
fmt.Print("[reset] Are you sure you want to proceed? [y/N]: ")
s := bufio.NewScanner(r.InputReader())
s.Scan()

View File

@ -19,6 +19,8 @@ package kubelet
import (
"fmt"
"k8s.io/klog/v2"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/util/initsystem"
)
@ -38,7 +40,7 @@ func TryStartKubelet() {
// This runs "systemctl daemon-reload && systemctl restart kubelet"
if err := initSystem.ServiceRestart(kubeadmconstants.Kubelet); err != nil {
fmt.Printf("[kubelet-start] WARNING: unable to start the kubelet service: [%v]\n", err)
klog.Warningf("[kubelet-start] WARNING: unable to start the kubelet service: [%v]\n", err)
fmt.Printf("[kubelet-start] Please ensure kubelet is reloaded and running manually.\n")
}
}
@ -58,7 +60,7 @@ func TryStopKubelet() {
// This runs "systemctl daemon-reload && systemctl stop kubelet"
if err := initSystem.ServiceStop(kubeadmconstants.Kubelet); err != nil {
fmt.Printf("[kubelet-start] WARNING: unable to stop the kubelet service momentarily: [%v]\n", err)
klog.Warningf("[kubelet-start] WARNING: unable to stop the kubelet service momentarily: [%v]\n", err)
}
}
@ -77,6 +79,6 @@ func TryRestartKubelet() {
// This runs "systemctl daemon-reload && systemctl stop kubelet"
if err := initSystem.ServiceRestart(kubeadmconstants.Kubelet); err != nil {
fmt.Printf("[kubelet-start] WARNING: unable to restart the kubelet service momentarily: [%v]\n", err)
klog.Warningf("[kubelet-start] WARNING: unable to restart the kubelet service momentarily: [%v]\n", err)
}
}

View File

@ -95,8 +95,8 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
// Get and output the current latest stable version
stableVersionStr, stableVersion, err := versionGetterImpl.VersionFromCILabel("stable", "stable version")
if err != nil {
fmt.Printf("[upgrade/versions] WARNING: %v\n", err)
fmt.Println("[upgrade/versions] WARNING: Falling back to current kubeadm version as latest stable version")
klog.Warningf("[upgrade/versions] WARNING: %v\n", err)
klog.Warningf("[upgrade/versions] WARNING: Falling back to current kubeadm version as latest stable version")
stableVersionStr, stableVersion = kubeadmVersionStr, kubeadmVersion
} else {
fmt.Printf("[upgrade/versions] Target version: %s\n", stableVersionStr)
@ -146,7 +146,7 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
// Get and output the latest patch version for the cluster branch
patchVersionStr, patchVersion, err := versionGetterImpl.VersionFromCILabel(versionLabel, description)
if err != nil {
fmt.Printf("[upgrade/versions] WARNING: %v\n", err)
klog.Warningf("[upgrade/versions] WARNING: %v\n", err)
} else {
fmt.Printf("[upgrade/versions] Latest %s: %s\n", description, patchVersionStr)

View File

@ -1027,7 +1027,7 @@ func addCommonChecks(execer utilsexec.Interface, k8sVersion string, nodeReg *kub
containerRuntime, err := utilruntime.NewContainerRuntime(execer, nodeReg.CRISocket)
isDocker := false
if err != nil {
fmt.Printf("[preflight] WARNING: Couldn't create the interface used for talking to the container runtime: %v\n", err)
klog.Warningf("[preflight] WARNING: Couldn't create the interface used for talking to the container runtime: %v\n", err)
} else {
checks = append(checks, ContainerRuntimeCheck{runtime: containerRuntime})
if containerRuntime.IsDocker() {

View File

@ -22,6 +22,8 @@ import (
"strings"
"github.com/pkg/errors"
"k8s.io/klog/v2"
)
// BuildArgumentListFromMap takes two string-string maps, one with the base arguments and one
@ -63,7 +65,7 @@ func ParseArgumentListToMap(arguments []string) map[string]string {
// Warn in all other cases, but don't error out. This can happen only if the user has edited the argument list by hand, so they might know what they are doing
if err != nil {
if i != 0 {
fmt.Printf("[kubeadm] WARNING: The component argument %q could not be parsed correctly. The argument must be of the form %q. Skipping...\n", arg, "--")
klog.Warningf("[kubeadm] WARNING: The component argument %q could not be parsed correctly. The argument must be of the form %q. Skipping...\n", arg, "--")
}
continue
}

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"fmt"
"io/ioutil"
"net"
"strconv"
@ -328,7 +327,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
// If the group is neither a kubeadm core type or of a supported component config group, we dump a warning about it being ignored
if !componentconfigs.Scheme.IsGroupRegistered(gvk.Group) {
fmt.Printf("[config] WARNING: Ignored YAML document with GroupVersionKind %v\n", gvk)
klog.Warningf("[config] WARNING: Ignored YAML document with GroupVersionKind %v\n", gvk)
}
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package util
import (
"fmt"
"net"
"net/url"
"strconv"
@ -25,6 +24,7 @@ import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/klog/v2"
netutils "k8s.io/utils/net"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
@ -54,7 +54,7 @@ func GetControlPlaneEndpoint(controlPlaneEndpoint string, localEndpoint *kubeadm
localEndpointPort := strconv.Itoa(int(localEndpoint.BindPort))
if port != "" {
if port != localEndpointPort {
fmt.Println("[endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address")
klog.Warning("[endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address")
}
} else {
port = localEndpointPort

View File

@ -41,6 +41,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
certutil "k8s.io/client-go/util/cert"
"k8s.io/client-go/util/keyutil"
"k8s.io/klog/v2"
netutils "k8s.io/utils/net"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
@ -515,7 +516,7 @@ func appendSANsToAltNames(altNames *certutil.AltNames, SANs []string, certName s
} else if len(validation.IsWildcardDNS1123Subdomain(altname)) == 0 {
altNames.DNSNames = append(altNames.DNSNames, altname)
} else {
fmt.Printf(
klog.Warningf(
"[certificates] WARNING: '%s' was not added to the '%s' SAN, because it is not a valid IP or RFC-1123 compliant DNS entry\n",
altname,
certName,