Skip to content

Commit dbdb022

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

14 files changed

Lines changed: 204 additions & 45 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/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(pod *corev1.Pod, 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: 3 additions & 3 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVirtua
9292
return reconcile.Result{}, err
9393
}
9494

95+
isUploaderReady, err := ds.statService.IsUploaderReady(pod, svc, ing)
96+
if err != nil {
97+
return reconcile.Result{}, err
98+
}
99+
95100
switch {
96101
case isDiskProvisioningFinished(condition):
97102
log.Info("Cluster virtual image provisioning finished: clean up")
@@ -221,7 +226,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVirtua
221226
}
222227

223228
log.Info("Provisioning...", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase)
224-
case ds.statService.IsUploaderReady(pod, svc, ing):
229+
case isUploaderReady:
225230
cb.
226231
Status(metav1.ConditionFalse).
227232
Reason(cvicondition.WaitForUserUpload).

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/deckhouse/virtualization-controller/pkg/common/humanize_bytes"
3838
"github.com/deckhouse/virtualization-controller/pkg/common/imageformat"
3939
"github.com/deckhouse/virtualization-controller/pkg/common/percent"
40-
podutil "github.com/deckhouse/virtualization-controller/pkg/common/pod"
4140
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
4241
"github.com/deckhouse/virtualization-controller/pkg/controller/monitoring"
4342
"github.com/deckhouse/virtualization/api/core/v1alpha2"
@@ -272,14 +271,25 @@ func (s StatService) IsImportStarted(ownerUID types.UID, pod *corev1.Pod) bool {
272271
return progress.ProgressRaw() > 0
273272
}
274273

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

280-
ingressIsOK := 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 server status: %w", err)
284+
}
285+
defer response.Body.Close()
286+
287+
if response.StatusCode == http.StatusOK {
288+
return true, nil
289+
}
290+
}
281291

282-
return podutil.IsPodRunning(pod) && podutil.IsPodStarted(pod) && ingressIsOK
292+
return false, nil
283293
}
284294

285295
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 {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ func (ds UploadDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk) (
122122
vdsupplements.SetPVCName(vd, dv.Status.ClaimName)
123123
}
124124

125+
isUploaderReady, err := ds.statService.IsUploaderReady(pod, svc, ing)
126+
if err != nil {
127+
return reconcile.Result{}, err
128+
}
129+
125130
switch {
126131
case IsDiskProvisioningFinished(condition):
127132
log.Debug("Disk provisioning finished: clean up")
@@ -190,7 +195,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk) (
190195
}
191196

192197
if !ds.statService.IsUploadStarted(vd.GetUID(), pod) {
193-
if ds.statService.IsUploaderReady(pod, svc, ing) {
198+
if isUploaderReady {
194199
log.Info("Waiting for the user upload", "pod.phase", pod.Status.Phase)
195200

196201
vd.Status.Phase = v1alpha2.DiskWaitForUserUpload

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(pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) (bool, error)
6868
GetDownloadSpeed(ownerUID types.UID, pod *corev1.Pod) *v1alpha2.StatusSpeed
6969
}
7070

0 commit comments

Comments
 (0)