mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-22 01:56:16 +00:00
retry GetThirdPartyGroupVersions
This commit is contained in:
parent
9e31175795
commit
7cea7ccd8d
@ -38,6 +38,7 @@ import (
|
|||||||
|
|
||||||
"k8s.io/kubernetes/federation/apis/federation"
|
"k8s.io/kubernetes/federation/apis/federation"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
apierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||||
"k8s.io/kubernetes/pkg/api/meta"
|
"k8s.io/kubernetes/pkg/api/meta"
|
||||||
"k8s.io/kubernetes/pkg/api/service"
|
"k8s.io/kubernetes/pkg/api/service"
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
@ -260,7 +261,18 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
|
|||||||
client, err := clients.ClientForVersion(&unversioned.GroupVersion{Version: "v1"})
|
client, err := clients.ClientForVersion(&unversioned.GroupVersion{Version: "v1"})
|
||||||
CheckErr(err)
|
CheckErr(err)
|
||||||
|
|
||||||
versions, gvks, err := GetThirdPartyGroupVersions(client.Discovery())
|
var versions []unversioned.GroupVersion
|
||||||
|
var gvks []unversioned.GroupVersionKind
|
||||||
|
retries := 3
|
||||||
|
for i := 0; i < retries; i++ {
|
||||||
|
versions, gvks, err = GetThirdPartyGroupVersions(client.Discovery())
|
||||||
|
// Retry if we got a NotFound error, because user may delete
|
||||||
|
// a thirdparty group when the GetThirdPartyGroupVersions is
|
||||||
|
// running.
|
||||||
|
if err == nil || !apierrors.IsNotFound(err) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
CheckErr(err)
|
CheckErr(err)
|
||||||
if len(versions) > 0 {
|
if len(versions) > 0 {
|
||||||
priorityMapper, ok := mapper.RESTMapper.(meta.PriorityRESTMapper)
|
priorityMapper, ok := mapper.RESTMapper.(meta.PriorityRESTMapper)
|
||||||
|
@ -488,6 +488,10 @@ func ShouldRecord(cmd *cobra.Command, info *resource.Info) bool {
|
|||||||
return GetRecordFlag(cmd) || ContainsChangeCause(info)
|
return GetRecordFlag(cmd) || ContainsChangeCause(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetThirdPartyGroupVersions returns the thirdparty "group/versions"s and
|
||||||
|
// resources supported by the server. A user may delete a thirdparty resource
|
||||||
|
// when this function is running, so this function may return a "NotFound" error
|
||||||
|
// due to the race.
|
||||||
func GetThirdPartyGroupVersions(discovery discovery.DiscoveryInterface) ([]unversioned.GroupVersion, []unversioned.GroupVersionKind, error) {
|
func GetThirdPartyGroupVersions(discovery discovery.DiscoveryInterface) ([]unversioned.GroupVersion, []unversioned.GroupVersionKind, error) {
|
||||||
result := []unversioned.GroupVersion{}
|
result := []unversioned.GroupVersion{}
|
||||||
gvks := []unversioned.GroupVersionKind{}
|
gvks := []unversioned.GroupVersionKind{}
|
||||||
|
Loading…
Reference in New Issue
Block a user