Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
exec enable cmd ignore ignore some apiservices error
Browse files Browse the repository at this point in the history
  • Loading branch information
huiwq1990 committed Dec 29, 2020
1 parent 7653009 commit 7979903
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/kubefedctl/enable/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package enable
import (
"fmt"
"io"
apierrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/klog"
"os"
"strings"

Expand Down Expand Up @@ -89,9 +91,10 @@ func CrdForAPIResource(apiResource metav1.APIResource, validation *apiextv1.Cust
}

func LookupAPIResource(config *rest.Config, key, targetVersion string) (*metav1.APIResource, error) {
errs := []error{}
resourceLists, err := GetServerPreferredResources(config)
if err != nil {
return nil, err
errs = append(errs, err)
}

var targetResource *metav1.APIResource
Expand Down Expand Up @@ -124,15 +127,19 @@ func LookupAPIResource(config *rest.Config, key, targetVersion string) (*metav1.
}
}
}

if len(matchedResources) > 1 {
return nil, errors.Errorf("Multiple resources are matched by %q: %s. A group-qualified plural name must be provided.", key, strings.Join(matchedResources, ", "))
errs = append(errs, errors.Errorf("Multiple resources are matched by %q: %s. A group-qualified plural name must be provided.", key, strings.Join(matchedResources, ", ")))
return nil, apierrors.NewAggregate(errs)
}

if targetResource != nil {
klog.Warningf("Api resource found with err %v, error ignored.", apierrors.NewAggregate(errs))
return targetResource, nil
}

return nil, errors.Errorf("Unable to find api resource named %q.", key)
errs = append(errs, errors.Errorf("Unable to find api resource named %q.", key))
return nil, apierrors.NewAggregate(errs)
}

func NameMatchesResource(name string, apiResource metav1.APIResource, group string) bool {
Expand Down Expand Up @@ -161,7 +168,7 @@ func GetServerPreferredResources(config *rest.Config) ([]*metav1.APIResourceList

resourceLists, err := client.ServerPreferredResources()
if err != nil {
return nil, errors.Wrap(err, "Error listing api resources")
return resourceLists, errors.Wrap(err, "Error listing api resources")
}
return resourceLists, nil
}
Expand Down

0 comments on commit 7979903

Please sign in to comment.