Skip to content

Commit

Permalink
Addressed review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Wels <[email protected]>
  • Loading branch information
awels committed May 27, 2022
1 parent dd519a7 commit 373bff1
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 203 deletions.
16 changes: 16 additions & 0 deletions pkg/controller/virtinformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ type KubeInformerFactory interface {
// Watches for the kubevirt export CA config map
KubeVirtExportCAConfigMap() cache.SharedIndexInformer

// Watches for the kubevirt export CA config map
ExportService() cache.SharedIndexInformer

// ConfigMaps which are managed by the operator
OperatorConfigMap() cache.SharedIndexInformer

Expand Down Expand Up @@ -739,6 +742,19 @@ func (f *kubeInformerFactory) KubeVirtExportCAConfigMap() cache.SharedIndexInfor
})
}

func (f *kubeInformerFactory) ExportService() cache.SharedIndexInformer {
return f.getInformer("exportService", func() cache.SharedIndexInformer {
// Watch all service with the kubevirt app label
labelSelector, err := labels.Parse(fmt.Sprintf("%s=%s", kubev1.AppLabel, exportv1.App))
if err != nil {
panic(err)
}

lw := NewListWatchFromClient(f.clientSet.CoreV1().RESTClient(), "services", k8sv1.NamespaceAll, fields.Everything(), labelSelector)
return cache.NewSharedIndexInformer(lw, &k8sv1.Service{}, f.defaultResync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
})
}

func (f *kubeInformerFactory) PersistentVolumeClaim() cache.SharedIndexInformer {
return f.getInformer("persistentVolumeClaimInformer", func() cache.SharedIndexInformer {
restClient := f.clientSet.CoreV1().RESTClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,6 @@ func (admitter *VMExportAdmitter) Admit(ar *admissionv1.AdmissionReview) *admiss
},
}
}
// case virtv1.SchemeGroupVersion.Group:
// switch vmExport.Spec.Source.Kind {
// case "VirtualMachine":
// causes, err = admitter.validateVM(sourceField.Child("name"), ar.Request.Namespace, vmExport.Spec.Source.Name)
// if err != nil {
// return webhookutils.ToAdmissionResponseError(err)
// }
// default:
// causes = []metav1.StatusCause{
// {
// Type: metav1.CauseTypeFieldValueInvalid,
// Message: "invalid kind",
// Field: sourceField.Child("kind").String(),
// },
// }
// }

default:
causes = []metav1.StatusCause{
{
Expand Down Expand Up @@ -169,17 +152,3 @@ func (admitter *VMExportAdmitter) validatePVC(field *k8sfield.Path, namespace, n

return []metav1.StatusCause{}, nil
}

// func (admitter *VMExportAdmitter) validateVM(field *k8sfield.Path, namespace, name string) ([]metav1.StatusCause, error) {
// if name == "" {
// return []metav1.StatusCause{
// {
// Type: metav1.CauseTypeFieldValueInvalid,
// Message: "VM name must not be empty",
// Field: field.String(),
// },
// }, nil
// }

// return []metav1.StatusCause{}, nil
// }
4 changes: 4 additions & 0 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const (
varRun = "/var/run"
virtBinDir = "virt-bin-share-dir"
hotplugDisk = "hotplug-disk"
virtExporter = "virt-exporter"
)

const KvmDevice = "devices.kubevirt.io/kvm"
Expand Down Expand Up @@ -1769,6 +1770,9 @@ func (t *templateService) RenderExporterManifest(vmExport *exportv1.VirtualMachi
Kind: "VirtualMachineExport",
}),
},
Labels: map[string]string{
v1.AppLabel: virtExporter,
},
},
Spec: k8sv1.PodSpec{
RestartPolicy: k8sv1.RestartPolicyNever,
Expand Down
5 changes: 4 additions & 1 deletion pkg/virt-controller/watch/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const (
defaultHost = "0.0.0.0"

launcherImage = "virt-launcher"
exporterImage = "virt-exporter"
exporterImage = "virt-exportserver"
launcherQemuTimeout = 240

imagePullSecret = ""
Expand Down Expand Up @@ -174,6 +174,7 @@ type VirtControllerApp struct {
workloadUpdateController *workloadupdater.WorkloadUpdateController

caExportConfigMapInformer cache.SharedIndexInformer
exportServiceInformer cache.SharedIndexInformer
exportController *export.VMExportController
snapshotController *snapshot.VMSnapshotController
restoreController *snapshot.VMRestoreController
Expand Down Expand Up @@ -354,6 +355,7 @@ func Execute() {
app.storageClassInformer = app.informerFactory.StorageClass()
app.caExportConfigMapInformer = app.informerFactory.KubeVirtExportCAConfigMap()
app.allPodInformer = app.informerFactory.Pod()
app.exportServiceInformer = app.informerFactory.ExportService()

if app.hasCDI {
app.dataVolumeInformer = app.informerFactory.DataVolume()
Expand Down Expand Up @@ -670,6 +672,7 @@ func (vca *VirtControllerApp) initExportController() {
PVCInformer: vca.persistentVolumeClaimInformer,
PodInformer: vca.allPodInformer,
VMInformer: vca.vmInformer,
ServiceInformer: vca.exportServiceInformer,
Recorder: recorder,
ResyncPeriod: vca.snapshotControllerResyncPeriod,
ConfigMapInformer: vca.caExportConfigMapInformer,
Expand Down
2 changes: 2 additions & 0 deletions pkg/virt-controller/watch/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var _ = Describe("Application", func() {
configMapInformer, _ := testutils.NewFakeInformerFor(&kubev1.ConfigMap{})
dvInformer, _ := testutils.NewFakeInformerFor(&cdiv1.DataVolume{})
flavorMethods := testutils.NewMockFlavorMethods()
exportServiceInformer, _ := testutils.NewFakeInformerFor(&k8sv1.Service{})

var qemuGid int64 = 107

Expand Down Expand Up @@ -184,6 +185,7 @@ var _ = Describe("Application", func() {
PVCInformer: pvcInformer,
PodInformer: podInformer,
VMInformer: vmInformer,
ServiceInformer: exportServiceInformer,
ConfigMapInformer: configMapInformer,
Recorder: recorder,
}
Expand Down
Loading

0 comments on commit 373bff1

Please sign in to comment.