Skip to content

Commit

Permalink
fix(vmbda): fix hotplug api call
Browse files Browse the repository at this point in the history
Signed-off-by: Isteb4k <[email protected]>
  • Loading branch information
Isteb4k committed Jun 20, 2024
1 parent 6a8faf7 commit 7773720
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 9 deletions.
File renamed without changes.
25 changes: 25 additions & 0 deletions .mirrord/mirrord_virtualization_api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"feature": {
"network": {
"incoming": "steal",
"outgoing": true
},
"fs": {
"mode": "read",
"read_only": [ "^/var/", "^/etc/" ]
},
"env": true
},
"agent": {
"communication_timeout": 6000,
"startup_timeout": 56000
},
"internal_proxy": {
"start_idle_timeout": 13000,
"idle_timeout": 1500
},
"target": {
"namespace": "d8-virtualization",
"path": "deployment/virtualization-api/container/virtualization-api"
}
}
3 changes: 2 additions & 1 deletion api/client/kubeclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ type StreamInterface interface {

type VirtualMachineInterface interface {
virtualizationv1alpha2.VirtualMachineInterface
SerialConsole(name string, options *SerialConsoleOptions) (StreamInterface, error)
SerialConsole(name string, opts *SerialConsoleOptions) (StreamInterface, error)
VNC(name string) (StreamInterface, error)
PortForward(name string, opts v1alpha2.VirtualMachinePortForward) (StreamInterface, error)
AddVolume(name string) (StreamInterface, error)
}

type client struct {
Expand Down
4 changes: 4 additions & 0 deletions api/client/kubeclient/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ func (v vm) PortForward(name string, opts v1alpha2.VirtualMachinePortForward) (S
}
return asyncSubresourceHelper(v.config, v.resource, v.namespace, name, "portforward", params)
}

func (v vm) AddVolume(name string) (StreamInterface, error) {
return asyncSubresourceHelper(v.config, v.resource, v.namespace, name, "addvolume", url.Values{})
}
27 changes: 27 additions & 0 deletions api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/subresources/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&VirtualMachineConsole{},
&VirtualMachineVNC{},
&VirtualMachinePortForward{},
&VirtualMachineAddVolume{},
&virtv2.VirtualMachine{},
&virtv2.VirtualMachineList{},
)
Expand Down
8 changes: 8 additions & 0 deletions api/subresources/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ type VirtualMachinePortForward struct {
Protocol string
Port int
}

// +genclient
// +genclient:readonly
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type VirtualMachineAddVolume struct {
metav1.TypeMeta
}
1 change: 1 addition & 0 deletions api/subresources/v1alpha2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&VirtualMachineConsole{},
&VirtualMachineVNC{},
&VirtualMachinePortForward{},
&VirtualMachineAddVolume{},
&virtv2.VirtualMachine{},
&virtv2.VirtualMachineList{},
)
Expand Down
9 changes: 9 additions & 0 deletions api/subresources/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ type VirtualMachinePortForward struct {
Protocol string `json:"protocol"`
Port int `json:"port"`
}

// +genclient
// +genclient:readonly
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:conversion-gen:explicit-from=net/url.Values

type VirtualMachineAddVolume struct {
metav1.TypeMeta `json:",inline"`
}
44 changes: 44 additions & 0 deletions api/subresources/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions api/subresources/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions api/subresources/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions images/virt-artifact/patches/017-fix-vmi-subresource-url.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/staging/src/kubevirt.io/client-go/kubecli/vmi.go b/staging/src/kubevirt.io/client-go/kubecli/vmi.go
index a9e071350..cb867cfc6 100644
--- a/staging/src/kubevirt.io/client-go/kubecli/vmi.go
+++ b/staging/src/kubevirt.io/client-go/kubecli/vmi.go
@@ -47,7 +47,10 @@ import (
"kubevirt.io/client-go/subresources"
)

-const vmiSubresourceURL = "/apis/subresources.kubevirt.io/%s/namespaces/%s/virtualmachineinstances/%s/%s"
+const (
+ vmiSubresourceURL = "/apis/subresources.kubevirt.io/%s/namespaces/%s/virtualmachineinstances/%s/%s"
+ vmiSubresourceVirtualizationURL = "/apis/subresources.virtualization.deckhouse.io/%s/namespaces/%s/virtualmachineinstances/%s/%s"
+)

func (k *kubevirt) VirtualMachineInstance(namespace string) VirtualMachineInstanceInterface {
return &vmis{
@@ -470,7 +473,7 @@ func (v *vmis) Screenshot(ctx context.Context, name string, screenshotOptions *v
}

func (v *vmis) AddVolume(ctx context.Context, name string, addVolumeOptions *v1.AddVolumeOptions) error {
- uri := fmt.Sprintf(vmiSubresourceURL, v1.ApiStorageVersion, v.namespace, name, "addvolume")
+ uri := fmt.Sprintf(vmiSubresourceVirtualizationURL, v1.ApiStorageVersion, v.namespace, name, "addvolume")

JSON, err := json.Marshal(addVolumeOptions)

@@ -482,7 +485,7 @@ func (v *vmis) AddVolume(ctx context.Context, name string, addVolumeOptions *v1.
}

func (v *vmis) RemoveVolume(ctx context.Context, name string, removeVolumeOptions *v1.RemoveVolumeOptions) error {
- uri := fmt.Sprintf(vmiSubresourceURL, v1.ApiStorageVersion, v.namespace, name, "removevolume")
+ uri := fmt.Sprintf(vmiSubresourceVirtualizationURL, v1.ApiStorageVersion, v.namespace, name, "removevolume")

JSON, err := json.Marshal(removeVolumeOptions)

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func Build(store *storage.VirtualMachineStorage) genericapiserver.APIGroupInfo {
"virtualmachines/console": store.ConsoleREST(),
"virtualmachines/vnc": store.VncREST(),
"virtualmachines/portforward": store.PortForwardREST(),
"virtualmachines/addvolume": store.AddVolumeREST(),
}
apiGroupInfo.VersionedResourcesStorageMap[v1alpha2.SchemeGroupVersion.Version] = resources
return apiGroupInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package rest

import (
"context"
"fmt"
"net/http"
"net/url"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/client-go/tools/cache"

"github.com/deckhouse/virtualization-controller/pkg/tls/certmanager"
"github.com/deckhouse/virtualization/api/subresources"
)

type AddVolumeREST struct {
vmLister cache.GenericLister
proxyCertManager certmanager.CertificateManager
kubevirt KubevirtApiServerConfig
}

var (
_ rest.Storage = &AddVolumeREST{}
_ rest.Connecter = &AddVolumeREST{}
)

func NewAddVolumeREST(vmLister cache.GenericLister, kubevirt KubevirtApiServerConfig, proxyCertManager certmanager.CertificateManager) *AddVolumeREST {
return &AddVolumeREST{
vmLister: vmLister,
kubevirt: kubevirt,
proxyCertManager: proxyCertManager,
}
}

func (r AddVolumeREST) New() runtime.Object {
return &subresources.VirtualMachineAddVolume{}
}

func (r AddVolumeREST) Destroy() {
}

func (r AddVolumeREST) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) {
addVolumeOpts, ok := opts.(*subresources.VirtualMachineAddVolume)
if !ok {
return nil, fmt.Errorf("invalid options object: %#v", opts)
}
location, transport, err := AddVolumeLocation(ctx, r.vmLister, name, addVolumeOpts, r.kubevirt, r.proxyCertManager)
if err != nil {
return nil, err
}
handler := newThrottledUpgradeAwareProxyHandler(location, transport, responder, r.kubevirt.ServiceAccount)
return handler, nil
}

// NewConnectOptions implements rest.Connecter interface
func (r AddVolumeREST) NewConnectOptions() (runtime.Object, bool, string) {
return &subresources.VirtualMachineConsole{}, false, ""
}

// ConnectMethods implements rest.Connecter interface
func (r AddVolumeREST) ConnectMethods() []string {
return upgradeableMethods
}

func AddVolumeLocation(
ctx context.Context,
getter cache.GenericLister,
name string,
opts *subresources.VirtualMachineAddVolume,
kubevirt KubevirtApiServerConfig,
proxyCertManager certmanager.CertificateManager,
) (*url.URL, *http.Transport, error) {
return streamLocation(ctx, getter, name, opts, "addvolume", kubevirt, proxyCertManager)
}
Loading

0 comments on commit 7773720

Please sign in to comment.