Skip to content

Commit 986aa2d

Browse files
authored
Add new CnsNodeVmBatchAttachment CRD and its reconciliation logic (#3320)
1 parent 0b22249 commit 986aa2d

File tree

29 files changed

+2656
-16
lines changed

29 files changed

+2656
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/stretchr/testify v1.10.0
2626
github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250509154507-b93e51fc90fa
2727
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa
28-
github.com/vmware/govmomi v0.52.0-alpha.0.0.20250702012001-bedcaadc5399
28+
github.com/vmware/govmomi v0.52.0-alpha.0.0.20250703230444-21b9e0eb856b
2929
go.uber.org/zap v1.27.0
3030
golang.org/x/crypto v0.38.0
3131
golang.org/x/sync v0.15.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250509154507-b93e51fc90fa h1:
293293
github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250509154507-b93e51fc90fa/go.mod h1:V0JbH4beGCU+q7yqnWUYYOuDij0ut5i1iBO4cyzg+tM=
294294
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa h1:4MKu14YJ7J54O6QKmT4ds5EUpysWLLtQRMff73cVkmU=
295295
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa/go.mod h1:8tiuyYslzjLIUmOlXZuGKQdQP2ZgWGCVhVeyptmZYnk=
296-
github.com/vmware/govmomi v0.52.0-alpha.0.0.20250702012001-bedcaadc5399 h1:WhIEqQdAYyAoit0wR2UOhQN682F2pyeWQWYOdFXWGZc=
297-
github.com/vmware/govmomi v0.52.0-alpha.0.0.20250702012001-bedcaadc5399/go.mod h1:ZJ5Zd2wDGRzsTRBqA1jpqtbyoe8mRok1rWiPsrL8c7k=
296+
github.com/vmware/govmomi v0.52.0-alpha.0.0.20250703230444-21b9e0eb856b h1:8yzbmQkF7m0njK7UzolNelVGpl7JWHifo1L+suH5VAM=
297+
github.com/vmware/govmomi v0.52.0-alpha.0.0.20250703230444-21b9e0eb856b/go.mod h1:ZJ5Zd2wDGRzsTRBqA1jpqtbyoe8mRok1rWiPsrL8c7k=
298298
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
299299
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
300300
github.com/xiang90/probing v0.0.0-20221125231312-a49e3df8f510 h1:S2dVYn90KE98chqDkyE9Z4N61UnQd+KOfgp5Iu53llk=

manifests/supervisorcluster/1.29/cns-csi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rules:
4040
resources: ["cnsvolumemetadatas", "cnsfileaccessconfigs"]
4141
verbs: ["get", "list", "watch", "update"]
4242
- apiGroups: ["cns.vmware.com"]
43-
resources: ["cnsnodevmattachments"]
43+
resources: ["cnsnodevmattachments", "cnsnodevmbatchattachments", "cnsnodevmbatchattachments/status"]
4444
verbs: ["get", "list", "watch", "update", "patch"]
4545
- apiGroups: ["cns.vmware.com"]
4646
resources: ["cnscsisvfeaturestates"]

manifests/supervisorcluster/1.30/cns-csi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rules:
4040
resources: ["cnsvolumemetadatas", "cnsfileaccessconfigs"]
4141
verbs: ["get", "list", "watch", "update"]
4242
- apiGroups: ["cns.vmware.com"]
43-
resources: ["cnsnodevmattachments"]
43+
resources: ["cnsnodevmattachments", "cnsnodevmbatchattachments", "cnsnodevmbatchattachments/status"]
4444
verbs: ["get", "list", "watch", "update", "patch"]
4545
- apiGroups: ["cns.vmware.com"]
4646
resources: ["cnscsisvfeaturestates"]

manifests/supervisorcluster/1.31/cns-csi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rules:
4040
resources: ["cnsvolumemetadatas", "cnsfileaccessconfigs"]
4141
verbs: ["get", "list", "watch", "update"]
4242
- apiGroups: ["cns.vmware.com"]
43-
resources: ["cnsnodevmattachments"]
43+
resources: ["cnsnodevmattachments","cnsnodevmbatchattachments", "cnsnodevmbatchattachments/status"]
4444
verbs: ["get", "list", "watch", "update", "patch"]
4545
- apiGroups: ["cns.vmware.com"]
4646
resources: ["cnscsisvfeaturestates"]

manifests/supervisorcluster/1.32/cns-csi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rules:
4040
resources: ["cnsvolumemetadatas", "cnsfileaccessconfigs"]
4141
verbs: ["get", "list", "watch", "update"]
4242
- apiGroups: ["cns.vmware.com"]
43-
resources: ["cnsnodevmattachments"]
43+
resources: ["cnsnodevmattachments", "cnsnodevmbatchattachments", "cnsnodevmbatchattachments/status"]
4444
verbs: ["get", "list", "watch", "update", "patch"]
4545
- apiGroups: ["cns.vmware.com"]
4646
resources: ["cnscsisvfeaturestates"]
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
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 v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// DiskMode describes the desired mode to use when attaching the volume.
24+
type DiskMode string
25+
26+
const (
27+
// By setting DiskMode to IndependentPersistent, a virtual machine's disk is not captured in snapshots and
28+
// changes are permanently written to the disk, regardless of snapshot operations.
29+
IndependentPersistent DiskMode = "IndependentPersistent"
30+
// Changes are immediately and permanently written to the virtual disk.
31+
Persistent DiskMode = "Persistent"
32+
)
33+
34+
// The sharing mode of the virtual disk.
35+
type SharingMode string
36+
37+
const (
38+
// The virtual disk is shared between multiple virtual machines.
39+
SharingMultiWriter SharingMode = "sharingMultiWriter"
40+
// The virtual disk is not shared.
41+
SharingNone SharingMode = "sharingNone"
42+
)
43+
44+
// CnsNodeVmBatchAttachmentSpec defines the desired state of CnsNodeVmBatchAttachment
45+
// +k8s:openapi-gen=true
46+
type CnsNodeVmBatchAttachmentSpec struct {
47+
// NodeUUID indicates the UUID of the node where the volume needs to be attached to.
48+
// Here NodeUUID is the instance UUID of the node.
49+
NodeUUID string `json:"nodeuuid"`
50+
51+
// +listType=map
52+
// +listMapKey=name
53+
// VolumeSpec reflects the desired state for each volume.
54+
Volumes []VolumeSpec `json:"volumes"`
55+
}
56+
57+
type VolumeSpec struct {
58+
// Name of the volume as given by the user.
59+
Name string `json:"name"`
60+
// PersistentVolumeClaim contains details about the volume's desired state.
61+
PersistentVolumeClaim PersistentVolumeClaimSpec `json:"persistentVolumeClaim"`
62+
}
63+
64+
type PersistentVolumeClaimSpec struct {
65+
// ClaimName is the PVC name.
66+
ClaimName string `json:"claimName"`
67+
// DiskMode is the desired mode to use when attaching the volume
68+
DiskMode DiskMode `json:"diskMode,omitempty"`
69+
// SharingMode indicates the shraring mode if the virtual disk while attaching.
70+
SharingMode SharingMode `json:"sharingMode,omitempty"`
71+
// ControllerKey is the object key for the controller object for this device.
72+
ControllerKey string `json:"controllerKey,omitempty"`
73+
// UnitNumber of this device on its controller.
74+
UnitNumber string `json:"unitNumber,omitempty"`
75+
}
76+
77+
// CnsNodeVmBatchAttachmentStatus defines the observed state of CnsNodeVmBatchAttachment
78+
// +k8s:openapi-gen=true
79+
type CnsNodeVmBatchAttachmentStatus struct {
80+
// Error is the overall error status for the instance.
81+
Error string `json:"error,omitempty"`
82+
// +listType=map
83+
// +listMapKey=name
84+
// VolumeStatus reflects the status for each volume.
85+
VolumeStatus []VolumeStatus `json:"volumes,omitempty"`
86+
}
87+
88+
type VolumeStatus struct {
89+
// Name of the volume as given by the user.
90+
Name string `json:"name"`
91+
// PersistentVolumeClaim contains details about the volume's current state.
92+
PersistentVolumeClaim PersistentVolumeClaimStatus `json:"persistentVolumeClaim"`
93+
}
94+
95+
type PersistentVolumeClaimStatus struct {
96+
// ClaimName is the PVC name.
97+
ClaimName string `json:"claimName"`
98+
// If volume is not attached, Attached will be set to false.
99+
// If volume is attached, Attached will be set to true.
100+
// If volume is detached successfully, its entry will be removed from VolumeStatus.
101+
Attached bool `json:"attached"`
102+
// Error indicates the error which may have occurred during attach/detach.
103+
Error string `json:"error,omitempty"`
104+
// CnsVolumeID is the volume ID for the PVC.
105+
CnsVolumeID string `json:"cnsVolumeId,omitempty"`
106+
// Diskuuid is the ID obtained when volume is attached to a VM.
107+
Diskuuid string `json:"diskuuid,omitempty"`
108+
}
109+
110+
// +genclient
111+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
112+
113+
// +k8s:openapi-gen=true
114+
// +kubebuilder:subresource:status
115+
116+
// CnsNodeVmBatchAttachment is the Schema for the cnsnodevmbatchattachments API
117+
type CnsNodeVmBatchAttachment struct {
118+
metav1.TypeMeta `json:",inline"`
119+
metav1.ObjectMeta `json:"metadata,omitempty"`
120+
121+
Spec CnsNodeVmBatchAttachmentSpec `json:"spec,omitempty"`
122+
Status CnsNodeVmBatchAttachmentStatus `json:"status,omitempty"`
123+
}
124+
125+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
126+
127+
// CnsNodeVmBatchAttachmentList contains a list of CnsNodeVmBatchAttachment
128+
type CnsNodeVmBatchAttachmentList struct {
129+
metav1.TypeMeta `json:",inline"`
130+
metav1.ListMeta `json:"metadata,omitempty"`
131+
Items []CnsNodeVmBatchAttachment `json:"items"`
132+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) 2025 VMware, Inc. All rights reserved. -- VMware Confidential
2+
// +k8s:deepcopy-gen=package
3+
// +k8s:defaulter-gen=TypeMeta
4+
// +groupName=cns.vmware.com
5+
6+
package v1alpha1

pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/zz_generated.deepcopy.go

Lines changed: 188 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/cnsoperator/config/cns.vmware.com_cnsnodevmattachments.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spec:
3939
properties:
4040
nodeuuid:
4141
description: NodeUUID indicates the UUID of the node where the volume
42-
needs to be attached to. Here NodeUUID is the bios UUID of the node.
42+
needs to be attached to. Here NodeUUID is the instance UUID of the node.
4343
type: string
4444
volumename:
4545
description: VolumeName indicates the name of the volume on the supervisor

0 commit comments

Comments
 (0)