mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-12-15 04:17:47 +00:00
DRA API: verbatim copy of v1alpha3 -> v1beta1
This commit is contained in:
40
pkg/apis/resource/v1beta1/conversion.go
Normal file
40
pkg/apis/resource/v1beta1/conversion.go
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
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 v1alpha3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
resourceapi "k8s.io/api/resource/v1alpha3"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
func addConversionFuncs(scheme *runtime.Scheme) error {
|
||||
if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("ResourceSlice"),
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "metadata.name", resourceapi.ResourceSliceSelectorNodeName, resourceapi.ResourceSliceSelectorDriver:
|
||||
return label, value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported for %s: %s", SchemeGroupVersion.WithKind("ResourceSlice"), label)
|
||||
}
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
36
pkg/apis/resource/v1beta1/defaults.go
Normal file
36
pkg/apis/resource/v1beta1/defaults.go
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
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 v1alpha3
|
||||
|
||||
import (
|
||||
resourceapi "k8s.io/api/resource/v1alpha3"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) error {
|
||||
return RegisterDefaults(scheme)
|
||||
}
|
||||
|
||||
func SetDefaults_DeviceRequest(obj *resourceapi.DeviceRequest) {
|
||||
if obj.AllocationMode == "" {
|
||||
obj.AllocationMode = resourceapi.DeviceAllocationModeExactCount
|
||||
}
|
||||
|
||||
if obj.AllocationMode == resourceapi.DeviceAllocationModeExactCount && obj.Count == 0 {
|
||||
obj.Count = 1
|
||||
}
|
||||
}
|
||||
86
pkg/apis/resource/v1beta1/defaults_test.go
Normal file
86
pkg/apis/resource/v1beta1/defaults_test.go
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
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 v1alpha3_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
v1alpha3 "k8s.io/api/resource/v1alpha3"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
// ensure types are installed
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
_ "k8s.io/kubernetes/pkg/apis/resource/install"
|
||||
)
|
||||
|
||||
func TestSetDefaultAllocationMode(t *testing.T) {
|
||||
claim := &v1alpha3.ResourceClaim{
|
||||
Spec: v1alpha3.ResourceClaimSpec{
|
||||
Devices: v1alpha3.DeviceClaim{
|
||||
Requests: []v1alpha3.DeviceRequest{{}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// fields should be defaulted
|
||||
defaultMode := v1alpha3.DeviceAllocationModeExactCount
|
||||
defaultCount := int64(1)
|
||||
output := roundTrip(t, runtime.Object(claim)).(*v1alpha3.ResourceClaim)
|
||||
assert.Equal(t, defaultMode, output.Spec.Devices.Requests[0].AllocationMode)
|
||||
assert.Equal(t, defaultCount, output.Spec.Devices.Requests[0].Count)
|
||||
|
||||
// field should not change
|
||||
nonDefaultMode := v1alpha3.DeviceAllocationModeExactCount
|
||||
nonDefaultCount := int64(10)
|
||||
claim = &v1alpha3.ResourceClaim{
|
||||
Spec: v1alpha3.ResourceClaimSpec{
|
||||
Devices: v1alpha3.DeviceClaim{
|
||||
Requests: []v1alpha3.DeviceRequest{{
|
||||
AllocationMode: nonDefaultMode,
|
||||
Count: nonDefaultCount,
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
output = roundTrip(t, runtime.Object(claim)).(*v1alpha3.ResourceClaim)
|
||||
assert.Equal(t, nonDefaultMode, output.Spec.Devices.Requests[0].AllocationMode)
|
||||
assert.Equal(t, nonDefaultCount, output.Spec.Devices.Requests[0].Count)
|
||||
}
|
||||
|
||||
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||
codec := legacyscheme.Codecs.LegacyCodec(v1alpha3.SchemeGroupVersion)
|
||||
data, err := runtime.Encode(codec, obj)
|
||||
if err != nil {
|
||||
t.Errorf("%v\n %#v", err, obj)
|
||||
return nil
|
||||
}
|
||||
obj2, err := runtime.Decode(codec, data)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
||||
return nil
|
||||
}
|
||||
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
||||
err = legacyscheme.Scheme.Convert(obj2, obj3, nil)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nSource: %#v", err, obj2)
|
||||
return nil
|
||||
}
|
||||
return obj3
|
||||
}
|
||||
23
pkg/apis/resource/v1beta1/doc.go
Normal file
23
pkg/apis/resource/v1beta1/doc.go
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/resource
|
||||
// +k8s:conversion-gen-external-types=k8s.io/api/resource/v1alpha3
|
||||
// +k8s:defaulter-gen=TypeMeta
|
||||
// +k8s:defaulter-gen-input=k8s.io/api/resource/v1alpha3
|
||||
|
||||
// Package v1alpha3 is the v1alpha3 version of the resource API.
|
||||
package v1alpha3 // import "k8s.io/kubernetes/pkg/apis/resource/v1alpha3"
|
||||
46
pkg/apis/resource/v1beta1/register.go
Normal file
46
pkg/apis/resource/v1beta1/register.go
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
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 v1alpha3
|
||||
|
||||
import (
|
||||
"k8s.io/api/resource/v1alpha3"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
localSchemeBuilder = &v1alpha3.SchemeBuilder
|
||||
AddToScheme = localSchemeBuilder.AddToScheme
|
||||
)
|
||||
|
||||
func init() {
|
||||
// We only register manually written functions here. The registration of the
|
||||
// generated functions takes place in the generated files. The separation
|
||||
// makes the code compile even when the generated files are missing.
|
||||
localSchemeBuilder.Register(addDefaultingFuncs, addConversionFuncs)
|
||||
}
|
||||
|
||||
// TODO: remove these global variables
|
||||
// GroupName is the group name use in this package
|
||||
const GroupName = "resource.k8s.io"
|
||||
|
||||
// SchemeGroupVersion is group version used to register these objects
|
||||
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha3"}
|
||||
|
||||
// Resource takes an unqualified resource and returns a Group qualified GroupResource
|
||||
func Resource(resource string) schema.GroupResource {
|
||||
return SchemeGroupVersion.WithResource(resource).GroupResource()
|
||||
}
|
||||
1113
pkg/apis/resource/v1beta1/zz_generated.conversion.go
generated
Normal file
1113
pkg/apis/resource/v1beta1/zz_generated.conversion.go
generated
Normal file
File diff suppressed because it is too large
Load Diff
70
pkg/apis/resource/v1beta1/zz_generated.defaults.go
generated
Normal file
70
pkg/apis/resource/v1beta1/zz_generated.defaults.go
generated
Normal file
@@ -0,0 +1,70 @@
|
||||
//go:build !ignore_autogenerated
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by defaulter-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha3
|
||||
|
||||
import (
|
||||
resourcev1alpha3 "k8s.io/api/resource/v1alpha3"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// RegisterDefaults adds defaulters functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
// All generated defaulters are covering - they call all nested defaulters.
|
||||
func RegisterDefaults(scheme *runtime.Scheme) error {
|
||||
scheme.AddTypeDefaultingFunc(&resourcev1alpha3.ResourceClaim{}, func(obj interface{}) { SetObjectDefaults_ResourceClaim(obj.(*resourcev1alpha3.ResourceClaim)) })
|
||||
scheme.AddTypeDefaultingFunc(&resourcev1alpha3.ResourceClaimList{}, func(obj interface{}) { SetObjectDefaults_ResourceClaimList(obj.(*resourcev1alpha3.ResourceClaimList)) })
|
||||
scheme.AddTypeDefaultingFunc(&resourcev1alpha3.ResourceClaimTemplate{}, func(obj interface{}) {
|
||||
SetObjectDefaults_ResourceClaimTemplate(obj.(*resourcev1alpha3.ResourceClaimTemplate))
|
||||
})
|
||||
scheme.AddTypeDefaultingFunc(&resourcev1alpha3.ResourceClaimTemplateList{}, func(obj interface{}) {
|
||||
SetObjectDefaults_ResourceClaimTemplateList(obj.(*resourcev1alpha3.ResourceClaimTemplateList))
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetObjectDefaults_ResourceClaim(in *resourcev1alpha3.ResourceClaim) {
|
||||
for i := range in.Spec.Devices.Requests {
|
||||
a := &in.Spec.Devices.Requests[i]
|
||||
SetDefaults_DeviceRequest(a)
|
||||
}
|
||||
}
|
||||
|
||||
func SetObjectDefaults_ResourceClaimList(in *resourcev1alpha3.ResourceClaimList) {
|
||||
for i := range in.Items {
|
||||
a := &in.Items[i]
|
||||
SetObjectDefaults_ResourceClaim(a)
|
||||
}
|
||||
}
|
||||
|
||||
func SetObjectDefaults_ResourceClaimTemplate(in *resourcev1alpha3.ResourceClaimTemplate) {
|
||||
for i := range in.Spec.Spec.Devices.Requests {
|
||||
a := &in.Spec.Spec.Devices.Requests[i]
|
||||
SetDefaults_DeviceRequest(a)
|
||||
}
|
||||
}
|
||||
|
||||
func SetObjectDefaults_ResourceClaimTemplateList(in *resourcev1alpha3.ResourceClaimTemplateList) {
|
||||
for i := range in.Items {
|
||||
a := &in.Items[i]
|
||||
SetObjectDefaults_ResourceClaimTemplate(a)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user