diff --git a/images/dvcr-artifact/pkg/importer/importer.go b/images/dvcr-artifact/pkg/importer/importer.go index 0c5f50bc4..aeeeccd25 100644 --- a/images/dvcr-artifact/pkg/importer/importer.go +++ b/images/dvcr-artifact/pkg/importer/importer.go @@ -139,7 +139,7 @@ func (i *Importer) runForDVCRSource(ctx context.Context) error { durCollector := monitoring.NewDurationCollector() craneOpts := i.destCraneOptions(ctx) - err := crane.CopyRepository(i.src, i.destImageName, craneOpts...) + err := crane.Copy(i.src, i.destImageName, craneOpts...) if err != nil { return fmt.Errorf("error copy repository: %w", err) } diff --git a/images/virtualization-artifact/pkg/controller/cvi/internal/source/http.go b/images/virtualization-artifact/pkg/controller/cvi/internal/source/http.go index 82982fe7a..51101ed12 100644 --- a/images/virtualization-artifact/pkg/controller/cvi/internal/source/http.go +++ b/images/virtualization-artifact/pkg/controller/cvi/internal/source/http.go @@ -89,7 +89,6 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma log.Info("Cleaning up...") case pod == nil: cvi.Status.Progress = ds.statService.GetProgress(cvi.GetUID(), pod, cvi.Status.Progress) - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) envSettings := ds.getEnvSettings(cvi, supgen) err = ds.importerService.Start(ctx, envSettings, cvi, supgen, datasource.NewCABundleForCVMI(cvi.Spec.DataSource)) @@ -127,7 +126,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma cvi.Status.CDROM = ds.statService.GetCDROM(pod) cvi.Status.Format = ds.statService.GetFormat(pod) cvi.Status.Progress = ds.statService.GetProgress(cvi.GetUID(), pod, cvi.Status.Progress) - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) cvi.Status.DownloadSpeed = ds.statService.GetDownloadSpeed(cvi.GetUID(), pod) log.Info("Ready", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase) @@ -163,7 +162,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma cvi.Status.Phase = virtv2.ImageProvisioning cvi.Status.Progress = ds.statService.GetProgress(cvi.GetUID(), pod, cvi.Status.Progress) - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) cvi.Status.DownloadSpeed = ds.statService.GetDownloadSpeed(cvi.GetUID(), pod) log.Info("Provisioning...", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase) @@ -195,7 +194,7 @@ func (ds HTTPDataSource) getEnvSettings(cvi *virtv2.ClusterVirtualImage, supgen &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForCVMI(cvi.Name), + ds.dvcrSettings.RegistryImageForCVI(cvi), ) return &settings diff --git a/images/virtualization-artifact/pkg/controller/cvi/internal/source/interfaces.go b/images/virtualization-artifact/pkg/controller/cvi/internal/source/interfaces.go index 58bcb8039..e64c2f5d9 100644 --- a/images/virtualization-artifact/pkg/controller/cvi/internal/source/interfaces.go +++ b/images/virtualization-artifact/pkg/controller/cvi/internal/source/interfaces.go @@ -55,6 +55,7 @@ type Stat interface { GetFormat(pod *corev1.Pod) string GetCDROM(pod *corev1.Pod) bool GetSize(pod *corev1.Pod) virtv2.ImageStatusSize + GetDVCRImageName(pod *corev1.Pod) string GetDownloadSpeed(ownerUID types.UID, pod *corev1.Pod) *virtv2.StatusSpeed GetProgress(ownerUID types.UID, pod *corev1.Pod, prevProgress string, opts ...service.GetProgressOption) string IsUploadStarted(ownerUID types.UID, pod *corev1.Pod) bool diff --git a/images/virtualization-artifact/pkg/controller/cvi/internal/source/mock.go b/images/virtualization-artifact/pkg/controller/cvi/internal/source/mock.go index 6a3388053..327ad54c8 100644 --- a/images/virtualization-artifact/pkg/controller/cvi/internal/source/mock.go +++ b/images/virtualization-artifact/pkg/controller/cvi/internal/source/mock.go @@ -737,6 +737,9 @@ var _ Stat = &StatMock{} // GetCDROMFunc: func(pod *corev1.Pod) bool { // panic("mock out the GetCDROM method") // }, +// GetDVCRImageNameFunc: func(pod *corev1.Pod) string { +// panic("mock out the GetDVCRImageName method") +// }, // GetDownloadSpeedFunc: func(ownerUID types.UID, pod *corev1.Pod) *virtv2.StatusSpeed { // panic("mock out the GetDownloadSpeed method") // }, @@ -765,6 +768,9 @@ type StatMock struct { // GetCDROMFunc mocks the GetCDROM method. GetCDROMFunc func(pod *corev1.Pod) bool + // GetDVCRImageNameFunc mocks the GetDVCRImageName method. + GetDVCRImageNameFunc func(pod *corev1.Pod) string + // GetDownloadSpeedFunc mocks the GetDownloadSpeed method. GetDownloadSpeedFunc func(ownerUID types.UID, pod *corev1.Pod) *virtv2.StatusSpeed @@ -792,6 +798,11 @@ type StatMock struct { // Pod is the pod argument value. Pod *corev1.Pod } + // GetDVCRImageName holds details about calls to the GetDVCRImageName method. + GetDVCRImageName []struct { + // Pod is the pod argument value. + Pod *corev1.Pod + } // GetDownloadSpeed holds details about calls to the GetDownloadSpeed method. GetDownloadSpeed []struct { // OwnerUID is the ownerUID argument value. @@ -830,6 +841,7 @@ type StatMock struct { } lockCheckPod sync.RWMutex lockGetCDROM sync.RWMutex + lockGetDVCRImageName sync.RWMutex lockGetDownloadSpeed sync.RWMutex lockGetFormat sync.RWMutex lockGetProgress sync.RWMutex @@ -901,6 +913,38 @@ func (mock *StatMock) GetCDROMCalls() []struct { return calls } +// GetDVCRImageName calls GetDVCRImageNameFunc. +func (mock *StatMock) GetDVCRImageName(pod *corev1.Pod) string { + if mock.GetDVCRImageNameFunc == nil { + panic("StatMock.GetDVCRImageNameFunc: method is nil but Stat.GetDVCRImageName was just called") + } + callInfo := struct { + Pod *corev1.Pod + }{ + Pod: pod, + } + mock.lockGetDVCRImageName.Lock() + mock.calls.GetDVCRImageName = append(mock.calls.GetDVCRImageName, callInfo) + mock.lockGetDVCRImageName.Unlock() + return mock.GetDVCRImageNameFunc(pod) +} + +// GetDVCRImageNameCalls gets all the calls that were made to GetDVCRImageName. +// Check the length with: +// +// len(mockedStat.GetDVCRImageNameCalls()) +func (mock *StatMock) GetDVCRImageNameCalls() []struct { + Pod *corev1.Pod +} { + var calls []struct { + Pod *corev1.Pod + } + mock.lockGetDVCRImageName.RLock() + calls = mock.calls.GetDVCRImageName + mock.lockGetDVCRImageName.RUnlock() + return calls +} + // GetDownloadSpeed calls GetDownloadSpeedFunc. func (mock *StatMock) GetDownloadSpeed(ownerUID types.UID, pod *corev1.Pod) *virtv2.StatusSpeed { if mock.GetDownloadSpeedFunc == nil { diff --git a/images/virtualization-artifact/pkg/controller/cvi/internal/source/object_ref.go b/images/virtualization-artifact/pkg/controller/cvi/internal/source/object_ref.go index 1d6339984..89ab999f9 100644 --- a/images/virtualization-artifact/pkg/controller/cvi/internal/source/object_ref.go +++ b/images/virtualization-artifact/pkg/controller/cvi/internal/source/object_ref.go @@ -113,8 +113,6 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu return false, err } - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) - log.Info("Ready", "progress", cvi.Status.Progress, "pod.phase", "nil") return requeue, nil @@ -157,7 +155,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu cvi.Status.CDROM = dvcrDataSource.IsCDROM() cvi.Status.Format = dvcrDataSource.GetFormat() cvi.Status.Progress = "100%" - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("Ready", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase) default: @@ -186,7 +184,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu condition.Message = "Import is in the process of provisioning to DVCR." cvi.Status.Phase = virtv2.ImageProvisioning - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("Ready", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase) } @@ -240,7 +238,7 @@ func (ds ObjectRefDataSource) getEnvSettings(cvi *virtv2.ClusterVirtualImage, su &settings, ds.dvcrSettings, sup, - ds.dvcrSettings.RegistryImageForCVMI(cvi.Name), + ds.dvcrSettings.RegistryImageForCVI(cvi), ) return &settings, nil diff --git a/images/virtualization-artifact/pkg/controller/cvi/internal/source/registry.go b/images/virtualization-artifact/pkg/controller/cvi/internal/source/registry.go index b3341bcf2..88859339c 100644 --- a/images/virtualization-artifact/pkg/controller/cvi/internal/source/registry.go +++ b/images/virtualization-artifact/pkg/controller/cvi/internal/source/registry.go @@ -96,6 +96,8 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua log.Info("Cleaning up...") case pod == nil: + cvi.Status.Progress = "0%" + envSettings := ds.getEnvSettings(cvi, supgen) err = ds.importerService.Start(ctx, envSettings, cvi, supgen, datasource.NewCABundleForCVMI(cvi.Spec.DataSource)) var requeue bool @@ -104,9 +106,6 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua return false, err } - cvi.Status.Progress = "0%" - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) - log.Info("Create importer pod...", "progress", cvi.Status.Progress, "pod.phase", "nil") return requeue, nil @@ -135,7 +134,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua cvi.Status.CDROM = ds.statService.GetCDROM(pod) cvi.Status.Format = ds.statService.GetFormat(pod) cvi.Status.Progress = "100%" - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("Ready", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase) default: @@ -165,7 +164,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua cvi.Status.Phase = virtv2.ImageProvisioning cvi.Status.Progress = "0%" - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("Provisioning...", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase) } @@ -211,7 +210,7 @@ func (ds RegistryDataSource) getEnvSettings(cvi *virtv2.ClusterVirtualImage, sup &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForCVMI(cvi.Name), + ds.dvcrSettings.RegistryImageForCVI(cvi), ) return &settings diff --git a/images/virtualization-artifact/pkg/controller/cvi/internal/source/upload.go b/images/virtualization-artifact/pkg/controller/cvi/internal/source/upload.go index 55a03dfd5..b76110f9c 100644 --- a/images/virtualization-artifact/pkg/controller/cvi/internal/source/upload.go +++ b/images/virtualization-artifact/pkg/controller/cvi/internal/source/upload.go @@ -103,7 +103,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualI log.Info("Cleaning up...") case pod == nil || svc == nil || ing == nil: - envSettings := ds.getEnvSettings(supgen) + envSettings := ds.getEnvSettings(cvi, supgen) err = ds.uploaderService.Start(ctx, envSettings, cvi, supgen, datasource.NewCABundleForCVMI(cvi.Spec.DataSource)) var requeue bool requeue, err = setPhaseConditionForUploaderStart(&condition, &cvi.Status.Phase, err) @@ -111,8 +111,6 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualI return false, err } - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) - log.Info("Create uploader pod...", "progress", cvi.Status.Progress, "pod.phase", nil) return requeue, nil @@ -141,7 +139,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualI cvi.Status.CDROM = ds.statService.GetCDROM(pod) cvi.Status.Format = ds.statService.GetFormat(pod) cvi.Status.Progress = "100%" - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) cvi.Status.DownloadSpeed = ds.statService.GetDownloadSpeed(cvi.GetUID(), pod) log.Info("Ready", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase) @@ -172,7 +170,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualI cvi.Status.Phase = virtv2.ImageProvisioning cvi.Status.Progress = ds.statService.GetProgress(cvi.GetUID(), pod, cvi.Status.Progress) - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) cvi.Status.DownloadSpeed = ds.statService.GetDownloadSpeed(cvi.GetUID(), pod) err = ds.uploaderService.Protect(ctx, pod, svc, ing) @@ -187,7 +185,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualI condition.Message = "Waiting for the user upload." cvi.Status.Phase = virtv2.ImageWaitForUserUpload - cvi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForCVMI(cvi.Name) + cvi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("WaitForUserUpload...", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase) } @@ -210,14 +208,14 @@ func (ds UploadDataSource) Validate(_ context.Context, _ *virtv2.ClusterVirtualI return nil } -func (ds UploadDataSource) getEnvSettings(supgen *supplements.Generator) *uploader.Settings { +func (ds UploadDataSource) getEnvSettings(cvi *virtv2.ClusterVirtualImage, supgen *supplements.Generator) *uploader.Settings { var settings uploader.Settings uploader.ApplyDVCRDestinationSettings( &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForCVMI(supgen.Name), + ds.dvcrSettings.RegistryImageForCVI(cvi), ) return &settings diff --git a/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_utils.go b/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_utils.go index 43f07229d..ce92c4228 100644 --- a/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_utils.go +++ b/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_utils.go @@ -25,7 +25,6 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/controller/common" "github.com/deckhouse/virtualization-controller/pkg/controller/ipam" - "github.com/deckhouse/virtualization-controller/pkg/dvcr" "github.com/deckhouse/virtualization-controller/pkg/imageformat" "github.com/deckhouse/virtualization-controller/pkg/util" virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2" @@ -66,10 +65,9 @@ type HotPlugDeviceSettings struct { func ApplyVirtualMachineSpec( kvvm *KVVM, vm *virtv2.VirtualMachine, - vmdByName map[string]*virtv2.VirtualDisk, - vmiByName map[string]*virtv2.VirtualImage, - cvmiByName map[string]*virtv2.ClusterVirtualImage, - dvcrSettings *dvcr.Settings, + vdByName map[string]*virtv2.VirtualDisk, + viByName map[string]*virtv2.VirtualImage, + cviByName map[string]*virtv2.ClusterVirtualImage, class *virtv2.VirtualMachineClass, ipAddress string, ) error { @@ -124,14 +122,14 @@ func ApplyVirtualMachineSpec( // Attach ephemeral disk for storage: Kubernetes. // Attach containerDisk for storage: ContainerRegistry (i.e. image from DVCR). - vmi := vmiByName[bd.Name] + vi := viByName[bd.Name] name := GenerateVMIDiskName(bd.Name) - switch vmi.Spec.Storage { + switch vi.Spec.Storage { case virtv2.StorageKubernetes: // Attach PVC as ephemeral volume: its data will be restored to initial state on VM restart. if err := kvvm.SetDisk(name, SetDiskOptions{ - PersistentVolumeClaim: util.GetPointer(vmi.Status.Target.PersistentVolumeClaim), + PersistentVolumeClaim: util.GetPointer(vi.Status.Target.PersistentVolumeClaim), IsEphemeral: true, Serial: name, BootOrder: bootOrder, @@ -139,30 +137,28 @@ func ApplyVirtualMachineSpec( return err } case virtv2.StorageContainerRegistry: - dvcrImage := dvcrSettings.RegistryImageForVMI(vmi.Name, vmi.Namespace) if err := kvvm.SetDisk(name, SetDiskOptions{ - ContainerDisk: util.GetPointer(dvcrImage), - IsCdrom: imageformat.IsISO(vmi.Status.Format), + ContainerDisk: util.GetPointer(vi.Status.Target.RegistryURL), + IsCdrom: imageformat.IsISO(vi.Status.Format), Serial: name, BootOrder: bootOrder, }); err != nil { return err } default: - return fmt.Errorf("unexpected storage type %q for vi %s. %w", vmi.Spec.Storage, vmi.Name, common.ErrUnknownType) + return fmt.Errorf("unexpected storage type %q for vi %s. %w", vi.Spec.Storage, vi.Name, common.ErrUnknownType) } bootOrder++ case virtv2.ClusterImageDevice: // ClusterVirtualImage is attached as containerDisk. - cvmi := cvmiByName[bd.Name] + cvi := cviByName[bd.Name] name := GenerateCVMIDiskName(bd.Name) - dvcrImage := dvcrSettings.RegistryImageForCVMI(cvmi.Name) if err := kvvm.SetDisk(name, SetDiskOptions{ - ContainerDisk: util.GetPointer(dvcrImage), - IsCdrom: imageformat.IsISO(cvmi.Status.Format), + ContainerDisk: util.GetPointer(cvi.Status.Target.RegistryURL), + IsCdrom: imageformat.IsISO(cvi.Status.Format), Serial: name, BootOrder: bootOrder, }); err != nil { @@ -173,15 +169,15 @@ func ApplyVirtualMachineSpec( case virtv2.DiskDevice: // VirtualDisk is attached as a regular disk. - vmd := vmdByName[bd.Name] + vd := vdByName[bd.Name] // VirtualDisk doesn't have pvc yet: wait for pvc and reconcile again. - if vmd.Status.Target.PersistentVolumeClaim == "" { + if vd.Status.Target.PersistentVolumeClaim == "" { continue } name := GenerateVMDDiskName(bd.Name) if err := kvvm.SetDisk(name, SetDiskOptions{ - PersistentVolumeClaim: util.GetPointer(vmd.Status.Target.PersistentVolumeClaim), + PersistentVolumeClaim: util.GetPointer(vd.Status.Target.PersistentVolumeClaim), Serial: name, BootOrder: bootOrder, }); err != nil { diff --git a/images/virtualization-artifact/pkg/controller/service/stat_service.go b/images/virtualization-artifact/pkg/controller/service/stat_service.go index 9f7777977..18ab21ea7 100644 --- a/images/virtualization-artifact/pkg/controller/service/stat_service.go +++ b/images/virtualization-artifact/pkg/controller/service/stat_service.go @@ -263,3 +263,19 @@ func (s StatService) GetImportDuration(pod *corev1.Pod) time.Duration { return report.Duration } + +func (s StatService) GetDVCRImageName(pod *corev1.Pod) string { + if pod == nil { + return "" + } + + for _, container := range pod.Spec.Containers { + for _, envVar := range container.Env { + if envVar.Name == common.ImporterDestinationEndpoint { + return envVar.Value + } + } + } + + return "" +} diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/source/http.go b/images/virtualization-artifact/pkg/controller/vd/internal/source/http.go index 1b835cc1f..46ae5ef05 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/source/http.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/source/http.go @@ -195,7 +195,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (bool return false, err } - source := ds.getSource(vd, supgen) + source := ds.getSource(supgen, ds.statService.GetDVCRImageName(pod)) err = ds.diskService.Start(ctx, diskSize, vd.Spec.PersistentVolumeClaim.StorageClass, source, vd, supgen) if updated, err := setPhaseConditionFromStorageError(err, vd, &condition); err != nil || updated { @@ -299,18 +299,16 @@ func (ds HTTPDataSource) getEnvSettings(vd *virtv2.VirtualDisk, supgen *suppleme &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForVMD(vd.Name, vd.Namespace), + ds.dvcrSettings.RegistryImageForVD(vd), ) return &settings } -func (ds HTTPDataSource) getSource(vd *virtv2.VirtualDisk, sup *supplements.Generator) *cdiv1.DataVolumeSource { +func (ds HTTPDataSource) getSource(sup *supplements.Generator, dvcrSourceImageName string) *cdiv1.DataVolumeSource { // The image was preloaded from source into dvcr. // We can't use the same data source a second time, but we can set dvcr as the data source. // Use DV name for the Secret with DVCR auth and the ConfigMap with DVCR CA Bundle. - dvcrSourceImageName := ds.dvcrSettings.RegistryImageForVMD(vd.Name, vd.Namespace) - url := cc.DockerRegistrySchemePrefix + dvcrSourceImageName secretName := sup.DVCRAuthSecretForDV().Name certConfigMapName := sup.DVCRCABundleConfigMapForDV().Name diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/source/registry.go b/images/virtualization-artifact/pkg/controller/vd/internal/source/registry.go index d7831b85f..fa8d82751 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/source/registry.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/source/registry.go @@ -199,7 +199,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) ( return false, err } - source := ds.getSource(vd, supgen) + source := ds.getSource(supgen, ds.statService.GetDVCRImageName(pod)) err = ds.diskService.Start(ctx, diskSize, vd.Spec.PersistentVolumeClaim.StorageClass, source, vd, supgen) if updated, err := setPhaseConditionFromStorageError(err, vd, &condition); err != nil || updated { @@ -319,18 +319,16 @@ func (ds RegistryDataSource) getEnvSettings(vd *virtv2.VirtualDisk, supgen *supp &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForVMD(vd.Name, vd.Namespace), + ds.dvcrSettings.RegistryImageForVD(vd), ) return &settings } -func (ds RegistryDataSource) getSource(vd *virtv2.VirtualDisk, sup *supplements.Generator) *cdiv1.DataVolumeSource { +func (ds RegistryDataSource) getSource(sup *supplements.Generator, dvcrSourceImageName string) *cdiv1.DataVolumeSource { // The image was preloaded from source into dvcr. // We can't use the same data source a second time, but we can set dvcr as the data source. // Use DV name for the Secret with DVCR auth and the ConfigMap with DVCR CA Bundle. - dvcrSourceImageName := ds.dvcrSettings.RegistryImageForVMD(vd.Name, vd.Namespace) - url := cc.DockerRegistrySchemePrefix + dvcrSourceImageName secretName := sup.DVCRAuthSecretForDV().Name certConfigMapName := sup.DVCRCABundleConfigMapForDV().Name diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/source/upload.go b/images/virtualization-artifact/pkg/controller/vd/internal/source/upload.go index 76c522772..849a44b60 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/source/upload.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/source/upload.go @@ -125,7 +125,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (bo case pod == nil || svc == nil || ing == nil: log.Info("Start import to DVCR") - envSettings := ds.getEnvSettings(supgen) + envSettings := ds.getEnvSettings(vd, supgen) err = ds.uploaderService.Start(ctx, envSettings, vd, supgen, datasource.NewCABundleForVMD(vd.Spec.DataSource)) var requeue bool requeue, err = setPhaseConditionForUploaderStart(&condition, &vd.Status.Phase, err) @@ -220,7 +220,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (bo return false, err } - source := ds.getSource(vd, supgen) + source := ds.getSource(supgen, ds.statService.GetDVCRImageName(pod)) err = ds.diskService.Start(ctx, diskSize, vd.Spec.PersistentVolumeClaim.StorageClass, source, vd, supgen) if updated, err := setPhaseConditionFromStorageError(err, vd, &condition); err != nil || updated { @@ -316,25 +316,23 @@ func (ds UploadDataSource) Name() string { return uploadDataSource } -func (ds UploadDataSource) getEnvSettings(supgen *supplements.Generator) *uploader.Settings { +func (ds UploadDataSource) getEnvSettings(vd *virtv2.VirtualDisk, supgen *supplements.Generator) *uploader.Settings { var settings uploader.Settings uploader.ApplyDVCRDestinationSettings( &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForVMD(supgen.Name, supgen.Namespace), + ds.dvcrSettings.RegistryImageForVD(vd), ) return &settings } -func (ds UploadDataSource) getSource(vd *virtv2.VirtualDisk, sup *supplements.Generator) *cdiv1.DataVolumeSource { +func (ds UploadDataSource) getSource(sup *supplements.Generator, dvcrSourceImageName string) *cdiv1.DataVolumeSource { // The image was preloaded from source into dvcr. // We can't use the same data source a second time, but we can set dvcr as the data source. // Use DV name for the Secret with DVCR auth and the ConfigMap with DVCR CA Bundle. - dvcrSourceImageName := ds.dvcrSettings.RegistryImageForVMD(vd.Name, vd.Namespace) - url := common2.DockerRegistrySchemePrefix + dvcrSourceImageName secretName := sup.DVCRAuthSecretForDV().Name certConfigMapName := sup.DVCRCABundleConfigMapForDV().Name diff --git a/images/virtualization-artifact/pkg/controller/vi/internal/source/http.go b/images/virtualization-artifact/pkg/controller/vi/internal/source/http.go index b22f546c9..58462e152 100644 --- a/images/virtualization-artifact/pkg/controller/vi/internal/source/http.go +++ b/images/virtualization-artifact/pkg/controller/vi/internal/source/http.go @@ -85,7 +85,6 @@ func (ds HTTPDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (boo log.Info("Cleaning up...") case pod == nil: vi.Status.Progress = ds.statService.GetProgress(vi.GetUID(), pod, vi.Status.Progress) - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) envSettings := ds.getEnvSettings(vi, supgen) err = ds.importerService.Start(ctx, envSettings, vi, supgen, datasource.NewCABundleForVMI(vi.Spec.DataSource)) @@ -123,7 +122,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (boo vi.Status.CDROM = ds.statService.GetCDROM(pod) vi.Status.Format = ds.statService.GetFormat(pod) vi.Status.Progress = ds.statService.GetProgress(vi.GetUID(), pod, vi.Status.Progress) - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) vi.Status.DownloadSpeed = ds.statService.GetDownloadSpeed(vi.GetUID(), pod) log.Info("Ready", "progress", vi.Status.Progress, "pod.phase", pod.Status.Phase) @@ -159,7 +158,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (boo vi.Status.Phase = virtv2.ImageProvisioning vi.Status.Progress = ds.statService.GetProgress(vi.GetUID(), pod, vi.Status.Progress) - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) vi.Status.DownloadSpeed = ds.statService.GetDownloadSpeed(vi.GetUID(), pod) log.Info("Provisioning...", "progress", vi.Status.Progress, "pod.phase", pod.Status.Phase) @@ -191,7 +190,7 @@ func (ds HTTPDataSource) getEnvSettings(vi *virtv2.VirtualImage, supgen *supplem &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace), + ds.dvcrSettings.RegistryImageForVI(vi), ) return &settings diff --git a/images/virtualization-artifact/pkg/controller/vi/internal/source/interfaces.go b/images/virtualization-artifact/pkg/controller/vi/internal/source/interfaces.go index 58bcb8039..e64c2f5d9 100644 --- a/images/virtualization-artifact/pkg/controller/vi/internal/source/interfaces.go +++ b/images/virtualization-artifact/pkg/controller/vi/internal/source/interfaces.go @@ -55,6 +55,7 @@ type Stat interface { GetFormat(pod *corev1.Pod) string GetCDROM(pod *corev1.Pod) bool GetSize(pod *corev1.Pod) virtv2.ImageStatusSize + GetDVCRImageName(pod *corev1.Pod) string GetDownloadSpeed(ownerUID types.UID, pod *corev1.Pod) *virtv2.StatusSpeed GetProgress(ownerUID types.UID, pod *corev1.Pod, prevProgress string, opts ...service.GetProgressOption) string IsUploadStarted(ownerUID types.UID, pod *corev1.Pod) bool diff --git a/images/virtualization-artifact/pkg/controller/vi/internal/source/mock.go b/images/virtualization-artifact/pkg/controller/vi/internal/source/mock.go new file mode 100644 index 000000000..327ad54c8 --- /dev/null +++ b/images/virtualization-artifact/pkg/controller/vi/internal/source/mock.go @@ -0,0 +1,1126 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package source + +import ( + "context" + "github.com/deckhouse/virtualization-controller/pkg/common/datasource" + "github.com/deckhouse/virtualization-controller/pkg/controller/importer" + "github.com/deckhouse/virtualization-controller/pkg/controller/service" + "github.com/deckhouse/virtualization-controller/pkg/controller/supplements" + "github.com/deckhouse/virtualization-controller/pkg/controller/uploader" + virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2" + corev1 "k8s.io/api/core/v1" + netv1 "k8s.io/api/networking/v1" + "k8s.io/apimachinery/pkg/types" + "sync" +) + +// Ensure, that ImporterMock does implement Importer. +// If this is not the case, regenerate this file with moq. +var _ Importer = &ImporterMock{} + +// ImporterMock is a mock implementation of Importer. +// +// func TestSomethingThatUsesImporter(t *testing.T) { +// +// // make and configure a mocked Importer +// mockedImporter := &ImporterMock{ +// CleanUpFunc: func(ctx context.Context, sup *supplements.Generator) (bool, error) { +// panic("mock out the CleanUp method") +// }, +// GetPodFunc: func(ctx context.Context, sup *supplements.Generator) (*corev1.Pod, error) { +// panic("mock out the GetPod method") +// }, +// ProtectFunc: func(ctx context.Context, pod *corev1.Pod) error { +// panic("mock out the Protect method") +// }, +// StartFunc: func(ctx context.Context, settings *importer.Settings, obj service.ObjectKind, sup *supplements.Generator, caBundle *datasource.CABundle) error { +// panic("mock out the Start method") +// }, +// UnprotectFunc: func(ctx context.Context, pod *corev1.Pod) error { +// panic("mock out the Unprotect method") +// }, +// } +// +// // use mockedImporter in code that requires Importer +// // and then make assertions. +// +// } +type ImporterMock struct { + // CleanUpFunc mocks the CleanUp method. + CleanUpFunc func(ctx context.Context, sup *supplements.Generator) (bool, error) + + // GetPodFunc mocks the GetPod method. + GetPodFunc func(ctx context.Context, sup *supplements.Generator) (*corev1.Pod, error) + + // ProtectFunc mocks the Protect method. + ProtectFunc func(ctx context.Context, pod *corev1.Pod) error + + // StartFunc mocks the Start method. + StartFunc func(ctx context.Context, settings *importer.Settings, obj service.ObjectKind, sup *supplements.Generator, caBundle *datasource.CABundle) error + + // UnprotectFunc mocks the Unprotect method. + UnprotectFunc func(ctx context.Context, pod *corev1.Pod) error + + // calls tracks calls to the methods. + calls struct { + // CleanUp holds details about calls to the CleanUp method. + CleanUp []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Sup is the sup argument value. + Sup *supplements.Generator + } + // GetPod holds details about calls to the GetPod method. + GetPod []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Sup is the sup argument value. + Sup *supplements.Generator + } + // Protect holds details about calls to the Protect method. + Protect []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Pod is the pod argument value. + Pod *corev1.Pod + } + // Start holds details about calls to the Start method. + Start []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Settings is the settings argument value. + Settings *importer.Settings + // Obj is the obj argument value. + Obj service.ObjectKind + // Sup is the sup argument value. + Sup *supplements.Generator + // CaBundle is the caBundle argument value. + CaBundle *datasource.CABundle + } + // Unprotect holds details about calls to the Unprotect method. + Unprotect []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Pod is the pod argument value. + Pod *corev1.Pod + } + } + lockCleanUp sync.RWMutex + lockGetPod sync.RWMutex + lockProtect sync.RWMutex + lockStart sync.RWMutex + lockUnprotect sync.RWMutex +} + +// CleanUp calls CleanUpFunc. +func (mock *ImporterMock) CleanUp(ctx context.Context, sup *supplements.Generator) (bool, error) { + if mock.CleanUpFunc == nil { + panic("ImporterMock.CleanUpFunc: method is nil but Importer.CleanUp was just called") + } + callInfo := struct { + Ctx context.Context + Sup *supplements.Generator + }{ + Ctx: ctx, + Sup: sup, + } + mock.lockCleanUp.Lock() + mock.calls.CleanUp = append(mock.calls.CleanUp, callInfo) + mock.lockCleanUp.Unlock() + return mock.CleanUpFunc(ctx, sup) +} + +// CleanUpCalls gets all the calls that were made to CleanUp. +// Check the length with: +// +// len(mockedImporter.CleanUpCalls()) +func (mock *ImporterMock) CleanUpCalls() []struct { + Ctx context.Context + Sup *supplements.Generator +} { + var calls []struct { + Ctx context.Context + Sup *supplements.Generator + } + mock.lockCleanUp.RLock() + calls = mock.calls.CleanUp + mock.lockCleanUp.RUnlock() + return calls +} + +// GetPod calls GetPodFunc. +func (mock *ImporterMock) GetPod(ctx context.Context, sup *supplements.Generator) (*corev1.Pod, error) { + if mock.GetPodFunc == nil { + panic("ImporterMock.GetPodFunc: method is nil but Importer.GetPod was just called") + } + callInfo := struct { + Ctx context.Context + Sup *supplements.Generator + }{ + Ctx: ctx, + Sup: sup, + } + mock.lockGetPod.Lock() + mock.calls.GetPod = append(mock.calls.GetPod, callInfo) + mock.lockGetPod.Unlock() + return mock.GetPodFunc(ctx, sup) +} + +// GetPodCalls gets all the calls that were made to GetPod. +// Check the length with: +// +// len(mockedImporter.GetPodCalls()) +func (mock *ImporterMock) GetPodCalls() []struct { + Ctx context.Context + Sup *supplements.Generator +} { + var calls []struct { + Ctx context.Context + Sup *supplements.Generator + } + mock.lockGetPod.RLock() + calls = mock.calls.GetPod + mock.lockGetPod.RUnlock() + return calls +} + +// Protect calls ProtectFunc. +func (mock *ImporterMock) Protect(ctx context.Context, pod *corev1.Pod) error { + if mock.ProtectFunc == nil { + panic("ImporterMock.ProtectFunc: method is nil but Importer.Protect was just called") + } + callInfo := struct { + Ctx context.Context + Pod *corev1.Pod + }{ + Ctx: ctx, + Pod: pod, + } + mock.lockProtect.Lock() + mock.calls.Protect = append(mock.calls.Protect, callInfo) + mock.lockProtect.Unlock() + return mock.ProtectFunc(ctx, pod) +} + +// ProtectCalls gets all the calls that were made to Protect. +// Check the length with: +// +// len(mockedImporter.ProtectCalls()) +func (mock *ImporterMock) ProtectCalls() []struct { + Ctx context.Context + Pod *corev1.Pod +} { + var calls []struct { + Ctx context.Context + Pod *corev1.Pod + } + mock.lockProtect.RLock() + calls = mock.calls.Protect + mock.lockProtect.RUnlock() + return calls +} + +// Start calls StartFunc. +func (mock *ImporterMock) Start(ctx context.Context, settings *importer.Settings, obj service.ObjectKind, sup *supplements.Generator, caBundle *datasource.CABundle) error { + if mock.StartFunc == nil { + panic("ImporterMock.StartFunc: method is nil but Importer.Start was just called") + } + callInfo := struct { + Ctx context.Context + Settings *importer.Settings + Obj service.ObjectKind + Sup *supplements.Generator + CaBundle *datasource.CABundle + }{ + Ctx: ctx, + Settings: settings, + Obj: obj, + Sup: sup, + CaBundle: caBundle, + } + mock.lockStart.Lock() + mock.calls.Start = append(mock.calls.Start, callInfo) + mock.lockStart.Unlock() + return mock.StartFunc(ctx, settings, obj, sup, caBundle) +} + +// StartCalls gets all the calls that were made to Start. +// Check the length with: +// +// len(mockedImporter.StartCalls()) +func (mock *ImporterMock) StartCalls() []struct { + Ctx context.Context + Settings *importer.Settings + Obj service.ObjectKind + Sup *supplements.Generator + CaBundle *datasource.CABundle +} { + var calls []struct { + Ctx context.Context + Settings *importer.Settings + Obj service.ObjectKind + Sup *supplements.Generator + CaBundle *datasource.CABundle + } + mock.lockStart.RLock() + calls = mock.calls.Start + mock.lockStart.RUnlock() + return calls +} + +// Unprotect calls UnprotectFunc. +func (mock *ImporterMock) Unprotect(ctx context.Context, pod *corev1.Pod) error { + if mock.UnprotectFunc == nil { + panic("ImporterMock.UnprotectFunc: method is nil but Importer.Unprotect was just called") + } + callInfo := struct { + Ctx context.Context + Pod *corev1.Pod + }{ + Ctx: ctx, + Pod: pod, + } + mock.lockUnprotect.Lock() + mock.calls.Unprotect = append(mock.calls.Unprotect, callInfo) + mock.lockUnprotect.Unlock() + return mock.UnprotectFunc(ctx, pod) +} + +// UnprotectCalls gets all the calls that were made to Unprotect. +// Check the length with: +// +// len(mockedImporter.UnprotectCalls()) +func (mock *ImporterMock) UnprotectCalls() []struct { + Ctx context.Context + Pod *corev1.Pod +} { + var calls []struct { + Ctx context.Context + Pod *corev1.Pod + } + mock.lockUnprotect.RLock() + calls = mock.calls.Unprotect + mock.lockUnprotect.RUnlock() + return calls +} + +// Ensure, that UploaderMock does implement Uploader. +// If this is not the case, regenerate this file with moq. +var _ Uploader = &UploaderMock{} + +// UploaderMock is a mock implementation of Uploader. +// +// func TestSomethingThatUsesUploader(t *testing.T) { +// +// // make and configure a mocked Uploader +// mockedUploader := &UploaderMock{ +// CleanUpFunc: func(ctx context.Context, sup *supplements.Generator) (bool, error) { +// panic("mock out the CleanUp method") +// }, +// GetIngressFunc: func(ctx context.Context, sup *supplements.Generator) (*netv1.Ingress, error) { +// panic("mock out the GetIngress method") +// }, +// GetPodFunc: func(ctx context.Context, sup *supplements.Generator) (*corev1.Pod, error) { +// panic("mock out the GetPod method") +// }, +// GetServiceFunc: func(ctx context.Context, sup *supplements.Generator) (*corev1.Service, error) { +// panic("mock out the GetService method") +// }, +// ProtectFunc: func(ctx context.Context, pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) error { +// panic("mock out the Protect method") +// }, +// StartFunc: func(ctx context.Context, settings *uploader.Settings, obj service.ObjectKind, sup *supplements.Generator, caBundle *datasource.CABundle) error { +// panic("mock out the Start method") +// }, +// UnprotectFunc: func(ctx context.Context, pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) error { +// panic("mock out the Unprotect method") +// }, +// } +// +// // use mockedUploader in code that requires Uploader +// // and then make assertions. +// +// } +type UploaderMock struct { + // CleanUpFunc mocks the CleanUp method. + CleanUpFunc func(ctx context.Context, sup *supplements.Generator) (bool, error) + + // GetIngressFunc mocks the GetIngress method. + GetIngressFunc func(ctx context.Context, sup *supplements.Generator) (*netv1.Ingress, error) + + // GetPodFunc mocks the GetPod method. + GetPodFunc func(ctx context.Context, sup *supplements.Generator) (*corev1.Pod, error) + + // GetServiceFunc mocks the GetService method. + GetServiceFunc func(ctx context.Context, sup *supplements.Generator) (*corev1.Service, error) + + // ProtectFunc mocks the Protect method. + ProtectFunc func(ctx context.Context, pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) error + + // StartFunc mocks the Start method. + StartFunc func(ctx context.Context, settings *uploader.Settings, obj service.ObjectKind, sup *supplements.Generator, caBundle *datasource.CABundle) error + + // UnprotectFunc mocks the Unprotect method. + UnprotectFunc func(ctx context.Context, pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) error + + // calls tracks calls to the methods. + calls struct { + // CleanUp holds details about calls to the CleanUp method. + CleanUp []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Sup is the sup argument value. + Sup *supplements.Generator + } + // GetIngress holds details about calls to the GetIngress method. + GetIngress []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Sup is the sup argument value. + Sup *supplements.Generator + } + // GetPod holds details about calls to the GetPod method. + GetPod []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Sup is the sup argument value. + Sup *supplements.Generator + } + // GetService holds details about calls to the GetService method. + GetService []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Sup is the sup argument value. + Sup *supplements.Generator + } + // Protect holds details about calls to the Protect method. + Protect []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Pod is the pod argument value. + Pod *corev1.Pod + // Svc is the svc argument value. + Svc *corev1.Service + // Ing is the ing argument value. + Ing *netv1.Ingress + } + // Start holds details about calls to the Start method. + Start []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Settings is the settings argument value. + Settings *uploader.Settings + // Obj is the obj argument value. + Obj service.ObjectKind + // Sup is the sup argument value. + Sup *supplements.Generator + // CaBundle is the caBundle argument value. + CaBundle *datasource.CABundle + } + // Unprotect holds details about calls to the Unprotect method. + Unprotect []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Pod is the pod argument value. + Pod *corev1.Pod + // Svc is the svc argument value. + Svc *corev1.Service + // Ing is the ing argument value. + Ing *netv1.Ingress + } + } + lockCleanUp sync.RWMutex + lockGetIngress sync.RWMutex + lockGetPod sync.RWMutex + lockGetService sync.RWMutex + lockProtect sync.RWMutex + lockStart sync.RWMutex + lockUnprotect sync.RWMutex +} + +// CleanUp calls CleanUpFunc. +func (mock *UploaderMock) CleanUp(ctx context.Context, sup *supplements.Generator) (bool, error) { + if mock.CleanUpFunc == nil { + panic("UploaderMock.CleanUpFunc: method is nil but Uploader.CleanUp was just called") + } + callInfo := struct { + Ctx context.Context + Sup *supplements.Generator + }{ + Ctx: ctx, + Sup: sup, + } + mock.lockCleanUp.Lock() + mock.calls.CleanUp = append(mock.calls.CleanUp, callInfo) + mock.lockCleanUp.Unlock() + return mock.CleanUpFunc(ctx, sup) +} + +// CleanUpCalls gets all the calls that were made to CleanUp. +// Check the length with: +// +// len(mockedUploader.CleanUpCalls()) +func (mock *UploaderMock) CleanUpCalls() []struct { + Ctx context.Context + Sup *supplements.Generator +} { + var calls []struct { + Ctx context.Context + Sup *supplements.Generator + } + mock.lockCleanUp.RLock() + calls = mock.calls.CleanUp + mock.lockCleanUp.RUnlock() + return calls +} + +// GetIngress calls GetIngressFunc. +func (mock *UploaderMock) GetIngress(ctx context.Context, sup *supplements.Generator) (*netv1.Ingress, error) { + if mock.GetIngressFunc == nil { + panic("UploaderMock.GetIngressFunc: method is nil but Uploader.GetIngress was just called") + } + callInfo := struct { + Ctx context.Context + Sup *supplements.Generator + }{ + Ctx: ctx, + Sup: sup, + } + mock.lockGetIngress.Lock() + mock.calls.GetIngress = append(mock.calls.GetIngress, callInfo) + mock.lockGetIngress.Unlock() + return mock.GetIngressFunc(ctx, sup) +} + +// GetIngressCalls gets all the calls that were made to GetIngress. +// Check the length with: +// +// len(mockedUploader.GetIngressCalls()) +func (mock *UploaderMock) GetIngressCalls() []struct { + Ctx context.Context + Sup *supplements.Generator +} { + var calls []struct { + Ctx context.Context + Sup *supplements.Generator + } + mock.lockGetIngress.RLock() + calls = mock.calls.GetIngress + mock.lockGetIngress.RUnlock() + return calls +} + +// GetPod calls GetPodFunc. +func (mock *UploaderMock) GetPod(ctx context.Context, sup *supplements.Generator) (*corev1.Pod, error) { + if mock.GetPodFunc == nil { + panic("UploaderMock.GetPodFunc: method is nil but Uploader.GetPod was just called") + } + callInfo := struct { + Ctx context.Context + Sup *supplements.Generator + }{ + Ctx: ctx, + Sup: sup, + } + mock.lockGetPod.Lock() + mock.calls.GetPod = append(mock.calls.GetPod, callInfo) + mock.lockGetPod.Unlock() + return mock.GetPodFunc(ctx, sup) +} + +// GetPodCalls gets all the calls that were made to GetPod. +// Check the length with: +// +// len(mockedUploader.GetPodCalls()) +func (mock *UploaderMock) GetPodCalls() []struct { + Ctx context.Context + Sup *supplements.Generator +} { + var calls []struct { + Ctx context.Context + Sup *supplements.Generator + } + mock.lockGetPod.RLock() + calls = mock.calls.GetPod + mock.lockGetPod.RUnlock() + return calls +} + +// GetService calls GetServiceFunc. +func (mock *UploaderMock) GetService(ctx context.Context, sup *supplements.Generator) (*corev1.Service, error) { + if mock.GetServiceFunc == nil { + panic("UploaderMock.GetServiceFunc: method is nil but Uploader.GetService was just called") + } + callInfo := struct { + Ctx context.Context + Sup *supplements.Generator + }{ + Ctx: ctx, + Sup: sup, + } + mock.lockGetService.Lock() + mock.calls.GetService = append(mock.calls.GetService, callInfo) + mock.lockGetService.Unlock() + return mock.GetServiceFunc(ctx, sup) +} + +// GetServiceCalls gets all the calls that were made to GetService. +// Check the length with: +// +// len(mockedUploader.GetServiceCalls()) +func (mock *UploaderMock) GetServiceCalls() []struct { + Ctx context.Context + Sup *supplements.Generator +} { + var calls []struct { + Ctx context.Context + Sup *supplements.Generator + } + mock.lockGetService.RLock() + calls = mock.calls.GetService + mock.lockGetService.RUnlock() + return calls +} + +// Protect calls ProtectFunc. +func (mock *UploaderMock) Protect(ctx context.Context, pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) error { + if mock.ProtectFunc == nil { + panic("UploaderMock.ProtectFunc: method is nil but Uploader.Protect was just called") + } + callInfo := struct { + Ctx context.Context + Pod *corev1.Pod + Svc *corev1.Service + Ing *netv1.Ingress + }{ + Ctx: ctx, + Pod: pod, + Svc: svc, + Ing: ing, + } + mock.lockProtect.Lock() + mock.calls.Protect = append(mock.calls.Protect, callInfo) + mock.lockProtect.Unlock() + return mock.ProtectFunc(ctx, pod, svc, ing) +} + +// ProtectCalls gets all the calls that were made to Protect. +// Check the length with: +// +// len(mockedUploader.ProtectCalls()) +func (mock *UploaderMock) ProtectCalls() []struct { + Ctx context.Context + Pod *corev1.Pod + Svc *corev1.Service + Ing *netv1.Ingress +} { + var calls []struct { + Ctx context.Context + Pod *corev1.Pod + Svc *corev1.Service + Ing *netv1.Ingress + } + mock.lockProtect.RLock() + calls = mock.calls.Protect + mock.lockProtect.RUnlock() + return calls +} + +// Start calls StartFunc. +func (mock *UploaderMock) Start(ctx context.Context, settings *uploader.Settings, obj service.ObjectKind, sup *supplements.Generator, caBundle *datasource.CABundle) error { + if mock.StartFunc == nil { + panic("UploaderMock.StartFunc: method is nil but Uploader.Start was just called") + } + callInfo := struct { + Ctx context.Context + Settings *uploader.Settings + Obj service.ObjectKind + Sup *supplements.Generator + CaBundle *datasource.CABundle + }{ + Ctx: ctx, + Settings: settings, + Obj: obj, + Sup: sup, + CaBundle: caBundle, + } + mock.lockStart.Lock() + mock.calls.Start = append(mock.calls.Start, callInfo) + mock.lockStart.Unlock() + return mock.StartFunc(ctx, settings, obj, sup, caBundle) +} + +// StartCalls gets all the calls that were made to Start. +// Check the length with: +// +// len(mockedUploader.StartCalls()) +func (mock *UploaderMock) StartCalls() []struct { + Ctx context.Context + Settings *uploader.Settings + Obj service.ObjectKind + Sup *supplements.Generator + CaBundle *datasource.CABundle +} { + var calls []struct { + Ctx context.Context + Settings *uploader.Settings + Obj service.ObjectKind + Sup *supplements.Generator + CaBundle *datasource.CABundle + } + mock.lockStart.RLock() + calls = mock.calls.Start + mock.lockStart.RUnlock() + return calls +} + +// Unprotect calls UnprotectFunc. +func (mock *UploaderMock) Unprotect(ctx context.Context, pod *corev1.Pod, svc *corev1.Service, ing *netv1.Ingress) error { + if mock.UnprotectFunc == nil { + panic("UploaderMock.UnprotectFunc: method is nil but Uploader.Unprotect was just called") + } + callInfo := struct { + Ctx context.Context + Pod *corev1.Pod + Svc *corev1.Service + Ing *netv1.Ingress + }{ + Ctx: ctx, + Pod: pod, + Svc: svc, + Ing: ing, + } + mock.lockUnprotect.Lock() + mock.calls.Unprotect = append(mock.calls.Unprotect, callInfo) + mock.lockUnprotect.Unlock() + return mock.UnprotectFunc(ctx, pod, svc, ing) +} + +// UnprotectCalls gets all the calls that were made to Unprotect. +// Check the length with: +// +// len(mockedUploader.UnprotectCalls()) +func (mock *UploaderMock) UnprotectCalls() []struct { + Ctx context.Context + Pod *corev1.Pod + Svc *corev1.Service + Ing *netv1.Ingress +} { + var calls []struct { + Ctx context.Context + Pod *corev1.Pod + Svc *corev1.Service + Ing *netv1.Ingress + } + mock.lockUnprotect.RLock() + calls = mock.calls.Unprotect + mock.lockUnprotect.RUnlock() + return calls +} + +// Ensure, that StatMock does implement Stat. +// If this is not the case, regenerate this file with moq. +var _ Stat = &StatMock{} + +// StatMock is a mock implementation of Stat. +// +// func TestSomethingThatUsesStat(t *testing.T) { +// +// // make and configure a mocked Stat +// mockedStat := &StatMock{ +// CheckPodFunc: func(pod *corev1.Pod) error { +// panic("mock out the CheckPod method") +// }, +// GetCDROMFunc: func(pod *corev1.Pod) bool { +// panic("mock out the GetCDROM method") +// }, +// GetDVCRImageNameFunc: func(pod *corev1.Pod) string { +// panic("mock out the GetDVCRImageName method") +// }, +// GetDownloadSpeedFunc: func(ownerUID types.UID, pod *corev1.Pod) *virtv2.StatusSpeed { +// panic("mock out the GetDownloadSpeed method") +// }, +// GetFormatFunc: func(pod *corev1.Pod) string { +// panic("mock out the GetFormat method") +// }, +// GetProgressFunc: func(ownerUID types.UID, pod *corev1.Pod, prevProgress string, opts ...service.GetProgressOption) string { +// panic("mock out the GetProgress method") +// }, +// GetSizeFunc: func(pod *corev1.Pod) virtv2.ImageStatusSize { +// panic("mock out the GetSize method") +// }, +// IsUploadStartedFunc: func(ownerUID types.UID, pod *corev1.Pod) bool { +// panic("mock out the IsUploadStarted method") +// }, +// } +// +// // use mockedStat in code that requires Stat +// // and then make assertions. +// +// } +type StatMock struct { + // CheckPodFunc mocks the CheckPod method. + CheckPodFunc func(pod *corev1.Pod) error + + // GetCDROMFunc mocks the GetCDROM method. + GetCDROMFunc func(pod *corev1.Pod) bool + + // GetDVCRImageNameFunc mocks the GetDVCRImageName method. + GetDVCRImageNameFunc func(pod *corev1.Pod) string + + // GetDownloadSpeedFunc mocks the GetDownloadSpeed method. + GetDownloadSpeedFunc func(ownerUID types.UID, pod *corev1.Pod) *virtv2.StatusSpeed + + // GetFormatFunc mocks the GetFormat method. + GetFormatFunc func(pod *corev1.Pod) string + + // GetProgressFunc mocks the GetProgress method. + GetProgressFunc func(ownerUID types.UID, pod *corev1.Pod, prevProgress string, opts ...service.GetProgressOption) string + + // GetSizeFunc mocks the GetSize method. + GetSizeFunc func(pod *corev1.Pod) virtv2.ImageStatusSize + + // IsUploadStartedFunc mocks the IsUploadStarted method. + IsUploadStartedFunc func(ownerUID types.UID, pod *corev1.Pod) bool + + // calls tracks calls to the methods. + calls struct { + // CheckPod holds details about calls to the CheckPod method. + CheckPod []struct { + // Pod is the pod argument value. + Pod *corev1.Pod + } + // GetCDROM holds details about calls to the GetCDROM method. + GetCDROM []struct { + // Pod is the pod argument value. + Pod *corev1.Pod + } + // GetDVCRImageName holds details about calls to the GetDVCRImageName method. + GetDVCRImageName []struct { + // Pod is the pod argument value. + Pod *corev1.Pod + } + // GetDownloadSpeed holds details about calls to the GetDownloadSpeed method. + GetDownloadSpeed []struct { + // OwnerUID is the ownerUID argument value. + OwnerUID types.UID + // Pod is the pod argument value. + Pod *corev1.Pod + } + // GetFormat holds details about calls to the GetFormat method. + GetFormat []struct { + // Pod is the pod argument value. + Pod *corev1.Pod + } + // GetProgress holds details about calls to the GetProgress method. + GetProgress []struct { + // OwnerUID is the ownerUID argument value. + OwnerUID types.UID + // Pod is the pod argument value. + Pod *corev1.Pod + // PrevProgress is the prevProgress argument value. + PrevProgress string + // Opts is the opts argument value. + Opts []service.GetProgressOption + } + // GetSize holds details about calls to the GetSize method. + GetSize []struct { + // Pod is the pod argument value. + Pod *corev1.Pod + } + // IsUploadStarted holds details about calls to the IsUploadStarted method. + IsUploadStarted []struct { + // OwnerUID is the ownerUID argument value. + OwnerUID types.UID + // Pod is the pod argument value. + Pod *corev1.Pod + } + } + lockCheckPod sync.RWMutex + lockGetCDROM sync.RWMutex + lockGetDVCRImageName sync.RWMutex + lockGetDownloadSpeed sync.RWMutex + lockGetFormat sync.RWMutex + lockGetProgress sync.RWMutex + lockGetSize sync.RWMutex + lockIsUploadStarted sync.RWMutex +} + +// CheckPod calls CheckPodFunc. +func (mock *StatMock) CheckPod(pod *corev1.Pod) error { + if mock.CheckPodFunc == nil { + panic("StatMock.CheckPodFunc: method is nil but Stat.CheckPod was just called") + } + callInfo := struct { + Pod *corev1.Pod + }{ + Pod: pod, + } + mock.lockCheckPod.Lock() + mock.calls.CheckPod = append(mock.calls.CheckPod, callInfo) + mock.lockCheckPod.Unlock() + return mock.CheckPodFunc(pod) +} + +// CheckPodCalls gets all the calls that were made to CheckPod. +// Check the length with: +// +// len(mockedStat.CheckPodCalls()) +func (mock *StatMock) CheckPodCalls() []struct { + Pod *corev1.Pod +} { + var calls []struct { + Pod *corev1.Pod + } + mock.lockCheckPod.RLock() + calls = mock.calls.CheckPod + mock.lockCheckPod.RUnlock() + return calls +} + +// GetCDROM calls GetCDROMFunc. +func (mock *StatMock) GetCDROM(pod *corev1.Pod) bool { + if mock.GetCDROMFunc == nil { + panic("StatMock.GetCDROMFunc: method is nil but Stat.GetCDROM was just called") + } + callInfo := struct { + Pod *corev1.Pod + }{ + Pod: pod, + } + mock.lockGetCDROM.Lock() + mock.calls.GetCDROM = append(mock.calls.GetCDROM, callInfo) + mock.lockGetCDROM.Unlock() + return mock.GetCDROMFunc(pod) +} + +// GetCDROMCalls gets all the calls that were made to GetCDROM. +// Check the length with: +// +// len(mockedStat.GetCDROMCalls()) +func (mock *StatMock) GetCDROMCalls() []struct { + Pod *corev1.Pod +} { + var calls []struct { + Pod *corev1.Pod + } + mock.lockGetCDROM.RLock() + calls = mock.calls.GetCDROM + mock.lockGetCDROM.RUnlock() + return calls +} + +// GetDVCRImageName calls GetDVCRImageNameFunc. +func (mock *StatMock) GetDVCRImageName(pod *corev1.Pod) string { + if mock.GetDVCRImageNameFunc == nil { + panic("StatMock.GetDVCRImageNameFunc: method is nil but Stat.GetDVCRImageName was just called") + } + callInfo := struct { + Pod *corev1.Pod + }{ + Pod: pod, + } + mock.lockGetDVCRImageName.Lock() + mock.calls.GetDVCRImageName = append(mock.calls.GetDVCRImageName, callInfo) + mock.lockGetDVCRImageName.Unlock() + return mock.GetDVCRImageNameFunc(pod) +} + +// GetDVCRImageNameCalls gets all the calls that were made to GetDVCRImageName. +// Check the length with: +// +// len(mockedStat.GetDVCRImageNameCalls()) +func (mock *StatMock) GetDVCRImageNameCalls() []struct { + Pod *corev1.Pod +} { + var calls []struct { + Pod *corev1.Pod + } + mock.lockGetDVCRImageName.RLock() + calls = mock.calls.GetDVCRImageName + mock.lockGetDVCRImageName.RUnlock() + return calls +} + +// GetDownloadSpeed calls GetDownloadSpeedFunc. +func (mock *StatMock) GetDownloadSpeed(ownerUID types.UID, pod *corev1.Pod) *virtv2.StatusSpeed { + if mock.GetDownloadSpeedFunc == nil { + panic("StatMock.GetDownloadSpeedFunc: method is nil but Stat.GetDownloadSpeed was just called") + } + callInfo := struct { + OwnerUID types.UID + Pod *corev1.Pod + }{ + OwnerUID: ownerUID, + Pod: pod, + } + mock.lockGetDownloadSpeed.Lock() + mock.calls.GetDownloadSpeed = append(mock.calls.GetDownloadSpeed, callInfo) + mock.lockGetDownloadSpeed.Unlock() + return mock.GetDownloadSpeedFunc(ownerUID, pod) +} + +// GetDownloadSpeedCalls gets all the calls that were made to GetDownloadSpeed. +// Check the length with: +// +// len(mockedStat.GetDownloadSpeedCalls()) +func (mock *StatMock) GetDownloadSpeedCalls() []struct { + OwnerUID types.UID + Pod *corev1.Pod +} { + var calls []struct { + OwnerUID types.UID + Pod *corev1.Pod + } + mock.lockGetDownloadSpeed.RLock() + calls = mock.calls.GetDownloadSpeed + mock.lockGetDownloadSpeed.RUnlock() + return calls +} + +// GetFormat calls GetFormatFunc. +func (mock *StatMock) GetFormat(pod *corev1.Pod) string { + if mock.GetFormatFunc == nil { + panic("StatMock.GetFormatFunc: method is nil but Stat.GetFormat was just called") + } + callInfo := struct { + Pod *corev1.Pod + }{ + Pod: pod, + } + mock.lockGetFormat.Lock() + mock.calls.GetFormat = append(mock.calls.GetFormat, callInfo) + mock.lockGetFormat.Unlock() + return mock.GetFormatFunc(pod) +} + +// GetFormatCalls gets all the calls that were made to GetFormat. +// Check the length with: +// +// len(mockedStat.GetFormatCalls()) +func (mock *StatMock) GetFormatCalls() []struct { + Pod *corev1.Pod +} { + var calls []struct { + Pod *corev1.Pod + } + mock.lockGetFormat.RLock() + calls = mock.calls.GetFormat + mock.lockGetFormat.RUnlock() + return calls +} + +// GetProgress calls GetProgressFunc. +func (mock *StatMock) GetProgress(ownerUID types.UID, pod *corev1.Pod, prevProgress string, opts ...service.GetProgressOption) string { + if mock.GetProgressFunc == nil { + panic("StatMock.GetProgressFunc: method is nil but Stat.GetProgress was just called") + } + callInfo := struct { + OwnerUID types.UID + Pod *corev1.Pod + PrevProgress string + Opts []service.GetProgressOption + }{ + OwnerUID: ownerUID, + Pod: pod, + PrevProgress: prevProgress, + Opts: opts, + } + mock.lockGetProgress.Lock() + mock.calls.GetProgress = append(mock.calls.GetProgress, callInfo) + mock.lockGetProgress.Unlock() + return mock.GetProgressFunc(ownerUID, pod, prevProgress, opts...) +} + +// GetProgressCalls gets all the calls that were made to GetProgress. +// Check the length with: +// +// len(mockedStat.GetProgressCalls()) +func (mock *StatMock) GetProgressCalls() []struct { + OwnerUID types.UID + Pod *corev1.Pod + PrevProgress string + Opts []service.GetProgressOption +} { + var calls []struct { + OwnerUID types.UID + Pod *corev1.Pod + PrevProgress string + Opts []service.GetProgressOption + } + mock.lockGetProgress.RLock() + calls = mock.calls.GetProgress + mock.lockGetProgress.RUnlock() + return calls +} + +// GetSize calls GetSizeFunc. +func (mock *StatMock) GetSize(pod *corev1.Pod) virtv2.ImageStatusSize { + if mock.GetSizeFunc == nil { + panic("StatMock.GetSizeFunc: method is nil but Stat.GetSize was just called") + } + callInfo := struct { + Pod *corev1.Pod + }{ + Pod: pod, + } + mock.lockGetSize.Lock() + mock.calls.GetSize = append(mock.calls.GetSize, callInfo) + mock.lockGetSize.Unlock() + return mock.GetSizeFunc(pod) +} + +// GetSizeCalls gets all the calls that were made to GetSize. +// Check the length with: +// +// len(mockedStat.GetSizeCalls()) +func (mock *StatMock) GetSizeCalls() []struct { + Pod *corev1.Pod +} { + var calls []struct { + Pod *corev1.Pod + } + mock.lockGetSize.RLock() + calls = mock.calls.GetSize + mock.lockGetSize.RUnlock() + return calls +} + +// IsUploadStarted calls IsUploadStartedFunc. +func (mock *StatMock) IsUploadStarted(ownerUID types.UID, pod *corev1.Pod) bool { + if mock.IsUploadStartedFunc == nil { + panic("StatMock.IsUploadStartedFunc: method is nil but Stat.IsUploadStarted was just called") + } + callInfo := struct { + OwnerUID types.UID + Pod *corev1.Pod + }{ + OwnerUID: ownerUID, + Pod: pod, + } + mock.lockIsUploadStarted.Lock() + mock.calls.IsUploadStarted = append(mock.calls.IsUploadStarted, callInfo) + mock.lockIsUploadStarted.Unlock() + return mock.IsUploadStartedFunc(ownerUID, pod) +} + +// IsUploadStartedCalls gets all the calls that were made to IsUploadStarted. +// Check the length with: +// +// len(mockedStat.IsUploadStartedCalls()) +func (mock *StatMock) IsUploadStartedCalls() []struct { + OwnerUID types.UID + Pod *corev1.Pod +} { + var calls []struct { + OwnerUID types.UID + Pod *corev1.Pod + } + mock.lockIsUploadStarted.RLock() + calls = mock.calls.IsUploadStarted + mock.lockIsUploadStarted.RUnlock() + return calls +} diff --git a/images/virtualization-artifact/pkg/controller/vi/internal/source/object_ref.go b/images/virtualization-artifact/pkg/controller/vi/internal/source/object_ref.go index ba3008e71..cf1d4536f 100644 --- a/images/virtualization-artifact/pkg/controller/vi/internal/source/object_ref.go +++ b/images/virtualization-artifact/pkg/controller/vi/internal/source/object_ref.go @@ -110,7 +110,6 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) return false, err } - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) vi.Status.SourceUID = util.GetPointer(dvcrDataSource.GetUID()) log.Info("Ready", "progress", vi.Status.Progress, "pod.phase", "nil") @@ -154,7 +153,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) vi.Status.CDROM = dvcrDataSource.IsCDROM() vi.Status.Format = dvcrDataSource.GetFormat() vi.Status.Progress = "100%" - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("Ready", "progress", vi.Status.Progress, "pod.phase", pod.Status.Phase) default: @@ -183,7 +182,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) condition.Message = "Import is in the process of provisioning to DVCR." vi.Status.Phase = virtv2.ImageProvisioning - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("Ready", "progress", vi.Status.Progress, "pod.phase", pod.Status.Phase) } @@ -237,7 +236,7 @@ func (ds ObjectRefDataSource) getEnvSettings(vi *virtv2.VirtualImage, sup *suppl &settings, ds.dvcrSettings, sup, - ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace), + ds.dvcrSettings.RegistryImageForVI(vi), ) return &settings, nil diff --git a/images/virtualization-artifact/pkg/controller/vi/internal/source/registry.go b/images/virtualization-artifact/pkg/controller/vi/internal/source/registry.go index a25b883cc..6172ee7b3 100644 --- a/images/virtualization-artifact/pkg/controller/vi/internal/source/registry.go +++ b/images/virtualization-artifact/pkg/controller/vi/internal/source/registry.go @@ -101,7 +101,6 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) } vi.Status.Progress = "0%" - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) log.Info("Create importer pod...", "progress", vi.Status.Progress, "pod.phase", "nil") @@ -131,7 +130,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) vi.Status.CDROM = ds.statService.GetCDROM(pod) vi.Status.Format = ds.statService.GetFormat(pod) vi.Status.Progress = "100%" - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("Ready", "progress", vi.Status.Progress, "pod.phase", pod.Status.Phase) default: @@ -161,7 +160,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) vi.Status.Phase = virtv2.ImageProvisioning vi.Status.Progress = "0%" - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("Provisioning...", "progress", vi.Status.Progress, "pod.phase", pod.Status.Phase) } @@ -207,7 +206,7 @@ func (ds RegistryDataSource) getEnvSettings(vi *virtv2.VirtualImage, supgen *sup &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace), + ds.dvcrSettings.RegistryImageForVI(vi), ) return &settings diff --git a/images/virtualization-artifact/pkg/controller/vi/internal/source/upload.go b/images/virtualization-artifact/pkg/controller/vi/internal/source/upload.go index fe1827110..b82b52ff2 100644 --- a/images/virtualization-artifact/pkg/controller/vi/internal/source/upload.go +++ b/images/virtualization-artifact/pkg/controller/vi/internal/source/upload.go @@ -99,7 +99,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (b log.Info("Cleaning up...") case pod == nil || svc == nil || ing == nil: - envSettings := ds.getEnvSettings(supgen) + envSettings := ds.getEnvSettings(vi, supgen) err = ds.uploaderService.Start(ctx, envSettings, vi, supgen, datasource.NewCABundleForVMI(vi.Spec.DataSource)) var requeue bool requeue, err = setPhaseConditionForUploaderStart(&condition, &vi.Status.Phase, err) @@ -107,8 +107,6 @@ func (ds UploadDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (b return false, err } - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) - log.Info("Create uploader pod...", "progress", vi.Status.Progress, "pod.phase", nil) return requeue, nil @@ -137,7 +135,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (b vi.Status.CDROM = ds.statService.GetCDROM(pod) vi.Status.Format = ds.statService.GetFormat(pod) vi.Status.Progress = "100%" - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) vi.Status.DownloadSpeed = ds.statService.GetDownloadSpeed(vi.GetUID(), pod) log.Info("Ready", "progress", vi.Status.Progress, "pod.phase", pod.Status.Phase) @@ -168,7 +166,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (b vi.Status.Phase = virtv2.ImageProvisioning vi.Status.Progress = ds.statService.GetProgress(vi.GetUID(), pod, vi.Status.Progress) - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) vi.Status.DownloadSpeed = ds.statService.GetDownloadSpeed(vi.GetUID(), pod) err = ds.uploaderService.Protect(ctx, pod, svc, ing) @@ -183,7 +181,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (b condition.Message = "Waiting for the user upload." vi.Status.Phase = virtv2.ImageWaitForUserUpload - vi.Status.Target.RegistryURL = ds.dvcrSettings.RegistryImageForVMI(vi.Name, vi.Namespace) + vi.Status.Target.RegistryURL = ds.statService.GetDVCRImageName(pod) log.Info("WaitForUserUpload...", "progress", vi.Status.Progress, "pod.phase", pod.Status.Phase) } @@ -206,14 +204,14 @@ func (ds UploadDataSource) Validate(_ context.Context, _ *virtv2.VirtualImage) e return nil } -func (ds UploadDataSource) getEnvSettings(supgen *supplements.Generator) *uploader.Settings { +func (ds UploadDataSource) getEnvSettings(vi *virtv2.VirtualImage, supgen *supplements.Generator) *uploader.Settings { var settings uploader.Settings uploader.ApplyDVCRDestinationSettings( &settings, ds.dvcrSettings, supgen, - ds.dvcrSettings.RegistryImageForVMI(supgen.Name, supgen.Namespace), + ds.dvcrSettings.RegistryImageForVI(vi), ) return &settings diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go b/images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go index 738147bee..3b4794640 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go @@ -358,7 +358,7 @@ func (h *SyncKvvmHandler) makeKVVMFromVMSpec(ctx context.Context, s state.Virtua } // Create kubevirt VirtualMachine resource from d8 VirtualMachine spec. - err = kvbuilder.ApplyVirtualMachineSpec(kvvmBuilder, current, bdState.VDByName, bdState.VIByName, bdState.CVIByName, h.dvcrSettings, class, ip.Status.Address) + err = kvbuilder.ApplyVirtualMachineSpec(kvvmBuilder, current, bdState.VDByName, bdState.VIByName, bdState.CVIByName, class, ip.Status.Address) if err != nil { return nil, err } diff --git a/images/virtualization-artifact/pkg/dvcr/dvcr.go b/images/virtualization-artifact/pkg/dvcr/dvcr.go index 79c99539a..503df7c24 100644 --- a/images/virtualization-artifact/pkg/dvcr/dvcr.go +++ b/images/virtualization-artifact/pkg/dvcr/dvcr.go @@ -19,6 +19,8 @@ package dvcr import ( "fmt" "path" + + "sigs.k8s.io/controller-runtime/pkg/client" ) type Settings struct { @@ -46,25 +48,25 @@ type UploaderIngressSettings struct { } const ( - CVMIImageTmpl = "cvi/%s" - VMIImageTmpl = "vi/%s/%s" - VMDImageTmpl = "vd/%s/%s" + CVMIImageTmpl = "cvi/%s:%s" + VMIImageTmpl = "vi/%s/%s:%s" + VMDImageTmpl = "vd/%s/%s:%s" ) -// RegistryImageForCVMI returns image name for CVMI. -func (s *Settings) RegistryImageForCVMI(name string) string { - imgPath := path.Clean(fmt.Sprintf(CVMIImageTmpl, name)) +// RegistryImageForCVI returns image name for CVI. +func (s *Settings) RegistryImageForCVI(obj client.Object) string { + imgPath := path.Clean(fmt.Sprintf(CVMIImageTmpl, obj.GetName(), obj.GetUID())) return path.Join(s.RegistryURL, imgPath) } -// RegistryImageForVMI returns image name for VMI. -func (s *Settings) RegistryImageForVMI(name, namespace string) string { - imgPath := path.Clean(fmt.Sprintf(VMIImageTmpl, namespace, name)) +// RegistryImageForVI returns image name for VI. +func (s *Settings) RegistryImageForVI(obj client.Object) string { + imgPath := path.Clean(fmt.Sprintf(VMIImageTmpl, obj.GetNamespace(), obj.GetName(), obj.GetUID())) return path.Join(s.RegistryURL, imgPath) } -// RegistryImageForVMD returns image name for VMD. -func (s *Settings) RegistryImageForVMD(name, namespace string) string { - imgPath := path.Clean(fmt.Sprintf(VMDImageTmpl, namespace, name)) +// RegistryImageForVD returns image name for VD. +func (s *Settings) RegistryImageForVD(obj client.Object) string { + imgPath := path.Clean(fmt.Sprintf(VMDImageTmpl, obj.GetNamespace(), obj.GetName(), obj.GetUID())) return path.Join(s.RegistryURL, imgPath) }