Skip to content

Commit bb9c27a

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

8 files changed

Lines changed: 117 additions & 93 deletions

File tree

images/virtualization-artifact/pkg/controller/cvi/internal/source/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Stat interface {
6666
GetDVCRImageName(pod *corev1.Pod) string
6767
GetDownloadSpeed(ownerUID types.UID, pod *corev1.Pod) *v1alpha2.StatusSpeed
6868
GetProgress(ownerUID types.UID, pod *corev1.Pod, prevProgress string, opts ...service.GetProgressOption) string
69-
IsUploaderReady(pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) bool
69+
IsUploaderReady(svc *corev1.Service, ing *netv1.Ingress) (bool, error)
7070
IsUploadStarted(ownerUID types.UID, pod *corev1.Pod) bool
7171
CheckPod(pod *corev1.Pod) error
7272
}

images/virtualization-artifact/pkg/controller/cvi/internal/source/mock.go

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

images/virtualization-artifact/pkg/controller/cvi/internal/source/upload.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,27 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVirtua
221221
}
222222

223223
log.Info("Provisioning...", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase)
224-
case ds.statService.IsUploaderReady(pod, svc, ing):
225-
cb.
226-
Status(metav1.ConditionFalse).
227-
Reason(cvicondition.WaitForUserUpload).
228-
Message("Waiting for the user upload.")
229-
230-
cvi.Status.Phase = v1alpha2.ImageWaitForUserUpload
231-
cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod)
232-
cvi.Status.ImageUploadURLs = &v1alpha2.ImageUploadURLs{
233-
External: ds.uploaderService.GetExternalURL(ctx, ing),
234-
InCluster: ds.uploaderService.GetInClusterURL(ctx, svc),
224+
case podutil.IsPodReady(pod):
225+
isUploderReady, err := ds.statService.IsUploaderReady(svc, ing)
226+
if err != nil {
227+
return reconcile.Result{}, err
235228
}
236229

237-
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
230+
if isUploderReady {
231+
cb.
232+
Status(metav1.ConditionFalse).
233+
Reason(cvicondition.WaitForUserUpload).
234+
Message("Waiting for the user upload.")
235+
236+
cvi.Status.Phase = v1alpha2.ImageWaitForUserUpload
237+
cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod)
238+
cvi.Status.ImageUploadURLs = &v1alpha2.ImageUploadURLs{
239+
External: ds.uploaderService.GetExternalURL(ctx, ing),
240+
InCluster: ds.uploaderService.GetInClusterURL(ctx, svc),
241+
}
242+
243+
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
244+
}
238245
default:
239246
cb.
240247
Status(metav1.ConditionFalse).

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +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"
4039
"github.com/deckhouse/virtualization-controller/pkg/common/percent"
41-
podutil "github.com/deckhouse/virtualization-controller/pkg/common/pod"
4240
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
4341
"github.com/deckhouse/virtualization-controller/pkg/controller/monitoring"
4442
"github.com/deckhouse/virtualization/api/core/v1alpha2"
@@ -273,14 +271,25 @@ func (s StatService) IsImportStarted(ownerUID types.UID, pod *corev1.Pod) bool {
273271
return progress.ProgressRaw() > 0
274272
}
275273

276-
func (s StatService) IsUploaderReady(pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) bool {
277-
if pod == nil || svc == nil || ing == nil {
278-
return false
274+
func (s StatService) IsUploaderReady(svc *corev1.Service, ing *netv1.Ingress) (bool, error) {
275+
if svc == nil || ing == nil {
276+
return false, nil
279277
}
280278

281-
ingressHasUploadPath := ing.Annotations[annotations.AnnUploadPath] != "" || ing.Annotations[annotations.AnnUploadURLDeprecated] != ""
279+
uploadURL, ok := ing.Annotations[annotations.AnnUploadURL]
280+
if ok {
281+
response, err := http.Get(uploadURL)
282+
if err != nil {
283+
return false, fmt.Errorf("failed to get upload service status: %w", err)
284+
}
285+
defer response.Body.Close()
286+
287+
if response.StatusCode == http.StatusOK {
288+
return true, nil
289+
}
290+
}
282291

283-
return podutil.IsPodReady(pod) && ingutil.IsIngressReady(ing) && ingressHasUploadPath
292+
return false, nil
284293
}
285294

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

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,29 +190,35 @@ func (ds UploadDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk) (
190190
}
191191

192192
if !ds.statService.IsUploadStarted(vd.GetUID(), pod) {
193-
if ds.statService.IsUploaderReady(pod, svc, ing) {
194-
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
195-
196-
vd.Status.Phase = v1alpha2.DiskWaitForUserUpload
197-
cb.
198-
Status(metav1.ConditionFalse).
199-
Reason(vdcondition.WaitForUserUpload).
200-
Message("Waiting for the user upload.")
201-
vd.Status.ImageUploadURLs = &v1alpha2.ImageUploadURLs{
202-
External: ds.uploaderService.GetExternalURL(ctx, ing),
203-
InCluster: ds.uploaderService.GetInClusterURL(ctx, svc),
193+
if podutil.IsPodReady(pod) {
194+
isUploaderReady, err := ds.statService.IsUploaderReady(svc, ing)
195+
if err != nil {
196+
return reconcile.Result{}, err
197+
}
198+
if isUploaderReady {
199+
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
200+
201+
vd.Status.Phase = v1alpha2.DiskWaitForUserUpload
202+
cb.
203+
Status(metav1.ConditionFalse).
204+
Reason(vdcondition.WaitForUserUpload).
205+
Message("Waiting for the user upload.")
206+
vd.Status.ImageUploadURLs = &v1alpha2.ImageUploadURLs{
207+
External: ds.uploaderService.GetExternalURL(ctx, ing),
208+
InCluster: ds.uploaderService.GetInClusterURL(ctx, svc),
209+
}
210+
} else {
211+
log.Info("Waiting for the uploader to be ready to process the user's upload", "pod.phase", pod.Status.Phase)
212+
213+
vd.Status.Phase = v1alpha2.DiskPending
214+
cb.
215+
Status(metav1.ConditionFalse).
216+
Reason(vdcondition.ProvisioningNotStarted).
217+
Message(fmt.Sprintf("Waiting for the uploader %q to be ready to process the user's upload.", pod.Name))
204218
}
205-
} else {
206-
log.Info("Waiting for the uploader to be ready to process the user's upload", "pod.phase", pod.Status.Phase)
207219

208-
vd.Status.Phase = v1alpha2.DiskPending
209-
cb.
210-
Status(metav1.ConditionFalse).
211-
Reason(vdcondition.ProvisioningNotStarted).
212-
Message(fmt.Sprintf("Waiting for the uploader %q to be ready to process the user's upload.", pod.Name))
220+
return reconcile.Result{RequeueAfter: time.Second}, nil
213221
}
214-
215-
return reconcile.Result{RequeueAfter: time.Second}, nil
216222
}
217223

218224
log.Info("Provisioning to DVCR is in progress", "podPhase", pod.Status.Phase)

images/virtualization-artifact/pkg/controller/vi/internal/source/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type Stat interface {
6464
step.WaitForPodStepStat
6565
step.ReadyContainerRegistryStepStat
6666
IsUploadStarted(ownerUID types.UID, pod *corev1.Pod) bool
67-
IsUploaderReady(pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) bool
67+
IsUploaderReady(svc *corev1.Service, ing *netv1.Ingress) (bool, error)
6868
GetDownloadSpeed(ownerUID types.UID, pod *corev1.Pod) *v1alpha2.StatusSpeed
6969
}
7070

images/virtualization-artifact/pkg/controller/vi/internal/source/mock.go

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

images/virtualization-artifact/pkg/controller/vi/internal/source/upload.go

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -172,30 +172,37 @@ func (ds UploadDataSource) StoreToPVC(ctx context.Context, vi *v1alpha2.VirtualI
172172
}
173173

174174
if !ds.statService.IsUploadStarted(vi.GetUID(), pod) {
175-
if ds.statService.IsUploaderReady(pod, svc, ing) {
176-
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
177-
178-
vi.Status.Phase = v1alpha2.ImageWaitForUserUpload
179-
cb.
180-
Status(metav1.ConditionFalse).
181-
Reason(vicondition.WaitForUserUpload).
182-
Message("Waiting for the user upload.")
175+
if podutil.IsPodReady(pod) {
176+
isUploaderReady, err := ds.statService.IsUploaderReady(svc, ing)
177+
if err != nil {
178+
return reconcile.Result{}, err
179+
}
183180

184-
vi.Status.ImageUploadURLs = &v1alpha2.ImageUploadURLs{
185-
External: ds.uploaderService.GetExternalURL(ctx, ing),
186-
InCluster: ds.uploaderService.GetInClusterURL(ctx, svc),
181+
if isUploaderReady {
182+
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
183+
184+
vi.Status.Phase = v1alpha2.ImageWaitForUserUpload
185+
cb.
186+
Status(metav1.ConditionFalse).
187+
Reason(vicondition.WaitForUserUpload).
188+
Message("Waiting for the user upload.")
189+
190+
vi.Status.ImageUploadURLs = &v1alpha2.ImageUploadURLs{
191+
External: ds.uploaderService.GetExternalURL(ctx, ing),
192+
InCluster: ds.uploaderService.GetInClusterURL(ctx, svc),
193+
}
194+
} else {
195+
log.Info("Waiting for the uploader to be ready to process the user's upload", "pod.phase", pod.Status.Phase)
196+
197+
vi.Status.Phase = v1alpha2.ImagePending
198+
cb.
199+
Status(metav1.ConditionFalse).
200+
Reason(vicondition.ProvisioningNotStarted).
201+
Message(fmt.Sprintf("Waiting for the uploader %q to be ready to process the user's upload.", pod.Name))
187202
}
188-
} else {
189-
log.Info("Waiting for the uploader to be ready to process the user's upload", "pod.phase", pod.Status.Phase)
190203

191-
vi.Status.Phase = v1alpha2.ImagePending
192-
cb.
193-
Status(metav1.ConditionFalse).
194-
Reason(vicondition.ProvisioningNotStarted).
195-
Message(fmt.Sprintf("Waiting for the uploader %q to be ready to process the user's upload.", pod.Name))
204+
return reconcile.Result{RequeueAfter: time.Second}, nil
196205
}
197-
198-
return reconcile.Result{RequeueAfter: time.Second}, nil
199206
}
200207

201208
vi.Status.Phase = v1alpha2.ImageProvisioning
@@ -454,20 +461,27 @@ func (ds UploadDataSource) StoreToDVCR(ctx context.Context, vi *v1alpha2.Virtual
454461
}
455462

456463
log.Info("Provisioning...", "pod.phase", pod.Status.Phase)
457-
case ds.statService.IsUploaderReady(pod, svc, ing):
458-
cb.
459-
Status(metav1.ConditionFalse).
460-
Reason(vicondition.WaitForUserUpload).
461-
Message("Waiting for the user upload.")
462-
463-
vi.Status.Phase = v1alpha2.ImageWaitForUserUpload
464-
vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod)
465-
vi.Status.ImageUploadURLs = &v1alpha2.ImageUploadURLs{
466-
External: ds.uploaderService.GetExternalURL(ctx, ing),
467-
InCluster: ds.uploaderService.GetInClusterURL(ctx, svc),
464+
case podutil.IsPodReady(pod):
465+
isUploaderReady, err := ds.statService.IsUploaderReady(svc, ing)
466+
if err != nil {
467+
return reconcile.Result{}, err
468468
}
469469

470-
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
470+
if isUploaderReady {
471+
cb.
472+
Status(metav1.ConditionFalse).
473+
Reason(vicondition.WaitForUserUpload).
474+
Message("Waiting for the user upload.")
475+
476+
vi.Status.Phase = v1alpha2.ImageWaitForUserUpload
477+
vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod)
478+
vi.Status.ImageUploadURLs = &v1alpha2.ImageUploadURLs{
479+
External: ds.uploaderService.GetExternalURL(ctx, ing),
480+
InCluster: ds.uploaderService.GetInClusterURL(ctx, svc),
481+
}
482+
483+
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
484+
}
471485
default:
472486
cb.
473487
Status(metav1.ConditionFalse).

0 commit comments

Comments
 (0)