kubeadm: optimize and make the usage consistent about apierrors.IsNotFound

This commit is contained in:
SataQiu 2022-10-13 23:20:38 +08:00
parent 575031b68f
commit d4cafe4738
3 changed files with 7 additions and 7 deletions

View File

@ -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. // GetCoreDNSInfo gets the current CoreDNS installed and the current Corefile Configuration of CoreDNS.
func GetCoreDNSInfo(client clientset.Interface) (*v1.ConfigMap, string, string, error) { func GetCoreDNSInfo(client clientset.Interface) (*v1.ConfigMap, string, string, error) {
coreDNSConfigMap, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(context.TODO(), kubeadmconstants.CoreDNSConfigMap, metav1.GetOptions{}) 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 return nil, "", "", err
} }
if apierrors.IsNotFound(err) {
return nil, "", "", nil
}
corefile, ok := coreDNSConfigMap.Data["Corefile"] corefile, ok := coreDNSConfigMap.Data["Corefile"]
if !ok { if !ok {
return nil, "", "", errors.New("unable to find the CoreDNS Corefile data") return nil, "", "", errors.New("unable to find the CoreDNS Corefile data")

View File

@ -76,9 +76,9 @@ func NewClientBackedDryRunGetterFromKubeconfig(file string) (*ClientBackedDryRun
// HandleGetAction handles GET actions to the dryrun clientset this interface supports // HandleGetAction handles GET actions to the dryrun clientset this interface supports
func (clg *ClientBackedDryRunGetter) HandleGetAction(action core.GetAction) (bool, runtime.Object, error) { 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{}) 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 { if err != nil {
// Inform the user that the requested object wasn't found.
printIfNotExists(err)
return true, nil, err return true, nil, err
} }
newObj, err := decodeUnstructuredIntoAPIObject(action, unstructuredObj) newObj, err := decodeUnstructuredIntoAPIObject(action, unstructuredObj)

View File

@ -125,7 +125,7 @@ func (w *KubeWaiter) WaitForPodsWithLabel(kvLabel string) error {
func (w *KubeWaiter) WaitForPodToDisappear(podName string) error { func (w *KubeWaiter) WaitForPodToDisappear(podName string) error {
return wait.PollImmediate(kubeadmconstants.APICallRetryInterval, w.timeout, func() (bool, error) { return wait.PollImmediate(kubeadmconstants.APICallRetryInterval, w.timeout, func() (bool, error) {
_, err := w.client.CoreV1().Pods(metav1.NamespaceSystem).Get(context.TODO(), podName, metav1.GetOptions{}) _, 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) fmt.Printf("[apiclient] The old Pod %q is now removed (which is desired)\n", podName)
return true, nil return true, nil
} }