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 ad2a82d commit c78e632
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
5 changes: 3 additions & 2 deletions api/client/kubeclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import (
)

var (
Scheme = runtime.NewScheme()
Codecs = serializer.NewCodecFactory(Scheme)
Scheme = runtime.NewScheme()
Codecs = serializer.NewCodecFactory(Scheme)
ParameterCodec = runtime.NewParameterCodec(Scheme)
)

func init() {
Expand Down
18 changes: 6 additions & 12 deletions api/client/kubeclient/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
virtv1 "kubevirt.io/api/core/v1"

Expand Down Expand Up @@ -152,26 +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")

return v.restClient.
Put().
AbsPath(path).
Param("name", opts.Name).
Param("volumeKind", opts.VolumeKind).
Param("pvcName", opts.PVCName).
Param("image", opts.Image).
Param("isCdrom", strconv.FormatBool(opts.IsCdrom)).
Do(ctx).
Error()
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")
return v.doRequest(ctx, path, &opts)
}

func (v vm) doRequest(ctx context.Context, path string, obj runtime.Object) error {
return v.restClient.
Put().
AbsPath(path).
Param("name", opts.Name).
VersionedParams(obj, ParameterCodec).
Do(ctx).
Error()
}

0 comments on commit c78e632

Please sign in to comment.