Skip to content

Commit

Permalink
Distinguish between different VDDK validation errors
Browse files Browse the repository at this point in the history
There are multiple cases that can lead to a "VDDK Init image is invalid"
error message for a migration plan. They are currently handled with a
single VDDKInvalid condition.

This patch adds a new error condition VDDKImageNotFound (and a new
advisory condition VDDKImageNotReady) to help diagnose an issue of a
missing image or incorrect image url.

Resolves: https://issues.redhat.com/browse/MTV-1150

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
  • Loading branch information
jonner committed Jul 23, 2024
1 parent 611fee6 commit 21c7f97
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion pkg/controller/plan/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"path"
"strconv"
"strings"

net "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
Expand All @@ -27,6 +28,7 @@ import (
k8serr "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
k8slabels "k8s.io/apimachinery/pkg/labels"
k8svalidation "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -69,6 +71,8 @@ const (
VDDKNotConfigured = "VDDKNotConfigured"
unsupportedVersion = "UnsupportedVersion"
VDDKInvalid = "VDDKInvalid"
VDDKImageNotReady = "VDDKImageNotReady"
VDDKImageNotFound = "VDDKImageNotFound"
ValidatingVDDK = "ValidatingVDDK"
)

Expand Down Expand Up @@ -744,6 +748,24 @@ func (r *Reconciler) validateVddkImage(plan *api.Plan) (err error) {
Category: Critical,
Message: "VDDK image is necessary for this type of migration",
}
vddkImageNotReady := libcnd.Condition{
Type: VDDKImageNotReady,
Status: True,
Reason: NotSet,
Category: Advisory,
Message: "Waiting for VDDK init image to be be pulled",
// make the condition durable because if the image pull times out,
// the pod will no longer exist to check for the 'waiting' status.
// We will remove the condition manually if it succeeds.
Durable: true,
}
vddkImageNotFound := libcnd.Condition{
Type: VDDKImageNotFound,
Status: True,
Reason: NotSet,
Category: Critical,
Message: "Failed to pull VDDK init image",
}
vddkInvalid := libcnd.Condition{
Type: VDDKInvalid,
Status: True,
Expand Down Expand Up @@ -792,14 +814,37 @@ func (r *Reconciler) validateVddkImage(plan *api.Plan) (err error) {
r.Log.Info("validation of VDDK job is in progress", "image", image)
plan.Status.SetCondition(vddkValidationInProgress)
}
pods := &core.PodList{}
listerr := r.List(context.TODO(), pods, &client.ListOptions{
Namespace: plan.Spec.TargetNamespace,
LabelSelector: k8slabels.SelectorFromSet(map[string]string{"job-name": job.Name}),
})
if listerr == nil {
for _, pod := range pods.Items {
if strings.Contains(pod.Name, job.Name) {
// there should only be a single init container
initStatus := pod.Status.InitContainerStatuses[0]
if initStatus.State.Waiting != nil {
plan.Status.SetCondition(vddkImageNotReady)
} else {
plan.Status.DeleteCondition(VDDKImageNotReady)
}
}
}
}
for _, condition := range job.Status.Conditions {
switch condition.Type {
case batchv1.JobComplete:
r.Log.Info("validate VDDK job completed", "image", image)
err = nil
return
case batchv1.JobFailed:
plan.Status.SetCondition(vddkInvalid)
if plan.Status.FindCondition(VDDKImageNotReady) != nil {
plan.Status.DeleteCondition(VDDKImageNotReady)
plan.Status.SetCondition(vddkImageNotFound)
} else {
plan.Status.SetCondition(vddkInvalid)
}
err = nil
return
default:
Expand Down

0 comments on commit 21c7f97

Please sign in to comment.