Skip to content

Commit 562771f

Browse files
author
Roman Sysoev
committed
fix(vd): uploader
Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
1 parent ab6c6c2 commit 562771f

6 files changed

Lines changed: 125 additions & 24 deletions

File tree

images/dvcr-artifact/pkg/uploader/uploader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ func (app *uploadServerApp) healthzHandler(w http.ResponseWriter, _ *http.Reques
280280
}
281281

282282
func (app *uploadServerApp) validateShouldHandleRequest(w http.ResponseWriter, r *http.Request) bool {
283+
if r.Method == http.MethodGet {
284+
w.WriteHeader(http.StatusOK)
285+
return false
286+
}
287+
283288
if r.Method != http.MethodPost && r.Method != http.MethodPut {
284289
w.WriteHeader(http.StatusNotFound)
285290
return false

images/virtualization-artifact/pkg/common/ingress/ingress.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ func MakeOwnerReference(ing *netv1.Ingress) metav1.OwnerReference {
3434
Controller: &isController,
3535
}
3636
}
37+
38+
// IsIngressReady returns true if the load-balancer has at least one ingress point in the status; otherwise, it returns false.
39+
func IsIngressReady(ing *netv1.Ingress) bool {
40+
return len(ing.Status.LoadBalancer.Ingress) != 0
41+
}

images/virtualization-artifact/pkg/common/pod/pod.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ func IsPodStarted(pod *corev1.Pod) bool {
103103
return true
104104
}
105105

106+
// IsPodReady returns true if the pod's `Ready` condition status is true; otherwise, it returns false.
107+
func IsPodReady(pod *corev1.Pod) bool {
108+
for _, c := range pod.Status.Conditions {
109+
if c.Type == corev1.PodReady && c.Status == corev1.ConditionTrue {
110+
return true
111+
}
112+
}
113+
114+
return false
115+
}
116+
106117
// IsPodComplete returns true if a Pod is in 'Succeeded' phase, false if not.
107118
func IsPodComplete(pod *corev1.Pod) bool {
108119
return pod != nil && pod.Status.Phase == corev1.PodSucceeded

images/virtualization-artifact/pkg/controller/service/stat_service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/deckhouse/virtualization-controller/pkg/common/annotations"
3737
"github.com/deckhouse/virtualization-controller/pkg/common/humanize_bytes"
3838
"github.com/deckhouse/virtualization-controller/pkg/common/imageformat"
39+
ingutil "github.com/deckhouse/virtualization-controller/pkg/common/ingress"
3940
"github.com/deckhouse/virtualization-controller/pkg/common/percent"
4041
podutil "github.com/deckhouse/virtualization-controller/pkg/common/pod"
4142
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
@@ -277,9 +278,9 @@ func (s StatService) IsUploaderReady(pod *corev1.Pod, svc *corev1.Service, ing *
277278
return false
278279
}
279280

280-
ingressIsOK := ing.Annotations[annotations.AnnUploadPath] != "" || ing.Annotations[annotations.AnnUploadURLDeprecated] != ""
281+
ingressHasUploadPath := ing.Annotations[annotations.AnnUploadPath] != "" || ing.Annotations[annotations.AnnUploadURLDeprecated] != ""
281282

282-
return podutil.IsPodRunning(pod) && podutil.IsPodStarted(pod) && ingressIsOK
283+
return podutil.IsPodReady(pod) && ingutil.IsIngressReady(ing) && ingressHasUploadPath
283284
}
284285

285286
func (s StatService) IsUploadStarted(ownerUID types.UID, pod *corev1.Pod) bool {

images/virtualization-artifact/pkg/controller/uploader/uploader_pod.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/apimachinery/pkg/util/intstr"
2526
"k8s.io/utils/ptr"
2627
"sigs.k8s.io/controller-runtime/pkg/client"
2728

@@ -36,6 +37,12 @@ const (
3637
destinationAuthVol = "dvcr-secret-vol"
3738
)
3839

40+
// These constants can't be imported from "images/dvcr-artifact/pkg/uploader/uploader.go" due to conflicts with the CDI version.
41+
const (
42+
healthzPort = 8080
43+
healthzPath = "/healthz"
44+
)
45+
3946
type Pod struct {
4047
PodSettings *PodSettings
4148
Settings *Settings
@@ -151,6 +158,15 @@ func (p *Pod) makeUploaderContainerSpec() *corev1.Container {
151158
SecurityContext: &corev1.SecurityContext{
152159
ReadOnlyRootFilesystem: ptr.To(true),
153160
},
161+
ReadinessProbe: &corev1.Probe{
162+
ProbeHandler: corev1.ProbeHandler{
163+
HTTPGet: &corev1.HTTPGetAction{
164+
Path: healthzPath,
165+
Port: intstr.FromInt(healthzPort),
166+
},
167+
},
168+
InitialDelaySeconds: 5,
169+
},
154170
}
155171

156172
if p.PodSettings.ResourceRequirements != nil {

test/e2e/blockdevice/data_exports.go

Lines changed: 85 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,6 @@ func createUploadDisk(f *framework.Framework, name string) *v1alpha2.VirtualDisk
285285
return vd
286286
}
287287

288-
func retry(maxRetries int, fn func() error) error {
289-
var lastErr error
290-
for attempt := 1; attempt <= maxRetries; attempt++ {
291-
if err := fn(); err != nil {
292-
lastErr = err
293-
GinkgoWriter.Printf("Attempt %d/%d failed: %v\n", attempt, maxRetries, err)
294-
time.Sleep(time.Duration(attempt) * time.Second)
295-
continue
296-
}
297-
return nil
298-
}
299-
return fmt.Errorf("failed after %d attempts: %w", maxRetries, lastErr)
300-
}
301-
302288
func uploadFile(f *framework.Framework, vd *v1alpha2.VirtualDisk, filePath string) {
303289
err := f.Clients.GenericClient().Get(context.Background(), crclient.ObjectKeyFromObject(vd), vd)
304290
Expect(err).NotTo(HaveOccurred())
@@ -314,14 +300,17 @@ func uploadFile(f *framework.Framework, vd *v1alpha2.VirtualDisk, filePath strin
314300
}
315301
uploadURL := vd.Status.ImageUploadURLs.External
316302

317-
// During the upload of a VirtualDisk of type 'Upload', there is a bug:
318-
// when the VirtualDisk is in the 'DiskWaitForUserUpload' phase,
319-
// nginx may not be ready yet and can return 413 or 503 errors.
320-
// Once this bug is fixed, the retry mechanism must be removed.
321-
const maxRetries = 5
322-
err = retry(maxRetries, func() error {
323-
return doUploadAttempt(httpClient, uploadURL, filePath)
324-
})
303+
// uploaderPod, err := getUploaderPod(vd.Name, vd.Namespace, f)
304+
// Expect(err).NotTo(HaveOccurred())
305+
// untilUploaderPodReady(uploaderPod.Name, uploaderPod.Namespace, f)
306+
307+
// uploaderIngress, err := getUploaderIngress(vd.Name, vd.Namespace, f)
308+
// Expect(err).NotTo(HaveOccurred())
309+
// untilUploaderIngressReady(uploaderIngress.Name, uploaderIngress.Namespace, f)
310+
311+
// time.Sleep(1 * time.Second)
312+
313+
err = doUploadAttempt(httpClient, uploadURL, filePath)
325314
Expect(err).NotTo(HaveOccurred(), "Upload failed")
326315
}
327316

@@ -385,3 +374,77 @@ func checkStorageVolumeDataManagerEnabled() (bool, error) {
385374

386375
return enabled != nil && *enabled, nil
387376
}
377+
378+
// func getUploaderPod(vd *v1alpha2.VirtualDisk, f *framework.Framework) (*corev1.Pod, error) {
379+
// pods, err := f.Clients.KubeClient().CoreV1().Pods(vd.Namespace).List(context.Background(), metav1.ListOptions{})
380+
// if err != nil {
381+
// return nil, err
382+
// }
383+
384+
// for _, pod := range pods.Items {
385+
// for _, ref := range pod.OwnerReferences {
386+
// if ref.Kind == v1alpha2.VirtualDiskKind && ref.Name == vd.Name && strings.HasSuffix(pod.Name, string(vd.UID)) {
387+
// for _, c := range pod.Spec.Containers {
388+
// if c.Name == common.UploaderContainerName {
389+
// return &pod, nil
390+
// }
391+
// }
392+
// }
393+
// }
394+
// }
395+
396+
// return nil, fmt.Errorf("could not find uploader pod for virtual disk %s", vd.Name)
397+
// }
398+
399+
// func untilUploaderPodReady(podName, podNamespace string, f *framework.Framework) {
400+
// GinkgoHelper()
401+
402+
// Eventually(func() error {
403+
// pod, err := f.Clients.KubeClient().CoreV1().Pods(podNamespace).Get(context.Background(), podName, metav1.GetOptions{})
404+
// if err != nil {
405+
// return err
406+
// }
407+
408+
// for _, c := range pod.Status.Conditions {
409+
// if c.Type == corev1.PodReady && c.Status == corev1.ConditionTrue {
410+
// return nil
411+
// }
412+
// }
413+
414+
// return fmt.Errorf("pod %s is not ready", podName)
415+
// }).WithTimeout(framework.ShortTimeout).WithPolling(framework.PollingInterval).Should(Succeed())
416+
// }
417+
418+
// func getUploaderIngress(vd *v1alpha2.VirtualDisk, f *framework.Framework) (*netv1.Ingress, error) {
419+
// ings, err := f.Clients.KubeClient().NetworkingV1().Ingresses(vd.Namespace).List(context.Background(), metav1.ListOptions{})
420+
// if err != nil {
421+
// return nil, err
422+
// }
423+
424+
// for _, ing := range ings.Items {
425+
// for _, ref := range ing.OwnerReferences {
426+
// if ref.Kind == v1alpha2.VirtualDiskKind && ref.Name == vd.Name && strings.HasSuffix(ing.Name, string(vd.UID)) {
427+
// return &ing, nil
428+
// }
429+
// }
430+
// }
431+
432+
// return nil, fmt.Errorf("could not find uploader ingress for virtual disk %s", vd.Name)
433+
// }
434+
435+
// func untilUploaderIngressReady(ingName, ingNamespace string, f *framework.Framework) {
436+
// GinkgoHelper()
437+
438+
// Eventually(func() error {
439+
// ing, err := f.Clients.KubeClient().NetworkingV1().Ingresses(ingNamespace).Get(context.Background(), ingName, metav1.GetOptions{})
440+
// if err != nil {
441+
// return err
442+
// }
443+
444+
// if len(ing.Status.LoadBalancer.Ingress) != 0 {
445+
// return nil
446+
// }
447+
448+
// return fmt.Errorf("ingress %s is not ready", ingName)
449+
// }).WithTimeout(framework.MiddleTimeout).WithPolling(framework.PollingInterval).Should(Succeed())
450+
// }

0 commit comments

Comments
 (0)