Skip to content

Commit

Permalink
docs(vd,vi,cvi): add conditions comments
Browse files Browse the repository at this point in the history
Signed-off-by: Isteb4k <dmitry.rakitin@flant.com>
  • Loading branch information
Isteb4k committed Jun 25, 2024
1 parent 078b61d commit a231f7e
Show file tree
Hide file tree
Showing 25 changed files with 223 additions and 174 deletions.
38 changes: 26 additions & 12 deletions api/core/v1alpha2/cvicondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,41 @@ limitations under the License.

package cvicondition

// Type represents the various condition types for the `ClusterVirtualImage`.
type Type = string

const (
// DatasourceReadyType indicates whether the datasource (for example, a `VirtualImage`) is ready, allowing the import process for the `ClusterVirtualImage` to start.
DatasourceReadyType Type = "DatasourceReady"
ReadyType Type = "Ready"
// ReadyType indicates whether the import process succeeded and the `ClusterVirtualImage` is ready for use.
ReadyType Type = "Ready"
)

type (
// DatasourceReadyReason represents the various reasons for the DatasourceReady condition type.
DatasourceReadyReason = string
ReadyReason = string
// ReadyReason represents the various reasons for the Ready condition type.
ReadyReason = string
)

const (
DatasourceReadyReason_DatasourceReady DatasourceReadyReason = "DatasourceReady"
DatasourceReadyReason_ContainerRegistrySecretNotFound DatasourceReadyReason = "ContainerRegistrySecretNotFound"
DatasourceReadyReason_ImageNotReady DatasourceReadyReason = "ImageNotReady"
DatasourceReadyReason_ClusterImageNotReady DatasourceReadyReason = "ClusterImageNotReady"

ReadyReason_WaitForUserUpload ReadyReason = "WaitForUserUpload"
ReadyReason_Provisioning ReadyReason = "Provisioning"
ReadyReason_ProvisioningNotStarted ReadyReason = "ProvisioningNotStarted"
ReadyReason_ProvisioningFailed ReadyReason = "ProvisioningFailed"
ReadyReason_Ready ReadyReason = "Ready"
// DatasourceReady indicates that the datasource is ready for use, allowing the import process to start.
DatasourceReady DatasourceReadyReason = "DatasourceReady"
// ContainerRegistrySecretNotFound indicates that the container registry secret was not found, which prevents the import process from starting.
ContainerRegistrySecretNotFound DatasourceReadyReason = "ContainerRegistrySecretNotFound"
// ImageNotReady indicates that the `VirtualImage` datasource is not ready yet, which prevents the import process from starting.
ImageNotReady DatasourceReadyReason = "ImageNotReady"
// ClusterImageNotReady indicates that the `ClusterVirtualImage` datasource is not ready, which prevents the import process from starting.
ClusterImageNotReady DatasourceReadyReason = "ClusterImageNotReady"

// WaitForUserUpload indicates that the `ClusterVirtualImage` is waiting for the user to upload a datasource for the import process to continue.
WaitForUserUpload ReadyReason = "WaitForUserUpload"
// Provisioning indicates that the provisioning process is currently in progress.
Provisioning ReadyReason = "Provisioning"
// ProvisioningNotStarted indicates that the provisioning process has not started yet.
ProvisioningNotStarted ReadyReason = "ProvisioningNotStarted"
// ProvisioningFailed indicates that the provisioning process has failed.
ProvisioningFailed ReadyReason = "ProvisioningFailed"
// Ready indicates that the import process is complete and the `ClusterVirtualImage` is ready for use.
Ready ReadyReason = "Ready"
)
61 changes: 41 additions & 20 deletions api/core/v1alpha2/vdcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,56 @@ limitations under the License.

package vdcondition

// Type represents the various condition types for the `VirtualDisk`.
type Type = string

const (
// DatasourceReadyType indicates whether the data source (for example, a `VirtualImage`) is ready, allowing the import process for the `VirtualDisk` to start.
DatasourceReadyType Type = "DatasourceReady"
ReadyType Type = "Ready"
ResizedType Type = "Resized"
// ReadyType indicates whether the import process succeeded and the `VirtualDisk` is ready for use.
ReadyType Type = "Ready"
// ResizedType indicates whether the disk resizing operation is completed.
ResizedType Type = "Resized"
)

type (
// DatasourceReadyReason represents the various reasons for the DatasourceReady condition type.
DatasourceReadyReason = string
ReadyReason = string
ResizedReason = string
// ReadyReason represents the various reasons for the Ready condition type.
ReadyReason = string
// ResizedReason represents the various reasons for the Resized condition type.
ResizedReason = string
)

const (
DatasourceReadyReason_DatasourceReady DatasourceReadyReason = "DatasourceReady"
DatasourceReadyReason_ContainerRegistrySecretNotFound DatasourceReadyReason = "ContainerRegistrySecretNotFound"
DatasourceReadyReason_ImageNotReady DatasourceReadyReason = "ImageNotReady"
DatasourceReadyReason_ClusterImageNotReady DatasourceReadyReason = "ClusterImageNotReady"

ReadyReason_WaitForUserUpload ReadyReason = "WaitForUserUpload"
ReadyReason_Provisioning ReadyReason = "Provisioning"
ReadyReason_ProvisioningNotStarted ReadyReason = "ProvisioningNotStarted"
ReadyReason_ProvisioningFailed ReadyReason = "ProvisioningFailed"
ReadyReason_Ready ReadyReason = "Ready"
ReadyReason_Lost ReadyReason = "PVCLost"

ResizedReason_NotRequested ResizedReason = "NotRequested"
ResizedReason_InProgress ResizedReason = "InProgress"
ResizedReason_TooSmallDiskSize ResizedReason = "TooSmallDiskSize"
ResizedReason_Resized ResizedReason = "Resized"
// DatasourceReady indicates that the datasource is ready for use, allowing the import process to start.
DatasourceReady DatasourceReadyReason = "DatasourceReady"
// ContainerRegistrySecretNotFound indicates that the container registry secret was not found, which prevents the import process from starting.
ContainerRegistrySecretNotFound DatasourceReadyReason = "ContainerRegistrySecretNotFound"
// ImageNotReady indicates that the `VirtualImage` datasource is not ready yet, which prevents the import process from starting.
ImageNotReady DatasourceReadyReason = "ImageNotReady"
// ClusterImageNotReady indicates that the `VirtualDisk` datasource is not ready, which prevents the import process from starting.
ClusterImageNotReady DatasourceReadyReason = "ClusterImageNotReady"

// WaitForUserUpload indicates that the `VirtualDisk` is waiting for the user to upload a datasource for the import process to continue.
WaitForUserUpload ReadyReason = "WaitForUserUpload"
// Provisioning indicates that the provisioning process is currently in progress.
Provisioning ReadyReason = "Provisioning"
// ProvisioningNotStarted indicates that the provisioning process has not started yet.
ProvisioningNotStarted ReadyReason = "ProvisioningNotStarted"
// ProvisioningFailed indicates that the provisioning process has failed.
ProvisioningFailed ReadyReason = "ProvisioningFailed"
// Ready indicates that the import process is complete and the `VirtualDisk` is ready for use.
Ready ReadyReason = "Ready"
// Lost indicates that the underlying PersistentVolumeClaim has been lost and the `VirtualDisk` can no longer be used.
Lost ReadyReason = "PVCLost"

// NotRequested indicates that the resize operation has not been requested yet.
NotRequested ResizedReason = "NotRequested"
// InProgress indicates that the resize request has been detected and the operation is currently in progress.
InProgress ResizedReason = "InProgress"
// TooSmallDiskSize indicates that the requested disk size is too small for the resize operation.
TooSmallDiskSize ResizedReason = "TooSmallDiskSize"
// Resized indicates that the resize operation has been successfully completed.
Resized ResizedReason = "Resized"
)
38 changes: 26 additions & 12 deletions api/core/v1alpha2/vicondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,41 @@ limitations under the License.

package vicondition

// Type represents the various condition types for the `VirtualImage`.
type Type = string

const (
// DatasourceReadyType indicates whether the datasource (for example, a `VirtualImage`) is ready, allowing the import process for the `VirtualImage` to start.
DatasourceReadyType Type = "DatasourceReady"
ReadyType Type = "Ready"
// ReadyType indicates whether the import process succeeded and the `VirtualImage` is ready for use.
ReadyType Type = "Ready"
)

type (
// DatasourceReadyReason represents the various reasons for the DatasourceReady condition type.
DatasourceReadyReason = string
ReadyReason = string
// ReadyReason represents the various reasons for the Ready condition type.
ReadyReason = string
)

const (
DatasourceReadyReason_DatasourceReady DatasourceReadyReason = "DatasourceReady"
DatasourceReadyReason_ContainerRegistrySecretNotFound DatasourceReadyReason = "ContainerRegistrySecretNotFound"
DatasourceReadyReason_ImageNotReady DatasourceReadyReason = "ImageNotReady"
DatasourceReadyReason_ClusterImageNotReady DatasourceReadyReason = "ClusterImageNotReady"

ReadyReason_WaitForUserUpload ReadyReason = "WaitForUserUpload"
ReadyReason_Provisioning ReadyReason = "Provisioning"
ReadyReason_ProvisioningNotStarted ReadyReason = "ProvisioningNotStarted"
ReadyReason_ProvisioningFailed ReadyReason = "ProvisioningFailed"
ReadyReason_Ready ReadyReason = "Ready"
// DatasourceReady indicates that the datasource is ready for use, allowing the import process to start.
DatasourceReady DatasourceReadyReason = "DatasourceReady"
// ContainerRegistrySecretNotFound indicates that the container registry secret was not found, which prevents the import process from starting.
ContainerRegistrySecretNotFound DatasourceReadyReason = "ContainerRegistrySecretNotFound"
// ImageNotReady indicates that the `VirtualImage` datasource is not ready yet, which prevents the import process from starting.
ImageNotReady DatasourceReadyReason = "ImageNotReady"
// ClusterImageNotReady indicates that the `VirtualImage` datasource is not ready, which prevents the import process from starting.
ClusterImageNotReady DatasourceReadyReason = "ClusterImageNotReady"

// WaitForUserUpload indicates that the `VirtualImage` is waiting for the user to upload a datasource for the import process to continue.
WaitForUserUpload ReadyReason = "WaitForUserUpload"
// Provisioning indicates that the provisioning process is currently in progress.
Provisioning ReadyReason = "Provisioning"
// ProvisioningNotStarted indicates that the provisioning process has not started yet.
ProvisioningNotStarted ReadyReason = "ProvisioningNotStarted"
// ProvisioningFailed indicates that the provisioning process has failed.
ProvisioningFailed ReadyReason = "ProvisioningFailed"
// Ready indicates that the import process is complete and the `VirtualImage` is ready for use.
Ready ReadyReason = "Ready"
)
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ func (h DatasourceReadyHandler) Handle(ctx context.Context, cvi *virtv2.ClusterV
switch {
case err == nil:
condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.DatasourceReadyReason_DatasourceReady
condition.Reason = cvicondition.DatasourceReady
condition.Message = ""
case errors.Is(err, source.ErrSecretNotFound):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.DatasourceReadyReason_ContainerRegistrySecretNotFound
condition.Reason = cvicondition.ContainerRegistrySecretNotFound
condition.Message = service.CapitalizeFirstLetter(err.Error())
case errors.As(err, &source.ImageNotReadyError{}):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.DatasourceReadyReason_ImageNotReady
condition.Reason = cvicondition.ImageNotReady
condition.Message = service.CapitalizeFirstLetter(err.Error())
case errors.As(err, &source.ClusterImageNotReadyError{}):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.DatasourceReadyReason_ClusterImageNotReady
condition.Reason = cvicondition.ClusterImageNotReady
condition.Message = service.CapitalizeFirstLetter(err.Error())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
ds.logger.Info("Finishing...", "cvi", cvi.Name)

condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.ReadyReason_Ready
condition.Reason = cvicondition.Ready
condition.Message = ""

cvi.Status.Phase = virtv2.ImageReady
Expand All @@ -91,7 +91,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
ds.logger.Info("Cleaning up...", "cvi", cvi.Name)
case pod == nil:
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_Provisioning
condition.Reason = cvicondition.Provisioning
condition.Message = "DVCR Provisioner not found: create the new one."

cvi.Status.Phase = virtv2.ImageProvisioning
Expand All @@ -108,7 +108,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
ds.logger.Info("Create importer pod...", "cvi", cvi.Name, "progress", cvi.Status.Progress, "pod.phase", "nil")
case common.IsPodComplete(pod):
condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.ReadyReason_Ready
condition.Reason = cvicondition.Ready
condition.Message = ""

cvi.Status.Phase = virtv2.ImageReady
Expand All @@ -128,12 +128,12 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
switch {
case errors.Is(err, service.ErrNotInitialized), errors.Is(err, service.ErrNotScheduled):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_ProvisioningNotStarted
condition.Reason = cvicondition.ProvisioningNotStarted
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_ProvisioningFailed
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
Expand All @@ -147,7 +147,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
}

condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_Provisioning
condition.Reason = cvicondition.Provisioning
condition.Message = "Import is in the process of provisioning to DVCR."

cvi.Status.Phase = virtv2.ImageProvisioning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
ds.logger.Info("Finishing...", "cvi", cvi.Name)

condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.ReadyReason_Ready
condition.Reason = cvicondition.Ready
condition.Message = ""

cvi.Status.Phase = virtv2.ImageReady
Expand All @@ -98,7 +98,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
ds.logger.Info("Cleaning up...", "cvi", cvi.Name)
case pod == nil:
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_Provisioning
condition.Reason = cvicondition.Provisioning
condition.Message = "DVCR Provisioner not found: create the new one."

var envSettings *importer.Settings
Expand All @@ -118,7 +118,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
ds.logger.Info("Ready", "cvi", cvi.Name, "progress", cvi.Status.Progress, "pod.phase", "nil")
case common.IsPodComplete(pod):
condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.ReadyReason_Ready
condition.Reason = cvicondition.Ready
condition.Message = ""

cvi.Status.Phase = virtv2.ImageReady
Expand All @@ -137,12 +137,12 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
switch {
case errors.Is(err, service.ErrNotInitialized), errors.Is(err, service.ErrNotScheduled):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_ProvisioningNotStarted
condition.Reason = cvicondition.ProvisioningNotStarted
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_ProvisioningFailed
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
Expand All @@ -151,7 +151,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
}

condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_Provisioning
condition.Reason = cvicondition.Provisioning
condition.Message = "Import is in the process of provisioning to DVCR."

cvi.Status.Phase = virtv2.ImageProvisioning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua
ds.logger.Info("Finishing...", "cvi", cvi.Name)

condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.ReadyReason_Ready
condition.Reason = cvicondition.Ready
condition.Message = ""

cvi.Status.Phase = virtv2.ImageReady
Expand All @@ -99,7 +99,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua
ds.logger.Info("Cleaning up...", "cvi", cvi.Name)
case pod == nil:
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_Provisioning
condition.Reason = cvicondition.Provisioning
condition.Message = "DVCR Provisioner not found: create the new one."

envSettings := ds.getEnvSettings(cvi, supgen)
Expand All @@ -115,7 +115,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua
ds.logger.Info("Create importer pod...", "cvi", cvi.Name, "progress", cvi.Status.Progress, "pod.phase", "nil")
case common.IsPodComplete(pod):
condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.ReadyReason_Ready
condition.Reason = cvicondition.Ready
condition.Message = ""

cvi.Status.Phase = virtv2.ImageReady
Expand All @@ -134,12 +134,12 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua
switch {
case errors.Is(err, service.ErrNotInitialized), errors.Is(err, service.ErrNotScheduled):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_ProvisioningNotStarted
condition.Reason = cvicondition.ProvisioningNotStarted
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_ProvisioningFailed
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
Expand All @@ -148,7 +148,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua
}

condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ReadyReason_Provisioning
condition.Reason = cvicondition.Provisioning
condition.Message = "Import is in the process of provisioning to DVCR."

cvi.Status.Phase = virtv2.ImageProvisioning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ func CleanUp(ctx context.Context, cvi *virtv2.ClusterVirtualImage, c Cleaner) (b
}

func isDiskProvisioningFinished(c metav1.Condition) bool {
return c.Reason == cvicondition.ReadyReason_Ready
return c.Reason == cvicondition.Ready
}
Loading

0 comments on commit a231f7e

Please sign in to comment.