Skip to content

Commit 303b776

Browse files
committed
debug
Signed-off-by: Dmitry Rakitin <dmitry.rakitin@flant.com>
1 parent 8b4f688 commit 303b776

4 files changed

Lines changed: 64 additions & 3 deletions

File tree

‎images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vi.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"reflect"
2324

25+
"github.com/deckhouse/virtualization-controller/pkg/logger"
2426
corev1 "k8s.io/api/core/v1"
2527
"k8s.io/apimachinery/pkg/types"
2628
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
@@ -71,6 +73,8 @@ func (ds ObjectRefVirtualImage) Sync(ctx context.Context, vd *v1alpha2.VirtualDi
7173
return reconcile.Result{}, fmt.Errorf("fetch dv: %w", err)
7274
}
7375

76+
logger.FromContext(ctx).Info("[GOGOGO] Reconcile virtual disk", "datavolume", safenil(dv), "pvc", safenil(pvc))
77+
7478
return steptaker.NewStepTakers[*v1alpha2.VirtualDisk](
7579
step.NewReadyStep(ds.diskService, pvc, cb),
7680
step.NewTerminatingStep(pvc),
@@ -81,6 +85,14 @@ func (ds ObjectRefVirtualImage) Sync(ctx context.Context, vd *v1alpha2.VirtualDi
8185
).Run(ctx, vd)
8286
}
8387

88+
func safenil(o client.Object) string {
89+
if o == nil || reflect.ValueOf(o).IsNil() {
90+
return "nil"
91+
}
92+
93+
return o.GetName()
94+
}
95+
8496
func (ds ObjectRefVirtualImage) Validate(ctx context.Context, vd *v1alpha2.VirtualDisk) error {
8597
if vd.Spec.DataSource == nil || vd.Spec.DataSource.ObjectRef == nil {
8698
return errors.New("object ref missed for data source")

‎images/virtualization-artifact/pkg/controller/vd/internal/source/step/create_dv_from_vi_step.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323

24+
"github.com/deckhouse/virtualization-controller/pkg/logger"
2425
corev1 "k8s.io/api/core/v1"
2526
"k8s.io/apimachinery/pkg/api/resource"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -69,6 +70,8 @@ func (s CreateDataVolumeFromVirtualImageStep) Take(ctx context.Context, vd *v1al
6970
return nil, nil
7071
}
7172

73+
logger.FromContext(ctx).Info("[GOGOGO] STEP CreateDataVolumeFromVirtualImageStep")
74+
7275
viRefKey := types.NamespacedName{Name: vd.Spec.DataSource.ObjectRef.Name, Namespace: vd.Namespace}
7376
viRef, err := object.FetchObject(ctx, viRefKey, s.client, &v1alpha2.VirtualImage{})
7477
if err != nil {

‎images/virtualization-artifact/pkg/controller/vd/internal/source/step/wait_for_dv_step.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package step
1919
import (
2020
"context"
2121
"fmt"
22+
"reflect"
2223
"strings"
2324

25+
"github.com/deckhouse/virtualization-controller/pkg/logger"
2426
corev1 "k8s.io/api/core/v1"
2527
storagev1 "k8s.io/api/storage/v1"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -66,13 +68,25 @@ func NewWaitForDVStep(
6668
}
6769
}
6870

71+
func safenil(o client.Object) string {
72+
if o == nil || reflect.ValueOf(o).IsNil() {
73+
return "nil"
74+
}
75+
76+
return o.GetName()
77+
}
78+
6979
func (s WaitForDVStep) Take(ctx context.Context, vd *v1alpha2.VirtualDisk) (*reconcile.Result, error) {
80+
logger.FromContext(ctx).Info("[GOGOGO] STEP WaitForDVStep", "datavolume", safenil(s.dv), "sc", vd.Status.StorageClassName)
81+
7082
if s.dv == nil {
7183
vd.Status.Phase = v1alpha2.DiskProvisioning
7284
s.cb.
7385
Status(metav1.ConditionFalse).
7486
Reason(vdcondition.Provisioning).
7587
Message("Waiting for the VirtualDisk importer to be created.")
88+
89+
logger.FromContext(ctx).Info("[GOGOGO] STEP WaitForDVStep [importer to be created]")
7690
return &reconcile.Result{}, nil
7791
}
7892

@@ -88,11 +102,13 @@ func (s WaitForDVStep) Take(ctx context.Context, vd *v1alpha2.VirtualDisk) (*rec
88102
return &reconcile.Result{}, nil
89103
}
90104
if set {
105+
logger.FromContext(ctx).Info("[GOGOGO] STEP WaitForDVStep [consumer awaited]")
91106
return &reconcile.Result{}, nil
92107
}
93108

94109
ok = s.checkRunningCondition(vd)
95110
if !ok {
111+
logger.FromContext(ctx).Info("[GOGOGO] STEP WaitForDVStep [checkRunningCondition]")
96112
return &reconcile.Result{}, nil
97113
}
98114

@@ -106,9 +122,12 @@ func (s WaitForDVStep) Take(ctx context.Context, vd *v1alpha2.VirtualDisk) (*rec
106122

107123
set = s.setForProvisioning(vd)
108124
if set {
125+
logger.FromContext(ctx).Info("[GOGOGO] STEP WaitForDVStep [provisioning to the pvc]")
109126
return &reconcile.Result{}, nil
110127
}
111128

129+
logger.FromContext(ctx).Info("[GOGOGO] STEP WaitForDVStep [ok]")
130+
112131
return nil, nil
113132
}
114133

@@ -126,6 +145,8 @@ func (s WaitForDVStep) setForProvisioning(vd *v1alpha2.VirtualDisk) (set bool) {
126145
}
127146

128147
func (s WaitForDVStep) setForFirstConsumerIsAwaited(ctx context.Context, vd *v1alpha2.VirtualDisk) (set bool, err error) {
148+
logger.FromContext(ctx).Info("[GOGOGO] STEP WaitForDVStep setForFirstConsumerIsAwaited 111")
149+
129150
if vd.Status.StorageClassName == "" {
130151
return false, fmt.Errorf("StorageClassName is empty, please report a bug")
131152
}
@@ -138,6 +159,9 @@ func (s WaitForDVStep) setForFirstConsumerIsAwaited(ctx context.Context, vd *v1a
138159
isWFFC := sc != nil && sc.VolumeBindingMode != nil && *sc.VolumeBindingMode == storagev1.VolumeBindingWaitForFirstConsumer
139160
dvRunningCond, _ := conditions.GetDataVolumeCondition(conditions.DVRunningConditionType, s.dv.Status.Conditions)
140161
dvRunningReasonEmptyOrPending := dvRunningCond.Reason == "" || dvRunningCond.Reason == conditions.DVRunningConditionPendingReason
162+
163+
logger.FromContext(ctx).Info("[GOGOGO] STEP WaitForDVStep setForFirstConsumerIsAwaited 222", "isWFFC", isWFFC, "dvPhase", s.dv.Status.Phase, "dvRunningReasonEmptyOrPending", dvRunningReasonEmptyOrPending)
164+
141165
if isWFFC && (s.dv.Status.Phase == cdiv1.PendingPopulation || s.dv.Status.Phase == cdiv1.WaitForFirstConsumer) && dvRunningReasonEmptyOrPending {
142166
vd.Status.Phase = v1alpha2.DiskWaitForFirstConsumer
143167
s.cb.

‎images/virtualization-artifact/pkg/controller/vd/internal/watcher/datavolume_watcher.go‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package watcher
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

23+
"github.com/deckhouse/deckhouse/pkg/log"
2224
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
2325
"sigs.k8s.io/controller-runtime/pkg/controller"
2426
"sigs.k8s.io/controller-runtime/pkg/event"
@@ -31,10 +33,14 @@ import (
3133
"github.com/deckhouse/virtualization/api/core/v1alpha2"
3234
)
3335

34-
type DataVolumeWatcher struct{}
36+
type DataVolumeWatcher struct {
37+
logger *log.Logger
38+
}
3539

3640
func NewDataVolumeWatcher() *DataVolumeWatcher {
37-
return &DataVolumeWatcher{}
41+
return &DataVolumeWatcher{
42+
logger: log.Default().With("watcher", strings.ToLower("DataVolume")),
43+
}
3844
}
3945

4046
func (w *DataVolumeWatcher) Watch(mgr manager.Manager, ctr controller.Controller) error {
@@ -49,37 +55,53 @@ func (w *DataVolumeWatcher) Watch(mgr manager.Manager, ctr controller.Controller
4955
predicate.TypedFuncs[*cdiv1.DataVolume]{
5056
CreateFunc: func(e event.TypedCreateEvent[*cdiv1.DataVolume]) bool { return false },
5157
UpdateFunc: func(e event.TypedUpdateEvent[*cdiv1.DataVolume]) bool {
58+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed")
59+
5260
if e.ObjectOld.Status.Progress != e.ObjectNew.Status.Progress {
61+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed [e.ObjectOld.Status.Progress != e.ObjectNew.Status.Progress]")
5362
return true
5463
}
5564

5665
if e.ObjectOld.Status.Phase != e.ObjectNew.Status.Phase && e.ObjectNew.Status.Phase == cdiv1.Succeeded {
66+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed [e.ObjectNew.Status.Phase == cdiv1.Succeeded]")
5767
return true
5868
}
5969

6070
if e.ObjectOld.Status.ClaimName != e.ObjectNew.Status.ClaimName {
71+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed [e.ObjectOld.Status.ClaimName != e.ObjectNew.Status.ClaimName]")
6172
return true
6273
}
6374

6475
oldDVQuotaNotExceeded, oldOk := conditions.GetDataVolumeCondition(conditions.DVQoutaNotExceededConditionType, e.ObjectOld.Status.Conditions)
6576
newDVQuotaNotExceeded, newOk := conditions.GetDataVolumeCondition(conditions.DVQoutaNotExceededConditionType, e.ObjectNew.Status.Conditions)
6677

6778
if !oldOk && newOk {
79+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed [quota]")
6880
return true
6981
}
7082

7183
if oldOk && newOk && oldDVQuotaNotExceeded != newDVQuotaNotExceeded {
84+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed [quota 2]")
7285
return true
7386
}
7487

7588
oldDVRunning, _ := conditions.GetDataVolumeCondition(conditions.DVRunningConditionType, e.ObjectOld.Status.Conditions)
7689
newDVRunning, _ := conditions.GetDataVolumeCondition(conditions.DVRunningConditionType, e.ObjectNew.Status.Conditions)
7790

7891
if oldDVRunning.Reason != newDVRunning.Reason {
92+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed [oldDVRunning.Reason != newDVRunning.Reason]")
7993
return true
8094
}
8195

82-
return newDVRunning.Reason == "Error" || newDVRunning.Reason == "ImagePullFailed"
96+
f := newDVRunning.Reason == "Error" || newDVRunning.Reason == "ImagePullFailed"
97+
if f {
98+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed [oldDVRunning.Reason != newDVRunning.Reason]")
99+
return true
100+
}
101+
102+
w.logger.Info("[GOGOGO] [DataVolumeWatcher] Event observed [FALSE]")
103+
104+
return false
83105
},
84106
},
85107
),

0 commit comments

Comments
 (0)