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

Commit c999f0d

Browse files
authored
Merge pull request #1334 from huiwq1990/fix-enableIgnoreErr
exec enable cmd ignore ignore some apiservices error
2 parents ea5b34a + 4cc634d commit c999f0d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/kubefedctl/enable/util.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
"os"
2323
"strings"
2424

25+
apierrors "k8s.io/apimachinery/pkg/util/errors"
26+
"k8s.io/klog"
27+
2528
"github.com/pkg/errors"
2629

2730
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -89,9 +92,10 @@ func CrdForAPIResource(apiResource metav1.APIResource, validation *apiextv1.Cust
8992
}
9093

9194
func LookupAPIResource(config *rest.Config, key, targetVersion string) (*metav1.APIResource, error) {
95+
errs := []error{}
9296
resourceLists, err := GetServerPreferredResources(config)
9397
if err != nil {
94-
return nil, err
98+
errs = append(errs, err)
9599
}
96100

97101
var targetResource *metav1.APIResource
@@ -124,15 +128,19 @@ func LookupAPIResource(config *rest.Config, key, targetVersion string) (*metav1.
124128
}
125129
}
126130
}
131+
127132
if len(matchedResources) > 1 {
128-
return nil, errors.Errorf("Multiple resources are matched by %q: %s. A group-qualified plural name must be provided.", key, strings.Join(matchedResources, ", "))
133+
errs = append(errs, errors.Errorf("Multiple resources are matched by %q: %s. A group-qualified plural name must be provided.", key, strings.Join(matchedResources, ", ")))
134+
return nil, apierrors.NewAggregate(errs)
129135
}
130136

131137
if targetResource != nil {
138+
klog.Warningf("Api resource found with err %v, and error could ignore.", apierrors.NewAggregate(errs))
132139
return targetResource, nil
133140
}
134141

135-
return nil, errors.Errorf("Unable to find api resource named %q.", key)
142+
errs = append(errs, errors.Errorf("Unable to find api resource named %q.", key))
143+
return nil, apierrors.NewAggregate(errs)
136144
}
137145

138146
func NameMatchesResource(name string, apiResource metav1.APIResource, group string) bool {
@@ -161,7 +169,7 @@ func GetServerPreferredResources(config *rest.Config) ([]*metav1.APIResourceList
161169

162170
resourceLists, err := client.ServerPreferredResources()
163171
if err != nil {
164-
return nil, errors.Wrap(err, "Error listing api resources")
172+
return resourceLists, errors.Wrap(err, "Error listing api resources")
165173
}
166174
return resourceLists, nil
167175
}

0 commit comments

Comments
 (0)