mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-03 11:45:20 +00:00
Wait for CRDs to be ready before restoring CRs (#1937)
* Wait for CRDs to be available and ready When restoring CRDs, we should wait for the definition to be ready and available before moving on to restoring specific CRs. While the CRDs are often ready by the time we get to restoring a CR, there is a race condition where the CRD isn't ready. This change waits on each CRD at restore time. Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
This commit is contained in:
@@ -34,6 +34,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
"github.com/vmware-tanzu/velero/pkg/client"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/kube"
|
||||
)
|
||||
|
||||
// kindToResource translates a Kind (mixed case, singular) to a Resource (lowercase, plural) string.
|
||||
@@ -56,21 +57,6 @@ type ResourceGroup struct {
|
||||
OtherResources []*unstructured.Unstructured
|
||||
}
|
||||
|
||||
// crdIsReady checks a CRD to see if it's ready, so that objects may be created from it.
|
||||
func crdIsReady(crd *apiextv1beta1.CustomResourceDefinition) bool {
|
||||
var isEstablished, namesAccepted bool
|
||||
for _, cond := range crd.Status.Conditions {
|
||||
if cond.Type == apiextv1beta1.Established {
|
||||
isEstablished = true
|
||||
}
|
||||
if cond.Type == apiextv1beta1.NamesAccepted {
|
||||
namesAccepted = true
|
||||
}
|
||||
}
|
||||
|
||||
return (isEstablished && namesAccepted)
|
||||
}
|
||||
|
||||
// crdsAreReady polls the API server to see if the BackupStorageLocation and VolumeSnapshotLocation CRDs are ready to create objects.
|
||||
func crdsAreReady(factory client.DynamicFactory, crdKinds []string) (bool, error) {
|
||||
gvk := schema.FromAPIVersionAndKind(apiextv1beta1.SchemeGroupVersion.String(), "CustomResourceDefinition")
|
||||
@@ -108,7 +94,7 @@ func crdsAreReady(factory client.DynamicFactory, crdKinds []string) (bool, error
|
||||
}
|
||||
|
||||
for _, crd := range foundCRDs {
|
||||
if !crdIsReady(crd) {
|
||||
if !kube.IsCRDReady(crd) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user