Skip to content

Commit ab6a498

Browse files
committed
Update VMClass.Spec.ConfigSpec to be RawMessage
This patch updates the VMClass.Spec.ConfigSpec to be json.RawMessage, which is similar to runtime.RawExtension, but has no opinion about being a runtime.Object. Per kubernetes-sigs/controller-tools#637, it was necessary to decorate the field with the following kubebuilder annotations to force the wire protocol to be an object: // +kubebuilder:validation:Schemaless // +kubebuilder:validation:Type=object // +kubebuilder:pruning:PreserveUnknownFields
1 parent bd9d04e commit ab6a498

File tree

6 files changed

+59
-15
lines changed

6 files changed

+59
-15
lines changed

api/v1alpha1/types.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2023 VMware, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import (
7+
"encoding/json"
8+
)
9+
10+
// RawMessage describes a message transmitted on the wire as raw JSON.
11+
//
12+
// The contents will also be emitted by commands like "kubectl get -oyaml"
13+
// as raw YAML instead of base64-encoding the contained byte slice.
14+
//
15+
// Please note that fields of type RawMesssage must also use the following
16+
// kubebuilder annotations +kubebuilder:pruning:PreserveUnknownFields
17+
// and +kubebuilder:validation:XPreserveUnknownFields to facilitate the desired
18+
// behavior.
19+
type RawMessage struct {
20+
json.RawMessage `json:"-"`
21+
}

api/v1alpha1/virtualmachineclass_types.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
// Copyright (c) 2019 VMware, Inc. All Rights Reserved.
1+
// Copyright (c) 2019-2023 VMware, Inc. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package v1alpha1
55

66
import (
7+
"encoding/json"
8+
79
"k8s.io/apimachinery/pkg/api/resource"
810
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9-
"k8s.io/apimachinery/pkg/runtime"
1011
)
1112

1213
// VGPUDevice contains the configuration corresponding to a vGPU device.
@@ -105,7 +106,10 @@ type VirtualMachineClassSpec struct {
105106
// field "_typeName" to preserve type information.
106107
//
107108
// +optional
108-
ConfigSpec *runtime.RawExtension `json:"configSpec,omitempty"`
109+
// +kubebuilder:validation:Schemaless
110+
// +kubebuilder:validation:Type=object
111+
// +kubebuilder:pruning:PreserveUnknownFields
112+
ConfigSpec json.RawMessage `json:"configSpec,omitempty"`
109113
}
110114

111115
// VirtualMachineClassStatus defines the observed state of VirtualMachineClass. VirtualMachineClasses are immutable,

api/v1alpha1/zz_generated.deepcopy.go

+23-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/user-guide/apis/v1alpha1.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ _Appears in:_
552552
| `timeoutSeconds` _integer_ | TimeoutSeconds specifies a number of seconds after which the probe times out. Defaults to 10 seconds. Minimum value is 1. |
553553
| `periodSeconds` _integer_ | PeriodSeconds specifics how often (in seconds) to perform the probe. Defaults to 10 seconds. Minimum value is 1. |
554554

555+
555556
### ResourcePoolSpec
556557

557558

@@ -679,7 +680,7 @@ _Appears in:_
679680
| `hardware` _[VirtualMachineClassHardware](#virtualmachineclasshardware)_ | Hardware describes the configuration of the VirtualMachineClass attributes related to virtual hardware. The configuration specified in this field is used to customize the virtual hardware characteristics of any VirtualMachine associated with this VirtualMachineClass. |
680681
| `policies` _[VirtualMachineClassPolicies](#virtualmachineclasspolicies)_ | Policies describes the configuration of the VirtualMachineClass attributes related to virtual infrastructure policy. The configuration specified in this field is used to customize various policies related to infrastructure resource consumption. |
681682
| `description` _string_ | Description describes the configuration of the VirtualMachineClass which is not related to virtual hardware or infrastructure policy. This field is used to address remaining specs about this VirtualMachineClass. |
682-
| `configSpec` _RawExtension_ | ConfigSpec describes additional configuration information for a VirtualMachine.
683+
| `configSpec` _integer array_ | ConfigSpec describes additional configuration information for a VirtualMachine.
683684
The contents of this field are the VirtualMachineConfigSpec data object (https://bit.ly/3HDtiRu) marshaled to JSON using the discriminator field "_typeName" to preserve type information. |
684685

685686

pkg/vmprovider/providers/vsphere/vmprovider_vm_test.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022 VMware, Inc. All Rights Reserved.
1+
// Copyright (c) 2022-2023 VMware, Inc. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package vsphere_test
@@ -21,7 +21,6 @@ import (
2121
corev1 "k8s.io/api/core/v1"
2222
"k8s.io/apimachinery/pkg/api/resource"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24-
"k8s.io/apimachinery/pkg/runtime"
2524
"k8s.io/utils/pointer"
2625
"sigs.k8s.io/controller-runtime/pkg/client"
2726

@@ -168,9 +167,7 @@ func vmTests() {
168167
// Update the VM Class with the XML.
169168
vmClass := &vmopv1alpha1.VirtualMachineClass{}
170169
Expect(ctx.Client.Get(ctx, client.ObjectKey{Name: vm.Spec.ClassName}, vmClass)).To(Succeed())
171-
vmClass.Spec.ConfigSpec = &runtime.RawExtension{
172-
Raw: w.Bytes(),
173-
}
170+
vmClass.Spec.ConfigSpec = w.Bytes()
174171
Expect(ctx.Client.Update(ctx, vmClass)).To(Succeed())
175172
}
176173

pkg/vmprovider/providers/vsphere/vmprovider_vm_utils.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// Copyright (c) 2022 VMware, Inc. All Rights Reserved.
1+
// Copyright (c) 2022-2023 VMware, Inc. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package vsphere
55

66
import (
7+
"encoding/json"
78
"fmt"
89

910
corev1 "k8s.io/api/core/v1"
10-
"k8s.io/apimachinery/pkg/runtime"
1111
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
1212

1313
"github.com/google/uuid"
@@ -316,11 +316,11 @@ func AddInstanceStorageVolumes(
316316
return nil
317317
}
318318

319-
func GetVMClassConfigSpec(raw *runtime.RawExtension) (*types.VirtualMachineConfigSpec, error) {
319+
func GetVMClassConfigSpec(raw json.RawMessage) (*types.VirtualMachineConfigSpec, error) {
320320
if raw == nil {
321321
return nil, nil
322322
}
323-
classConfigSpec, err := util.UnmarshalConfigSpecFromJSON(raw.Raw)
323+
classConfigSpec, err := util.UnmarshalConfigSpecFromJSON(raw)
324324
if err != nil {
325325
return nil, err
326326
}

0 commit comments

Comments
 (0)