Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-v1.23] Add library function to determine if a PVC has been p…
…opulated fully. (#1401) * Add library function to determine if a PVC has been populated fully. The logic is as following: If PVC has no ownerRef, then we assume something else fully populated it and will return true If PVC has an ownerRef and its a DataVolume, then look up the DataVolume If DV.status.Phase == succeeded, return true, return false otherwise. Signed-off-by: Alexander Wels <awels@redhat.com> * Renamed functions to better indicate its purpose. Signed-off-by: Alexander Wels <awels@redhat.com> Co-authored-by: Alexander Wels <awels@redhat.com>
- Loading branch information
Showing
11 changed files
with
190 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2020 The CDI Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// IsPopulated indicates if the persistent volume passed in has been fully populated. It follow the following logic | ||
// 1. If the PVC is not owned by a DataVolume, return true, we assume someone else has properly populated the image | ||
// 2. If the PVC is owned by a DataVolume, look up the DV and check the phase, if phase succeeded return true | ||
// 3. If the PVC is owned by a DataVolume, look up the DV and check the phase, if phase !succeeded return false | ||
func IsPopulated(pvc *corev1.PersistentVolumeClaim, getDvFunc func(name, namespace string) (*DataVolume, error)) (bool, error) { | ||
pvcOwner := metav1.GetControllerOf(pvc) | ||
if pvcOwner != nil && pvcOwner.Kind == "DataVolume" { | ||
// Find the data volume: | ||
dv, err := getDvFunc(pvcOwner.Name, pvc.Namespace) | ||
if err != nil { | ||
return false, err | ||
} | ||
if dv.Status.Phase != Succeeded { | ||
return false, nil | ||
} | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2020 The CDI Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// IsPopulated indicates if the persistent volume passed in has been fully populated. It follow the following logic | ||
// 1. If the PVC is not owned by a DataVolume, return true, we assume someone else has properly populated the image | ||
// 2. If the PVC is owned by a DataVolume, look up the DV and check the phase, if phase succeeded return true | ||
// 3. If the PVC is owned by a DataVolume, look up the DV and check the phase, if phase !succeeded return false | ||
func IsPopulated(pvc *corev1.PersistentVolumeClaim, getDvFunc func(name, namespace string) (*DataVolume, error)) (bool, error) { | ||
pvcOwner := metav1.GetControllerOf(pvc) | ||
if pvcOwner != nil && pvcOwner.Kind == "DataVolume" { | ||
// Find the data volume: | ||
dv, err := getDvFunc(pvcOwner.Name, pvc.Namespace) | ||
if err != nil { | ||
return false, err | ||
} | ||
if dv.Status.Phase != Succeeded { | ||
return false, nil | ||
} | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters