Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
Signed-off-by: Valeriy Khorunzhin <[email protected]>
  • Loading branch information
Valeriy Khorunzhin committed Dec 27, 2024
1 parent 42945d6 commit 10041dd
Showing 1 changed file with 87 additions and 35 deletions.
122 changes: 87 additions & 35 deletions images/cdi-artifact/patches/022-kek.patch
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,42 @@ index acd09cb94..c9674a305 100644

func (r *ReconcilerBase) emitConditionEvent(dataVolume *cdiv1.DataVolume, originalCond []cdiv1.DataVolumeCondition) {
diff --git a/pkg/controller/import-controller.go b/pkg/controller/import-controller.go
index 49f1ff898..c656ffee1 100644
index 49f1ff898..f2871a130 100644
--- a/pkg/controller/import-controller.go
+++ b/pkg/controller/import-controller.go
@@ -736,6 +736,8 @@ func (r *ImportReconciler) requiresScratchSpace(pvc *corev1.PersistentVolumeClai
}

func (r *ImportReconciler) createScratchPvcForPod(pvc *corev1.PersistentVolumeClaim, pod *corev1.Pod) error {
+ fmt.Println("Import create")
+ fmt.Println(pvc.Name)
scratchPvc := &corev1.PersistentVolumeClaim{}
scratchPVCName, exists := getScratchNameFromPod(pod)
if !exists {
@@ -34,6 +34,7 @@ import (
"kubevirt.io/containerized-data-importer/pkg/common"
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
featuregates "kubevirt.io/containerized-data-importer/pkg/feature-gates"
+ datavolume_patched "kubevirt.io/containerized-data-importer/pkg/patchesv"
"kubevirt.io/containerized-data-importer/pkg/util"
"kubevirt.io/containerized-data-importer/pkg/util/naming"
sdkapi "kubevirt.io/controller-lifecycle-operator-sdk/api"
@@ -753,8 +754,22 @@ func (r *ImportReconciler) createScratchPvcForPod(pvc *corev1.PersistentVolumeCl
// Scratch PVC doesn't exist yet, create it. Determine which storage class to use.
_, err = createScratchPersistentVolumeClaim(r.client, pvc, pod, scratchPVCName, storageClassName, r.installerLabels, r.recorder)
if err != nil {
+ fmt.Println("------------------------------------------------------------")
+ fmt.Println("trying to patch")
+ reason := "ErrCreating"
+ if strings.Contains(err.Error(), "exceeded quota") {
+ reason = "ErrExceededQuota"
+ }
+ datavolume_patched.UpdateDVScratchCondition(r.client, pvc, corev1.ConditionFalse, fmt.Sprintf("Err creating scratch pvc: %q", err.Error()), reason)
+ fmt.Println("------------------------------------------------------------")
return err
}
+
+ fmt.Println("------------------------------------------------------------")
+ fmt.Println("trying to patch")
+ datavolume_patched.UpdateDVScratchCondition(r.client, pvc, corev1.ConditionTrue, "", "ScratchConditionCreated")
+ fmt.Println("------------------------------------------------------------")
+
anno[cc.AnnBoundCondition] = "false"
anno[cc.AnnBoundConditionMessage] = "Creating scratch space"
anno[cc.AnnBoundConditionReason] = creatingScratch
diff --git a/pkg/controller/populators/populator-base.go b/pkg/controller/populators/populator-base.go
index 6c6fd8f8a..ded727513 100644
index 6c6fd8f8a..7cf6becf1 100644
--- a/pkg/controller/populators/populator-base.go
+++ b/pkg/controller/populators/populator-base.go
@@ -18,7 +18,9 @@ package populators
Expand All @@ -73,7 +95,19 @@ index 6c6fd8f8a..ded727513 100644
"kubevirt.io/containerized-data-importer/pkg/util"
)

@@ -213,9 +216,23 @@ func (r *ReconcilerBase) createPVCPrime(pvc *corev1.PersistentVolumeClaim, sourc
@@ -182,6 +185,11 @@ func (r *ReconcilerBase) createPVCPrime(pvc *corev1.PersistentVolumeClaim, sourc
annotations[cc.AnnPodRetainAfterCompletion] = pvc.Annotations[cc.AnnPodRetainAfterCompletion]
}

+ dvUid, ok := pvc.Annotations[cc.AnnCreatedForDataVolume]
+ if ok {
+ annotations[datavolume_patched.AnnPrimeForDataVolume] = dvUid
+ }
+
// Assemble PVC' spec
pvcPrime := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
@@ -213,9 +221,23 @@ func (r *ReconcilerBase) createPVCPrime(pvc *corev1.PersistentVolumeClaim, sourc
}

if err := r.client.Create(context.TODO(), pvcPrime); err != nil {
Expand All @@ -98,36 +132,52 @@ index 6c6fd8f8a..ded727513 100644
}

diff --git a/pkg/controller/upload-controller.go b/pkg/controller/upload-controller.go
index 4c153257a..972eef824 100644
index 4c153257a..595d370ba 100644
--- a/pkg/controller/upload-controller.go
+++ b/pkg/controller/upload-controller.go
@@ -458,6 +458,7 @@ func (r *UploadReconciler) createUploadPodForPvc(pvc *corev1.PersistentVolumeCla
@@ -51,6 +51,7 @@ import (
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
featuregates "kubevirt.io/containerized-data-importer/pkg/feature-gates"
"kubevirt.io/containerized-data-importer/pkg/operator"
+ datavolume_patched "kubevirt.io/containerized-data-importer/pkg/patchesv"
"kubevirt.io/containerized-data-importer/pkg/util"
"kubevirt.io/containerized-data-importer/pkg/util/cert/fetcher"
"kubevirt.io/containerized-data-importer/pkg/util/cert/generator"
@@ -458,6 +459,7 @@ func (r *UploadReconciler) createUploadPodForPvc(pvc *corev1.PersistentVolumeCla

func (r *UploadReconciler) getOrCreateScratchPvc(pvc *corev1.PersistentVolumeClaim, pod *corev1.Pod, name string) (*corev1.PersistentVolumeClaim, error) {
// Set condition, then check if need to override with scratch pvc message
+ fmt.Println("Getting or creating scratch")
anno := pvc.Annotations
scratchPvc := &corev1.PersistentVolumeClaim{}
if err := r.client.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: pvc.Namespace}, scratchPvc); err != nil {
diff --git a/pkg/controller/util.go b/pkg/controller/util.go
index 4d25ae36b..2cd5c5d3a 100644
--- a/pkg/controller/util.go
+++ b/pkg/controller/util.go
@@ -171,6 +171,8 @@ func newScratchPersistentVolumeClaimSpec(pvc *corev1.PersistentVolumeClaim, pod

// createScratchPersistentVolumeClaim creates and returns a pointer to a scratch PVC which is created based on the passed-in pvc and storage class name.
func createScratchPersistentVolumeClaim(client client.Client, pvc *corev1.PersistentVolumeClaim, pod *corev1.Pod, name, storageClassName string, installerLabels map[string]string, recorder record.EventRecorder) (*corev1.PersistentVolumeClaim, error) {
+ fmt.Println("Upload create")
+ fmt.Println(pvc.Name)
scratchPvcSpec := newScratchPersistentVolumeClaimSpec(pvc, pod, name, storageClassName)

sizeRequest := pvc.Spec.Resources.Requests[corev1.ResourceStorage]
@@ -473,8 +475,20 @@ func (r *UploadReconciler) getOrCreateScratchPvc(pvc *corev1.PersistentVolumeCla
// Scratch PVC doesn't exist yet, create it.
scratchPvc, err = createScratchPersistentVolumeClaim(r.client, pvc, pod, name, storageClassName, map[string]string{}, r.recorder)
if err != nil {
+ fmt.Println("------------------------------------------------------------")
+ fmt.Println("trying to patch")
+ reason := "ErrCreating"
+ if strings.Contains(err.Error(), "exceeded quota") {
+ reason = "ErrExceededQuota"
+ }
+ datavolume_patched.UpdateDVScratchCondition(r.client, pvc, corev1.ConditionFalse, fmt.Sprintf("Err creating scratch pvc: %q", err.Error()), reason)
+ fmt.Println("------------------------------------------------------------")
return nil, err
}
+ fmt.Println("------------------------------------------------------------")
+ fmt.Println("trying to patch")
+ datavolume_patched.UpdateDVPrimeCondition(r.client, pvc, corev1.ConditionTrue, "", "PrimeConditionCreated")
+ fmt.Println("------------------------------------------------------------")
} else {
if !metav1.IsControlledBy(scratchPvc, pod) {
return nil, errors.Errorf("%s scratch PVC not controlled by pod %s", scratchPvc.Name, pod.Name)
diff --git a/pkg/patchesv/patched_condition_type.go b/pkg/patchesv/patched_condition_type.go
new file mode 100644
index 000000000..7b1f3d96b
index 000000000..ad9c8ca6e
--- /dev/null
+++ b/pkg/patchesv/patched_condition_type.go
@@ -0,0 +1,126 @@
@@ -0,0 +1,128 @@
+package datavolume_patched
+
+import (
Expand All @@ -144,6 +194,8 @@ index 000000000..7b1f3d96b
+const (
+ DataVolumePrimeConditionCreated cdiv1.DataVolumeConditionType = "PrimePVCCreated"
+ DataVolumeScratchConditionCreated cdiv1.DataVolumeConditionType = "ScratchPVCCreated"
+
+ AnnPrimeForDataVolume = common.AnnAPIGroup + "/primeForDataVolume"
+)
+
+func FindConditionByType(conditionType cdiv1.DataVolumeConditionType, conditions []cdiv1.DataVolumeCondition) *cdiv1.DataVolumeCondition {
Expand Down Expand Up @@ -177,8 +229,8 @@ index 000000000..7b1f3d96b
+ return conditions
+}
+
+func getDVByPVC(clientObject client.Client, pvc *corev1.PersistentVolumeClaim) *cdiv1.DataVolume {
+ uid, ok := pvc.Annotations[common.AnnCreatedForDataVolume]
+func getDVByPVC(clientObject client.Client, pvc *corev1.PersistentVolumeClaim, ann string) *cdiv1.DataVolume {
+ uid, ok := pvc.Annotations[ann]
+ if !ok {
+ fmt.Println("Annotation not found")
+ return nil
Expand Down Expand Up @@ -208,7 +260,7 @@ index 000000000..7b1f3d96b
+}
+
+func UpdateDVPrimeCondition(clientObject client.Client, pvc *corev1.PersistentVolumeClaim, status corev1.ConditionStatus, message, reason string) {
+ dv := getDVByPVC(clientObject, pvc)
+ dv := getDVByPVC(clientObject, pvc, common.AnnCreatedForDataVolume)
+ if dv == nil {
+ fmt.Println("dv is nil")
+ return
Expand All @@ -223,7 +275,7 @@ index 000000000..7b1f3d96b
+ fmt.Println(err)
+ }
+ fmt.Println("Need to be updated")
+ dvUpdated := getDVByPVC(clientObject, pvc)
+ dvUpdated := getDVByPVC(clientObject, pvc, common.AnnCreatedForDataVolume)
+ if dvUpdated == nil {
+ fmt.Println("Updated is nil")
+ }
Expand All @@ -232,7 +284,7 @@ index 000000000..7b1f3d96b
+}
+
+func UpdateDVScratchCondition(clientObject client.Client, pvc *corev1.PersistentVolumeClaim, status corev1.ConditionStatus, message, reason string) {
+ dv := getDVByPVC(clientObject, pvc)
+ dv := getDVByPVC(clientObject, pvc, AnnPrimeForDataVolume)
+ if dv == nil {
+ fmt.Println("dv is nil")
+ return
Expand All @@ -247,7 +299,7 @@ index 000000000..7b1f3d96b
+ fmt.Println(err)
+ }
+ fmt.Println("Need to be updated")
+ dvUpdated := getDVByPVC(clientObject, pvc)
+ dvUpdated := getDVByPVC(clientObject, pvc, common.AnnCreatedForDataVolume)
+ if dvUpdated == nil {
+ fmt.Println("Updated is nil")
+ }
Expand Down

0 comments on commit 10041dd

Please sign in to comment.