Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat committed Jan 18, 2025
1 parent c78e632 commit 55b6582
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 8 additions & 0 deletions api/client/kubeclient/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,19 @@ func (v vm) Migrate(ctx context.Context, name string, opts v1alpha2.VirtualMachi

func (v vm) AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineAddVolume) error {
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "addvolume")
opts.TypeMeta = metav1.TypeMeta{
Kind: v1alpha2.VirtualMachineAddVolumeKind,
APIVersion: v1alpha2.SchemeGroupVersion.String(),
}
return v.doRequest(ctx, path, &opts)
}

func (v vm) RemoveVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineRemoveVolume) error {
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "removevolume")
opts.TypeMeta = metav1.TypeMeta{
Kind: v1alpha2.VirtualMachineRemoveVolumeKind,
APIVersion: v1alpha2.SchemeGroupVersion.String(),
}
return v.doRequest(ctx, path, &opts)
}

Expand Down
5 changes: 5 additions & 0 deletions api/subresources/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ package v1alpha2

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

const (
VirtualMachineAddVolumeKind = "VirtualMachineAddVolume"
VirtualMachineRemoveVolumeKind = "VirtualMachineRemoveVolume"
)

// +genclient
// +genclient:readonly
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewVirtualImageWatcherr(client client.Client) *VirtualImageWatcher {

func (w VirtualImageWatcher) Watch(mgr manager.Manager, ctr controller.Controller) error {
return ctr.Watch(
source.Kind(mgr.GetCache(), &virtv2.VirtualDisk{}),
source.Kind(mgr.GetCache(), &virtv2.VirtualImage{}),
handler.EnqueueRequestsFromMapFunc(w.enqueueRequests),
predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool { return false },
Expand Down Expand Up @@ -85,13 +85,13 @@ func (w VirtualImageWatcher) enqueueRequests(ctx context.Context, obj client.Obj
}

func (w VirtualImageWatcher) filterUpdateEvents(e event.UpdateEvent) bool {
oldVI, ok := e.ObjectOld.(*virtv2.VirtualDisk)
oldVI, ok := e.ObjectOld.(*virtv2.VirtualImage)
if !ok {
slog.Default().Error(fmt.Sprintf("expected an old VirtualImage but got a %T", e.ObjectOld))
return false
}

newVI, ok := e.ObjectNew.(*virtv2.VirtualDisk)
newVI, ok := e.ObjectNew.(*virtv2.VirtualImage)
if !ok {
slog.Default().Error(fmt.Sprintf("expected a new VirtualImage but got a %T", e.ObjectNew))
return false
Expand Down

0 comments on commit 55b6582

Please sign in to comment.