From d4cafe4738195dea7bc893202d3194e0091aed3e Mon Sep 17 00:00:00 2001 From: SataQiu Date: Thu, 13 Oct 2022 23:20:38 +0800 Subject: [PATCH] kubeadm: optimize and make the usage consistent about apierrors.IsNotFound --- cmd/kubeadm/app/phases/addons/dns/dns.go | 8 ++++---- cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go | 4 ++-- cmd/kubeadm/app/util/apiclient/wait.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/kubeadm/app/phases/addons/dns/dns.go b/cmd/kubeadm/app/phases/addons/dns/dns.go index cff0c6e9702..3677dbb5b76 100644 --- a/cmd/kubeadm/app/phases/addons/dns/dns.go +++ b/cmd/kubeadm/app/phases/addons/dns/dns.go @@ -344,12 +344,12 @@ func migrateCoreDNSCorefile(client clientset.Interface, cm *v1.ConfigMap, corefi // GetCoreDNSInfo gets the current CoreDNS installed and the current Corefile Configuration of CoreDNS. func GetCoreDNSInfo(client clientset.Interface) (*v1.ConfigMap, string, string, error) { coreDNSConfigMap, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(context.TODO(), kubeadmconstants.CoreDNSConfigMap, metav1.GetOptions{}) - if err != nil && !apierrors.IsNotFound(err) { + if err != nil { + if apierrors.IsNotFound(err) { + return nil, "", "", nil + } return nil, "", "", err } - if apierrors.IsNotFound(err) { - return nil, "", "", nil - } corefile, ok := coreDNSConfigMap.Data["Corefile"] if !ok { return nil, "", "", errors.New("unable to find the CoreDNS Corefile data") diff --git a/cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go b/cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go index e8a82f16576..c80dd33f669 100644 --- a/cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go +++ b/cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go @@ -76,9 +76,9 @@ func NewClientBackedDryRunGetterFromKubeconfig(file string) (*ClientBackedDryRun // HandleGetAction handles GET actions to the dryrun clientset this interface supports func (clg *ClientBackedDryRunGetter) HandleGetAction(action core.GetAction) (bool, runtime.Object, error) { unstructuredObj, err := clg.dynamicClient.Resource(action.GetResource()).Namespace(action.GetNamespace()).Get(context.TODO(), action.GetName(), metav1.GetOptions{}) - // Inform the user that the requested object wasn't found. - printIfNotExists(err) if err != nil { + // Inform the user that the requested object wasn't found. + printIfNotExists(err) return true, nil, err } newObj, err := decodeUnstructuredIntoAPIObject(action, unstructuredObj) diff --git a/cmd/kubeadm/app/util/apiclient/wait.go b/cmd/kubeadm/app/util/apiclient/wait.go index b319d511051..cd417980ff0 100644 --- a/cmd/kubeadm/app/util/apiclient/wait.go +++ b/cmd/kubeadm/app/util/apiclient/wait.go @@ -125,7 +125,7 @@ func (w *KubeWaiter) WaitForPodsWithLabel(kvLabel string) error { func (w *KubeWaiter) WaitForPodToDisappear(podName string) error { return wait.PollImmediate(kubeadmconstants.APICallRetryInterval, w.timeout, func() (bool, error) { _, err := w.client.CoreV1().Pods(metav1.NamespaceSystem).Get(context.TODO(), podName, metav1.GetOptions{}) - if apierrors.IsNotFound(err) { + if err != nil && apierrors.IsNotFound(err) { fmt.Printf("[apiclient] The old Pod %q is now removed (which is desired)\n", podName) return true, nil }