Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foobar #608

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions api/core/v1alpha2/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,36 @@ const (

// ReasonVMClassInUse is event reason that VMClass is used by virtual machine.
ReasonVMClassInUse = "VirtualMachineClassInUse"

// ReasonVDStorageClassWasDeleted is event reason that VDStorageClass was deleted.
ReasonVDStorageClassWasDeleted = "VirtualDiskStorageClassWasDeleted"
// ReasonVDStorageClassNotFound is event reason that VDStorageClass not found.
ReasonVDStorageClassNotFound = "VirtualDiskStorageClassNotFound"
// ReasonVDSpecChanged is event reason that VDStorageClass is chanded.
ReasonVDSpecChanged = "VirtualDiskSpecChanged"
// ReasonVDContainerRegistrySecretNotFound is event reason that VDContainerRegistrySecret not found.
ReasonVDContainerRegistrySecretNotFound = "VirtualDiskContainerRegistrySecretNotFound"

// ReasonVDResizingStarted is event reason that VD Resizing is started.
ReasonVDResizingStarted = "VirtualDiskResizingStarted"
// ReasonVDResizingCompleted is event reason that VD Resizing is completed.
ReasonVDResizingCompleted = "VirtualDiskResizingCompleted"
// ReasonVDResizingFailed is event reason that VD Resizing is failed.
ReasonVDResizingFailed = "VirtualDiskResizingFailed"
// ReasonVDResizingNotAvailable is event reason that VD Resizing is not available.
ReasonVDResizingNotAvailable = "VirtualDiskResizingNotAvailable"

// ReasonDataSourceSyncStarted is event reason that DataSource sync is started.
ReasonDataSourceSyncStarted = "DataSourceImportStarted"
// ReasonDataSourceSyncInProgress is event reason that DataSource sync is in progress.
ReasonDataSourceSyncInProgress = "DataSourceImportInProgress"
// ReasonDataSourceSyncCompleted is event reason that DataSource sync is completed.
ReasonDataSourceSyncCompleted = "DataSourceImportCompleted"
// ReasonDataSourceSyncFailed is event reason that DataSource sync is failed.
ReasonDataSourceSyncFailed = "DataSourceImportFailed"
// ReasonDataSourceQuotaExceeded is event reason that DataSource sync is failed because quota exceed.
ReasonDataSourceQuotaExceeded = "DataSourceQuotaExceed"

// ReasonDataSourceDiskProvisioningFailed is event reason that DataSource disk provisioning is failed.
ReasonDataSourceDiskProvisioningFailed = "DataSourceImportDiskProvisioningFailed"
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/deckhouse/virtualization-controller/pkg/controller/cvi/internal/source"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/dvcr"
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
"github.com/deckhouse/virtualization-controller/pkg/logger"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
)
Expand Down Expand Up @@ -60,12 +61,13 @@ func NewController(
protection := service.NewProtectionService(mgr.GetClient(), virtv2.FinalizerCVIProtection)
importer := service.NewImporterService(dvcr, mgr.GetClient(), importerImage, requirements, PodPullPolicy, PodVerbose, ControllerName, protection)
uploader := service.NewUploaderService(dvcr, mgr.GetClient(), uploaderImage, requirements, PodPullPolicy, PodVerbose, ControllerName, protection)
recorder := eventrecord.NewEventRecorderLogger(mgr, ControllerName)

sources := source.NewSources()
sources.Set(virtv2.DataSourceTypeHTTP, source.NewHTTPDataSource(stat, importer, dvcr, ns))
sources.Set(virtv2.DataSourceTypeContainerImage, source.NewRegistryDataSource(stat, importer, dvcr, mgr.GetClient(), ns))
sources.Set(virtv2.DataSourceTypeObjectRef, source.NewObjectRefDataSource(stat, importer, dvcr, mgr.GetClient(), ns))
sources.Set(virtv2.DataSourceTypeUpload, source.NewUploadDataSource(stat, uploader, dvcr, ns))
sources.Set(virtv2.DataSourceTypeHTTP, source.NewHTTPDataSource(recorder, stat, importer, dvcr, ns))
sources.Set(virtv2.DataSourceTypeContainerImage, source.NewRegistryDataSource(recorder, stat, importer, dvcr, mgr.GetClient(), ns))
sources.Set(virtv2.DataSourceTypeObjectRef, source.NewObjectRefDataSource(recorder, stat, importer, dvcr, mgr.GetClient(), ns))
sources.Set(virtv2.DataSourceTypeUpload, source.NewUploadDataSource(recorder, stat, uploader, dvcr, ns))

reconciler := NewReconciler(
mgr.GetClient(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand All @@ -34,6 +35,7 @@ import (
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
"github.com/deckhouse/virtualization-controller/pkg/dvcr"
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
"github.com/deckhouse/virtualization-controller/pkg/logger"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
Expand All @@ -44,9 +46,11 @@ type HTTPDataSource struct {
importerService Importer
dvcrSettings *dvcr.Settings
controllerNamespace string
recorder eventrecord.EventRecorderLogger
}

func NewHTTPDataSource(
recorder eventrecord.EventRecorderLogger,
statService Stat,
importerService Importer,
dvcrSettings *dvcr.Settings,
Expand All @@ -57,6 +61,7 @@ func NewHTTPDataSource(
importerService: importerService,
dvcrSettings: dvcrSettings,
controllerNamespace: controllerNamespace,
recorder: recorder,
}
}

Expand Down Expand Up @@ -100,6 +105,13 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma

log.Info("Cleaning up...")
case pod == nil:
ds.recorder.Event(
cvi,
corev1.EventTypeNormal,
virtv2.ReasonDataSourceSyncStarted,
"The HTTP DataSource import has started",
)

cvi.Status.Progress = ds.statService.GetProgress(cvi.GetUID(), pod, cvi.Status.Progress)

envSettings := ds.getEnvSettings(cvi, supgen)
Expand All @@ -108,6 +120,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
case err == nil:
// OK.
case common.ErrQuotaExceeded(err):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceQuotaExceeded, "DataSource quota exceed")
return setQuotaExceededPhaseCondition(cb, &cvi.Status.Phase, err, cvi.CreationTimestamp), nil
default:
setPhaseConditionToFailed(cb, &cvi.Status.Phase, fmt.Errorf("unexpected error: %w", err))
Expand All @@ -129,6 +142,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma

switch {
case errors.Is(err, service.ErrProvisioningFailed):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceDiskProvisioningFailed, "Disk provisioning failed")
cb.Status(metav1.ConditionFalse).
Reason(cvicondition.ProvisioningFailed).
Message(service.CapitalizeFirstLetter(err.Error() + "."))
Expand All @@ -138,6 +152,13 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
}
}

ds.recorder.Event(
cvi,
corev1.EventTypeNormal,
virtv2.ReasonDataSourceSyncCompleted,
"The HTTP DataSource import has completed",
)

cb.Status(metav1.ConditionTrue).
Reason(cvicondition.Ready).
Message("")
Expand All @@ -163,6 +184,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
Message(service.CapitalizeFirstLetter(err.Error() + "."))
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceDiskProvisioningFailed, "Disk provisioning failed")
cb.Status(metav1.ConditionFalse).
Reason(cvicondition.ProvisioningFailed).
Message(service.CapitalizeFirstLetter(err.Error() + "."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -37,6 +38,7 @@ import (
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
"github.com/deckhouse/virtualization-controller/pkg/dvcr"
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
"github.com/deckhouse/virtualization-controller/pkg/logger"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
Expand All @@ -48,12 +50,14 @@ type ObjectRefDataSource struct {
dvcrSettings *dvcr.Settings
client client.Client
controllerNamespace string
recorder eventrecord.EventRecorderLogger

viOnPvcSyncer *ObjectRefVirtualImageOnPvc
vdSyncer *ObjectRefVirtualDisk
}

func NewObjectRefDataSource(
recorder eventrecord.EventRecorderLogger,
statService Stat,
importerService Importer,
dvcrSettings *dvcr.Settings,
Expand All @@ -66,9 +70,10 @@ func NewObjectRefDataSource(
dvcrSettings: dvcrSettings,
client: client,
controllerNamespace: controllerNamespace,
recorder: recorder,

viOnPvcSyncer: NewObjectRefVirtualImageOnPvc(importerService, dvcrSettings, statService),
vdSyncer: NewObjectRefVirtualDisk(importerService, client, controllerNamespace, dvcrSettings, statService),
viOnPvcSyncer: NewObjectRefVirtualImageOnPvc(recorder, importerService, dvcrSettings, statService),
vdSyncer: NewObjectRefVirtualDisk(recorder, importerService, client, controllerNamespace, dvcrSettings, statService),
}
}

Expand Down Expand Up @@ -159,6 +164,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
case err == nil:
// OK.
case common.ErrQuotaExceeded(err):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceQuotaExceeded, "DataSource quota exceed")
return setQuotaExceededPhaseCondition(cb, &cvi.Status.Phase, err, cvi.CreationTimestamp), nil
default:
setPhaseConditionToFailed(cb, &cvi.Status.Phase, fmt.Errorf("unexpected error: %w", err))
Expand All @@ -181,6 +187,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu

switch {
case errors.Is(err, service.ErrProvisioningFailed):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceDiskProvisioningFailed, "Disk provisioning failed")
cb.
Status(metav1.ConditionFalse).
Reason(cvicondition.ProvisioningFailed).
Expand Down Expand Up @@ -232,6 +239,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
Message(service.CapitalizeFirstLetter(err.Error() + "."))
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceDiskProvisioningFailed, "Disk provisioning failed")
cb.
Status(metav1.ConditionFalse).
Reason(cvicondition.ProvisioningFailed).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
"github.com/deckhouse/virtualization-controller/pkg/dvcr"
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
"github.com/deckhouse/virtualization-controller/pkg/logger"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
Expand All @@ -48,15 +50,17 @@ type ObjectRefVirtualDisk struct {
statService Stat
dvcrSettings *dvcr.Settings
controllerNamespace string
recorder eventrecord.EventRecorderLogger
}

func NewObjectRefVirtualDisk(importerService Importer, client client.Client, controllerNamespace string, dvcrSettings *dvcr.Settings, statService Stat) *ObjectRefVirtualDisk {
func NewObjectRefVirtualDisk(recorder eventrecord.EventRecorderLogger, importerService Importer, client client.Client, controllerNamespace string, dvcrSettings *dvcr.Settings, statService Stat) *ObjectRefVirtualDisk {
return &ObjectRefVirtualDisk{
importerService: importerService,
statService: statService,
dvcrSettings: dvcrSettings,
client: client,
controllerNamespace: controllerNamespace,
recorder: recorder,
}
}

Expand Down Expand Up @@ -103,6 +107,7 @@ func (ds ObjectRefVirtualDisk) Sync(ctx context.Context, cvi *virtv2.ClusterVirt
case err == nil:
// OK.
case common.ErrQuotaExceeded(err):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceQuotaExceeded, "DataSource quota exceed")
return setQuotaExceededPhaseCondition(cb, &cvi.Status.Phase, err, cvi.CreationTimestamp), nil
default:
setPhaseConditionToFailed(cb, &cvi.Status.Phase, fmt.Errorf("unexpected error: %w", err))
Expand All @@ -125,6 +130,7 @@ func (ds ObjectRefVirtualDisk) Sync(ctx context.Context, cvi *virtv2.ClusterVirt

switch {
case errors.Is(err, service.ErrProvisioningFailed):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceDiskProvisioningFailed, "Disk provisioning failed")
cb.
Status(metav1.ConditionFalse).
Reason(cvicondition.ProvisioningFailed).
Expand Down Expand Up @@ -161,6 +167,7 @@ func (ds ObjectRefVirtualDisk) Sync(ctx context.Context, cvi *virtv2.ClusterVirt
Message(service.CapitalizeFirstLetter(err.Error() + "."))
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceDiskProvisioningFailed, "Disk provisioning failed")
cb.
Status(metav1.ConditionFalse).
Reason(cvicondition.ProvisioningFailed).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand All @@ -34,6 +35,7 @@ import (
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
"github.com/deckhouse/virtualization-controller/pkg/dvcr"
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
"github.com/deckhouse/virtualization-controller/pkg/logger"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
Expand All @@ -45,13 +47,15 @@ type ObjectRefVirtualImageOnPvc struct {
importerService Importer
statService Stat
dvcrSettings *dvcr.Settings
recorder eventrecord.EventRecorderLogger
}

func NewObjectRefVirtualImageOnPvc(importerService Importer, dvcrSettings *dvcr.Settings, statService Stat) *ObjectRefVirtualImageOnPvc {
func NewObjectRefVirtualImageOnPvc(recorder eventrecord.EventRecorderLogger, importerService Importer, dvcrSettings *dvcr.Settings, statService Stat) *ObjectRefVirtualImageOnPvc {
return &ObjectRefVirtualImageOnPvc{
importerService: importerService,
statService: statService,
dvcrSettings: dvcrSettings,
recorder: recorder,
}
}

Expand Down Expand Up @@ -98,6 +102,7 @@ func (ds ObjectRefVirtualImageOnPvc) Sync(ctx context.Context, cvi *virtv2.Clust
case err == nil:
// OK.
case common.ErrQuotaExceeded(err):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceQuotaExceeded, "DataSource quota exceed")
return setQuotaExceededPhaseCondition(cb, &cvi.Status.Phase, err, cvi.CreationTimestamp), nil
default:
setPhaseConditionToFailed(cb, &cvi.Status.Phase, fmt.Errorf("unexpected error: %w", err))
Expand All @@ -120,6 +125,7 @@ func (ds ObjectRefVirtualImageOnPvc) Sync(ctx context.Context, cvi *virtv2.Clust

switch {
case errors.Is(err, service.ErrProvisioningFailed):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceDiskProvisioningFailed, "Disk provisioning failed")
cb.
Status(metav1.ConditionFalse).
Reason(cvicondition.ProvisioningFailed).
Expand Down Expand Up @@ -156,6 +162,7 @@ func (ds ObjectRefVirtualImageOnPvc) Sync(ctx context.Context, cvi *virtv2.Clust
Message(service.CapitalizeFirstLetter(err.Error() + "."))
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
ds.recorder.Event(cvi, corev1.EventTypeWarning, virtv2.ReasonDataSourceDiskProvisioningFailed, "Disk provisioning failed")
cb.
Status(metav1.ConditionFalse).
Reason(cvicondition.ProvisioningFailed).
Expand Down
Loading
Loading