Skip to content

Commit d9d4886

Browse files
refactor
Signed-off-by: Yaroslav Borbat <[email protected]>
1 parent ded361f commit d9d4886

File tree

30 files changed

+1695
-195
lines changed

30 files changed

+1695
-195
lines changed

api/client/generated/clientset/versioned/typed/core/v1alpha2/virtualmachine_expansion.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ import (
2323
"net"
2424
"time"
2525

26-
"github.com/deckhouse/virtualization/api/subresources/v1alpha2"
26+
"github.com/deckhouse/virtualization/api/subresources/v1alpha3"
2727
)
2828

2929
type VirtualMachineExpansion interface {
3030
SerialConsole(name string, options *SerialConsoleOptions) (StreamInterface, error)
3131
VNC(name string) (StreamInterface, error)
32-
PortForward(name string, opts v1alpha2.VirtualMachinePortForward) (StreamInterface, error)
33-
Freeze(ctx context.Context, name string, opts v1alpha2.VirtualMachineFreeze) error
32+
PortForward(name string, opts v1alpha3.VirtualMachinePortForward) (StreamInterface, error)
33+
Freeze(ctx context.Context, name string, opts v1alpha3.VirtualMachineFreeze) error
3434
Unfreeze(ctx context.Context, name string) error
35-
AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineAddVolume) error
36-
RemoveVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineRemoveVolume) error
35+
AddVolume(ctx context.Context, name string, opts v1alpha3.VirtualMachineAddVolume) error
36+
RemoveVolume(ctx context.Context, name string, opts v1alpha3.VirtualMachineRemoveVolume) error
3737
CancelEvacuation(ctx context.Context, name string, dryRun []string) error
3838
}
3939

@@ -58,23 +58,23 @@ func (c *virtualMachines) VNC(name string) (StreamInterface, error) {
5858
return nil, fmt.Errorf("not implemented")
5959
}
6060

61-
func (c *virtualMachines) PortForward(name string, opts v1alpha2.VirtualMachinePortForward) (StreamInterface, error) {
61+
func (c *virtualMachines) PortForward(name string, opts v1alpha3.VirtualMachinePortForward) (StreamInterface, error) {
6262
return nil, fmt.Errorf("not implemented")
6363
}
6464

65-
func (c *virtualMachines) Freeze(ctx context.Context, name string, opts v1alpha2.VirtualMachineFreeze) error {
65+
func (c *virtualMachines) Freeze(ctx context.Context, name string, opts v1alpha3.VirtualMachineFreeze) error {
6666
return fmt.Errorf("not implemented")
6767
}
6868

6969
func (c *virtualMachines) Unfreeze(ctx context.Context, name string) error {
7070
return fmt.Errorf("not implemented")
7171
}
7272

73-
func (c *virtualMachines) AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineAddVolume) error {
73+
func (c *virtualMachines) AddVolume(ctx context.Context, name string, opts v1alpha3.VirtualMachineAddVolume) error {
7474
return fmt.Errorf("not implemented")
7575
}
7676

77-
func (c *virtualMachines) RemoveVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineRemoveVolume) error {
77+
func (c *virtualMachines) RemoveVolume(ctx context.Context, name string, opts v1alpha3.VirtualMachineRemoveVolume) error {
7878
return fmt.Errorf("not implemented")
7979
}
8080

api/client/kubeclient/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (c client) VirtualMachines(namespace string) virtualizationv1alpha2.Virtual
7575
restClient: c.restClient,
7676
config: c.config,
7777
namespace: namespace,
78-
resource: "virtualmachines",
78+
resource: "apivirtualmachines",
7979
}
8080
}
8181

api/client/kubeclient/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"k8s.io/client-go/rest"
2929
)
3030

31-
const subresourceURLTpl = "/apis/subresources.virtualization.deckhouse.io/v1alpha2/namespaces/%s/%s/%s/%s"
31+
const subresourceURLTpl = "/apis/subresources.virtualization.deckhouse.io/v1alpha3/namespaces/%s/%s/%s/%s"
3232

3333
func RequestFromConfig(config *rest.Config, resource, name, namespace, subresource string,
3434
queryParams url.Values) (*http.Request, error) {

api/client/kubeclient/vm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
virtv1 "kubevirt.io/api/core/v1"
3535

3636
virtualizationv1alpha2 "github.com/deckhouse/virtualization/api/client/generated/clientset/versioned/typed/core/v1alpha2"
37-
"github.com/deckhouse/virtualization/api/subresources/v1alpha2"
37+
"github.com/deckhouse/virtualization/api/subresources/v1alpha3"
3838
)
3939

4040
type vm struct {
@@ -96,7 +96,7 @@ func (v vm) VNC(name string) (virtualizationv1alpha2.StreamInterface, error) {
9696
return asyncSubresourceHelper(v.config, v.resource, v.namespace, name, "vnc", url.Values{})
9797
}
9898

99-
func (v vm) PortForward(name string, opts v1alpha2.VirtualMachinePortForward) (virtualizationv1alpha2.StreamInterface, error) {
99+
func (v vm) PortForward(name string, opts v1alpha3.VirtualMachinePortForward) (virtualizationv1alpha2.StreamInterface, error) {
100100
params := url.Values{}
101101
if opts.Port > 0 {
102102
params.Add("port", strconv.Itoa(opts.Port))
@@ -107,7 +107,7 @@ func (v vm) PortForward(name string, opts v1alpha2.VirtualMachinePortForward) (v
107107
return asyncSubresourceHelper(v.config, v.resource, v.namespace, name, "portforward", params)
108108
}
109109

110-
func (v vm) Freeze(ctx context.Context, name string, opts v1alpha2.VirtualMachineFreeze) error {
110+
func (v vm) Freeze(ctx context.Context, name string, opts v1alpha3.VirtualMachineFreeze) error {
111111
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "freeze")
112112

113113
unfreezeTimeout := virtv1.FreezeUnfreezeTimeout{
@@ -132,7 +132,7 @@ func (v vm) Unfreeze(ctx context.Context, name string) error {
132132
return v.restClient.Put().AbsPath(path).Do(ctx).Error()
133133
}
134134

135-
func (v vm) AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineAddVolume) error {
135+
func (v vm) AddVolume(ctx context.Context, name string, opts v1alpha3.VirtualMachineAddVolume) error {
136136
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "addvolume")
137137
return v.restClient.
138138
Put().
@@ -147,7 +147,7 @@ func (v vm) AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMac
147147
Error()
148148
}
149149

150-
func (v vm) RemoveVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineRemoveVolume) error {
150+
func (v vm) RemoveVolume(ctx context.Context, name string, opts v1alpha3.VirtualMachineRemoveVolume) error {
151151
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "removevolume")
152152
return v.restClient.
153153
Put().

api/scripts/update-codegen.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ function generate::subresources {
4949
--boilerplate "${SCRIPT_DIR}/boilerplate.go.txt" \
5050
"${API_ROOT}/subresources"
5151

52+
# "${THIS_PKG}/subresources/v1alpha3" "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/version"
53+
# TODO: replace packages when legacyVMStorage is removed
5254
go tool openapi-gen \
5355
--output-pkg "openapi" \
5456
--output-dir "${ROOT}/images/virtualization-artifact/pkg/apiserver/api/generated/openapi" \
5557
--output-file "zz_generated.openapi.go" \
5658
--go-header-file "${SCRIPT_DIR}/boilerplate.go.txt" \
5759
-r /dev/null \
58-
"${THIS_PKG}/core/v1alpha2" "${THIS_PKG}/subresources/v1alpha2" "kubevirt.io/api/core/v1" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/version"
60+
"${THIS_PKG}/core/v1alpha2" "${THIS_PKG}/subresources/v1alpha2" "${THIS_PKG}/subresources/v1alpha3" "kubevirt.io/api/core/v1" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/version"
5961
}
6062

6163
function generate::core {

api/subresources/install/install.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import (
2222

2323
"github.com/deckhouse/virtualization/api/subresources"
2424
"github.com/deckhouse/virtualization/api/subresources/v1alpha2"
25+
"github.com/deckhouse/virtualization/api/subresources/v1alpha3"
2526
)
2627

2728
// Install registers the API group and adds types to a scheme
2829
func Install(scheme *runtime.Scheme) {
2930
utilruntime.Must(subresources.AddToScheme(scheme))
3031
utilruntime.Must(v1alpha2.AddToScheme(scheme))
31-
utilruntime.Must(scheme.SetVersionPriority(v1alpha2.SchemeGroupVersion))
32+
utilruntime.Must(v1alpha3.AddToScheme(scheme))
33+
utilruntime.Must(scheme.SetVersionPriority(v1alpha3.SchemeGroupVersion, v1alpha2.SchemeGroupVersion))
3234
}

api/subresources/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ var (
4848
AddToScheme = SchemeBuilder.AddToScheme
4949
)
5050

51-
// TODO: move types virtv2 to pkg/apiserver/api/install
5251
func addKnownTypes(scheme *runtime.Scheme) error {
5352
scheme.AddKnownTypes(SchemeGroupVersion,
53+
&APIVirtualMachine{},
5454
&VirtualMachineConsole{},
5555
&VirtualMachineVNC{},
5656
&VirtualMachinePortForward{},

api/subresources/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ import (
2222

2323
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
2424

25+
type APIVirtualMachine struct {
26+
metav1.TypeMeta
27+
metav1.ObjectMeta
28+
}
29+
30+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
31+
2532
type VirtualMachineConsole struct {
2633
metav1.TypeMeta
2734
}

api/subresources/v1alpha3/doc.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:deepcopy-gen=package
18+
// +k8s:openapi-gen=true
19+
// +k8s:conversion-gen=github.com/deckhouse/virtualization/api/subresources
20+
// +groupName=subresources.virtualization.deckhouse.io
21+
22+
// Package v1alpha3 is the v1alpha3 version of the operations API.
23+
package v1alpha3 // import "github.com/deckhouse/virtualization/api/subresources/v1alpha3"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha3
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime"
21+
"k8s.io/apimachinery/pkg/runtime/schema"
22+
23+
"github.com/deckhouse/virtualization/api/subresources"
24+
)
25+
26+
const (
27+
Version = "v1alpha3"
28+
)
29+
30+
// SchemeGroupVersion is group version used to register these objects
31+
var SchemeGroupVersion = schema.GroupVersion{Group: subresources.GroupName, Version: Version}
32+
33+
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
34+
func Kind(kind string) schema.GroupKind {
35+
return SchemeGroupVersion.WithKind(kind).GroupKind()
36+
}
37+
38+
// Resource takes an unqualified resource and returns back a Group qualified GroupResource
39+
func Resource(resource string) schema.GroupResource {
40+
return SchemeGroupVersion.WithResource(resource).GroupResource()
41+
}
42+
43+
var (
44+
// SchemeBuilder is the scheme builder with scheme init functions to run for this API package
45+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
46+
localSchemeBuilder = &SchemeBuilder
47+
// AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme
48+
AddToScheme = SchemeBuilder.AddToScheme
49+
)
50+
51+
func addKnownTypes(scheme *runtime.Scheme) error {
52+
scheme.AddKnownTypes(SchemeGroupVersion,
53+
&APIVirtualMachine{},
54+
&VirtualMachineConsole{},
55+
&VirtualMachineVNC{},
56+
&VirtualMachinePortForward{},
57+
&VirtualMachineAddVolume{},
58+
&VirtualMachineRemoveVolume{},
59+
&VirtualMachineFreeze{},
60+
&VirtualMachineUnfreeze{},
61+
&VirtualMachineCancelEvacuation{},
62+
)
63+
return nil
64+
}

0 commit comments

Comments
 (0)