diff --git a/go.mod b/go.mod index bddd219739..b8cb9c48cd 100644 --- a/go.mod +++ b/go.mod @@ -22,14 +22,14 @@ require ( github.com/onsi/gomega v1.36.0 github.com/pkg/sftp v1.13.6 github.com/prometheus/client_golang v1.22.0 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20250923172217-bf5a74e51c65 github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa - github.com/vmware/govmomi v0.52.0-alpha.0.0.20250807230438-0eee109f1f2c + github.com/vmware/govmomi v0.53.0-alpha.0.0.20251008032440-5ef2d64275e2 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.38.0 - golang.org/x/sync v0.15.0 - golang.org/x/sys v0.33.0 + golang.org/x/crypto v0.40.0 + golang.org/x/sync v0.16.0 + golang.org/x/sys v0.34.0 google.golang.org/grpc v1.72.1 google.golang.org/protobuf v1.36.5 gopkg.in/gcfg.v1 v1.2.3 @@ -161,12 +161,12 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.yaml.in/yaml/v2 v2.4.2 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect - golang.org/x/net v0.40.0 // indirect + golang.org/x/net v0.42.0 // indirect golang.org/x/oauth2 v0.27.0 // indirect - golang.org/x/term v0.32.0 // indirect - golang.org/x/text v0.26.0 // indirect + golang.org/x/term v0.33.0 // indirect + golang.org/x/text v0.28.0 // indirect golang.org/x/time v0.9.0 // indirect - golang.org/x/tools v0.33.0 // indirect + golang.org/x/tools v0.35.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect diff --git a/go.sum b/go.sum index 46bf348b6d..18e3eeb7bc 100644 --- a/go.sum +++ b/go.sum @@ -281,8 +281,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/thecodeteam/gofsutil v0.1.2 h1:FL87mBzZeeuDMZm8hpYLFcYylQdq6bbm8UQ1oc6VRMM= github.com/thecodeteam/gofsutil v0.1.2/go.mod h1:7bDOpr2aMnmdm9RTdxBEeqdOr+8RpnQhsB/VUEI3DgM= github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE= @@ -291,8 +291,8 @@ github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20250923172217-bf5a74e51c65 h1: github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20250923172217-bf5a74e51c65/go.mod h1:nWTPpxfe4gHuuYuFcrs86+NMxfkqPk3a3IlvI8TCWak= github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa h1:4MKu14YJ7J54O6QKmT4ds5EUpysWLLtQRMff73cVkmU= github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa/go.mod h1:8tiuyYslzjLIUmOlXZuGKQdQP2ZgWGCVhVeyptmZYnk= -github.com/vmware/govmomi v0.52.0-alpha.0.0.20250807230438-0eee109f1f2c h1:1nMVFr1CBMSNLLjsfx3QPfZ5k0R1/O29QX/A2X0w3RQ= -github.com/vmware/govmomi v0.52.0-alpha.0.0.20250807230438-0eee109f1f2c/go.mod h1:ZJ5Zd2wDGRzsTRBqA1jpqtbyoe8mRok1rWiPsrL8c7k= +github.com/vmware/govmomi v0.53.0-alpha.0.0.20251008032440-5ef2d64275e2 h1:3FnvoKG1eNWYm4KUpcNWHPKG//D8LD/lPCkwRtE/3cY= +github.com/vmware/govmomi v0.53.0-alpha.0.0.20251008032440-5ef2d64275e2/go.mod h1:MKEZBs5aGMM+J33dt2rWXP7ayDyCMKi4hO4DkH694pw= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xiang90/probing v0.0.0-20221125231312-a49e3df8f510 h1:S2dVYn90KE98chqDkyE9Z4N61UnQd+KOfgp5Iu53llk= @@ -359,8 +359,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= -golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM= +golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -374,16 +374,16 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= -golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= -golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs= +golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8= golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M= golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= -golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= +golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -394,19 +394,19 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= -golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= +golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= -golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= +golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg= +golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= -golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= +golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= +golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -415,8 +415,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= -golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= +golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0= +golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/cnsnodebatchvmattachment_types.go b/pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/cnsnodebatchvmattachment_types.go index 01f249f8d2..e9fdee22f3 100644 --- a/pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/cnsnodebatchvmattachment_types.go +++ b/pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/cnsnodebatchvmattachment_types.go @@ -21,35 +21,39 @@ import ( ) // DiskMode describes the desired mode to use when attaching the volume. +// +kubebuilder:validation:Enum=independent_persistent;persistent;independent_nonpersistent type DiskMode string const ( - // By setting DiskMode to independent_persistent, a virtual machine's disk is not captured in snapshots and + // IndependentPersistent is the diskMode in which, a virtual machine's disk is not captured in snapshots and // changes are permanently written to the disk, regardless of snapshot operations. IndependentPersistent DiskMode = "independent_persistent" - // Changes are immediately and permanently written to the virtual disk. + // Persistent diskMode changes are immediately and permanently written to the virtual disk. Persistent DiskMode = "persistent" // Changes to virtual disk are made to a redo log and discarded at power off. // It is not affected by snapshots. IndependentNonPersistent = "independent_nonpersistent" ) -// The sharing mode of the virtual disk. +// SharingMode is the sharing mode of the virtual disk. +// +kubebuilder:validation:Enum=sharingMultiWriter;sharingNone type SharingMode string const ( - // The virtual disk is shared between multiple virtual machines. + // SharingMultiWriter: The virtual disk is shared between multiple virtual machines. SharingMultiWriter SharingMode = "sharingMultiWriter" - // The virtual disk is not shared. + // SharingNone: The virtual disk is not shared. SharingNone SharingMode = "sharingNone" ) -// CnsNodeVmBatchAttachmentSpec defines the desired state of CnsNodeVmBatchAttachment +// CnsNodeVMBatchAttachmentSpec defines the desired state of CnsNodeVMBatchAttachment // +k8s:openapi-gen=true -type CnsNodeVmBatchAttachmentSpec struct { +type CnsNodeVMBatchAttachmentSpec struct { + // +required + // NodeUUID indicates the UUID of the node where the volume needs to be attached to. // Here NodeUUID is the instance UUID of the node. - NodeUUID string `json:"nodeuuid"` + NodeUUID string `json:"nodeUUID"` // +listType=map // +listMapKey=name @@ -65,21 +69,31 @@ type VolumeSpec struct { } type PersistentVolumeClaimSpec struct { + // +required + // ClaimName is the PVC name. ClaimName string `json:"claimName"` + // +optional + // DiskMode is the desired mode to use when attaching the volume DiskMode DiskMode `json:"diskMode,omitempty"` - // SharingMode indicates the shraring mode if the virtual disk while attaching. + // +optional + + // SharingMode indicates the sharing mode if the virtual disk while attaching. SharingMode SharingMode `json:"sharingMode,omitempty"` + // +optional + // ControllerKey is the object key for the controller object for this device. - ControllerKey string `json:"controllerKey,omitempty"` + ControllerKey *int32 `json:"controllerKey,omitempty"` + // +optional + // UnitNumber of this device on its controller. - UnitNumber string `json:"unitNumber,omitempty"` + UnitNumber *int32 `json:"unitNumber,omitempty"` } -// CnsNodeVmBatchAttachmentStatus defines the observed state of CnsNodeVmBatchAttachment +// CnsNodeVMBatchAttachmentStatus defines the observed state of CnsNodeVMBatchAttachment // +k8s:openapi-gen=true -type CnsNodeVmBatchAttachmentStatus struct { +type CnsNodeVMBatchAttachmentStatus struct { // Error is the overall error status for the instance. Error string `json:"error,omitempty"` // +listType=map @@ -98,6 +112,7 @@ type VolumeStatus struct { type PersistentVolumeClaimStatus struct { // ClaimName is the PVC name. ClaimName string `json:"claimName"` + // Attached indicates the attach status of a PVC. // If volume is not attached, Attached will be set to false. // If volume is attached, Attached will be set to true. // If volume is detached successfully, its entry will be removed from VolumeStatus. @@ -106,8 +121,8 @@ type PersistentVolumeClaimStatus struct { Error string `json:"error,omitempty"` // CnsVolumeID is the volume ID for the PVC. CnsVolumeID string `json:"cnsVolumeId,omitempty"` - // Diskuuid is the ID obtained when volume is attached to a VM. - Diskuuid string `json:"diskuuid,omitempty"` + // DiskUUID is the ID obtained when volume is attached to a VM. + DiskUUID string `json:"DiskUUID,omitempty"` } // +genclient @@ -115,21 +130,24 @@ type PersistentVolumeClaimStatus struct { // +k8s:openapi-gen=true // +kubebuilder:subresource:status +// +kubebuilder:object:root=true +// +kubebuilder:resource:shortName=batchattach +// +kubebuilder:printcolumn:name="NodeUUID",type="string",JSONPath=".spec.nodeUUID" -// CnsNodeVmBatchAttachment is the Schema for the cnsnodevmbatchattachments API -type CnsNodeVmBatchAttachment struct { +// CnsNodeVMBatchAttachment is the Schema for the cnsnodevmbatchattachments API +type CnsNodeVMBatchAttachment struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec CnsNodeVmBatchAttachmentSpec `json:"spec,omitempty"` - Status CnsNodeVmBatchAttachmentStatus `json:"status,omitempty"` + Spec CnsNodeVMBatchAttachmentSpec `json:"spec,omitempty"` + Status CnsNodeVMBatchAttachmentStatus `json:"status,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// CnsNodeVmBatchAttachmentList contains a list of CnsNodeVmBatchAttachment -type CnsNodeVmBatchAttachmentList struct { +// CnsNodeVMBatchAttachmentList contains a list of CnsNodeVMBatchAttachment +type CnsNodeVMBatchAttachmentList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []CnsNodeVmBatchAttachment `json:"items"` + Items []CnsNodeVMBatchAttachment `json:"items"` } diff --git a/pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/zz_generated.deepcopy.go index 3099ee3c6e..9ee08181e5 100644 --- a/pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/cnsoperator/cnsnodevmbatchattachment/v1alpha1/zz_generated.deepcopy.go @@ -23,7 +23,7 @@ import ( ) // DeepCopyInto copies all properties from the source into the target. -func (in *CnsNodeVmBatchAttachment) DeepCopyInto(out *CnsNodeVmBatchAttachment) { +func (in *CnsNodeVMBatchAttachment) DeepCopyInto(out *CnsNodeVMBatchAttachment) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -31,18 +31,18 @@ func (in *CnsNodeVmBatchAttachment) DeepCopyInto(out *CnsNodeVmBatchAttachment) in.Status.DeepCopyInto(&out.Status) } -// DeepCopy creates a new CnsNodeVmBatchAttachment. -func (in *CnsNodeVmBatchAttachment) DeepCopy() *CnsNodeVmBatchAttachment { +// DeepCopy creates a new CnsNodeVMBatchAttachment. +func (in *CnsNodeVMBatchAttachment) DeepCopy() *CnsNodeVMBatchAttachment { if in == nil { return nil } - out := new(CnsNodeVmBatchAttachment) + out := new(CnsNodeVMBatchAttachment) in.DeepCopyInto(out) return out } -// DeepCopyObject creates a new runtime.Object from the CnsNodeVmBatchAttachment. -func (in *CnsNodeVmBatchAttachment) DeepCopyObject() runtime.Object { +// DeepCopyObject creates a new runtime.Object from the CnsNodeVMBatchAttachment. +func (in *CnsNodeVMBatchAttachment) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -50,31 +50,31 @@ func (in *CnsNodeVmBatchAttachment) DeepCopyObject() runtime.Object { } // DeepCopyInto copies all properties from the source into the target. -func (in *CnsNodeVmBatchAttachmentList) DeepCopyInto(out *CnsNodeVmBatchAttachmentList) { +func (in *CnsNodeVMBatchAttachmentList) DeepCopyInto(out *CnsNodeVMBatchAttachmentList) { *out = *in out.TypeMeta = in.TypeMeta out.ListMeta = in.ListMeta if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]CnsNodeVmBatchAttachment, len(*in)) + *out = make([]CnsNodeVMBatchAttachment, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy creates a new CnsNodeVmBatchAttachmentList. -func (in *CnsNodeVmBatchAttachmentList) DeepCopy() *CnsNodeVmBatchAttachmentList { +// DeepCopy creates a new CnsNodeVMBatchAttachmentList. +func (in *CnsNodeVMBatchAttachmentList) DeepCopy() *CnsNodeVMBatchAttachmentList { if in == nil { return nil } - out := new(CnsNodeVmBatchAttachmentList) + out := new(CnsNodeVMBatchAttachmentList) in.DeepCopyInto(out) return out } -// DeepCopyObject creates a new runtime.Object from the CnsNodeVmBatchAttachmentList. -func (in *CnsNodeVmBatchAttachmentList) DeepCopyObject() runtime.Object { +// DeepCopyObject creates a new runtime.Object from the CnsNodeVMBatchAttachmentList. +func (in *CnsNodeVMBatchAttachmentList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -82,7 +82,7 @@ func (in *CnsNodeVmBatchAttachmentList) DeepCopyObject() runtime.Object { } // DeepCopyInto copies all properties from the source into the target. -func (in *CnsNodeVmBatchAttachmentSpec) DeepCopyInto(out *CnsNodeVmBatchAttachmentSpec) { +func (in *CnsNodeVMBatchAttachmentSpec) DeepCopyInto(out *CnsNodeVMBatchAttachmentSpec) { *out = *in if in.Volumes != nil { in, out := &in.Volumes, &out.Volumes @@ -93,18 +93,18 @@ func (in *CnsNodeVmBatchAttachmentSpec) DeepCopyInto(out *CnsNodeVmBatchAttachme } } -// DeepCopy creates a new CnsNodeVmBatchAttachmentSpec. -func (in *CnsNodeVmBatchAttachmentSpec) DeepCopy() *CnsNodeVmBatchAttachmentSpec { +// DeepCopy creates a new CnsNodeVMBatchAttachmentSpec. +func (in *CnsNodeVMBatchAttachmentSpec) DeepCopy() *CnsNodeVMBatchAttachmentSpec { if in == nil { return nil } - out := new(CnsNodeVmBatchAttachmentSpec) + out := new(CnsNodeVMBatchAttachmentSpec) in.DeepCopyInto(out) return out } // DeepCopyInto copies all properties from the source into the target. -func (in *CnsNodeVmBatchAttachmentStatus) DeepCopyInto(out *CnsNodeVmBatchAttachmentStatus) { +func (in *CnsNodeVMBatchAttachmentStatus) DeepCopyInto(out *CnsNodeVMBatchAttachmentStatus) { *out = *in if in.VolumeStatus != nil { in, out := &in.VolumeStatus, &out.VolumeStatus @@ -115,12 +115,12 @@ func (in *CnsNodeVmBatchAttachmentStatus) DeepCopyInto(out *CnsNodeVmBatchAttach } } -// DeepCopy creates a new CnsNodeVmBatchAttachmentStatus. -func (in *CnsNodeVmBatchAttachmentStatus) DeepCopy() *CnsNodeVmBatchAttachmentStatus { +// DeepCopy creates a new CnsNodeVMBatchAttachmentStatus. +func (in *CnsNodeVMBatchAttachmentStatus) DeepCopy() *CnsNodeVMBatchAttachmentStatus { if in == nil { return nil } - out := new(CnsNodeVmBatchAttachmentStatus) + out := new(CnsNodeVMBatchAttachmentStatus) in.DeepCopyInto(out) return out } diff --git a/pkg/apis/cnsoperator/config/cns.vmware.com_cnsnodevmbatchattachments.yaml b/pkg/apis/cnsoperator/config/cns.vmware.com_cnsnodevmbatchattachments.yaml index a863ce5f8c..6bf9a58e6d 100644 --- a/pkg/apis/cnsoperator/config/cns.vmware.com_cnsnodevmbatchattachments.yaml +++ b/pkg/apis/cnsoperator/config/cns.vmware.com_cnsnodevmbatchattachments.yaml @@ -8,16 +8,22 @@ metadata: spec: group: cns.vmware.com names: - kind: CnsNodeVmBatchAttachment - listKind: CnsNodeVmBatchAttachmentList + kind: CnsNodeVMBatchAttachment + listKind: CnsNodeVMBatchAttachmentList plural: cnsnodevmbatchattachments + shortNames: + - batchattach singular: cnsnodevmbatchattachment scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - jsonPath: .spec.nodeUUID + name: NodeUUID + type: string + name: v1alpha1 schema: openAPIV3Schema: - description: CnsNodeVmBatchAttachment is the Schema for the cnsnodevmbatchattachments + description: CnsNodeVMBatchAttachment is the Schema for the cnsnodevmbatchattachments API properties: apiVersion: @@ -38,13 +44,13 @@ spec: metadata: type: object spec: - description: CnsNodeVmBatchAttachmentSpec defines the desired state of - CnsNodeVmBatchAttachment + description: CnsNodeVMBatchAttachmentSpec defines the desired state of + CnsNodeVMBatchAttachment properties: - nodeuuid: + nodeUUID: description: |- NodeUUID indicates the UUID of the node where the volume needs to be attached to. - Here NodeUUID is the bios UUID of the node. + Here NodeUUID is the instance UUID of the node. type: string volumes: description: VolumeSpec reflects the desired state for each volume. @@ -63,18 +69,27 @@ spec: controllerKey: description: ControllerKey is the object key for the controller object for this device. - type: string + format: int32 + type: integer diskMode: description: DiskMode is the desired mode to use when attaching the volume + enum: + - independent_persistent + - persistent + - independent_nonpersistent type: string sharingMode: - description: SharingMode indicates the shraring mode if - the virtual disk while attaching. + description: SharingMode indicates the sharing mode if the + virtual disk while attaching. + enum: + - sharingMultiWriter + - sharingNone type: string unitNumber: description: UnitNumber of this device on its controller. - type: string + format: int32 + type: integer required: - claimName type: object @@ -87,12 +102,12 @@ spec: - name x-kubernetes-list-type: map required: - - nodeuuid + - nodeUUID - volumes type: object status: - description: CnsNodeVmBatchAttachmentStatus defines the observed state - of CnsNodeVmBatchAttachment + description: CnsNodeVMBatchAttachmentStatus defines the observed state + of CnsNodeVMBatchAttachment properties: error: description: Error is the overall error status for the instance. @@ -108,8 +123,13 @@ spec: description: PersistentVolumeClaim contains details about the volume's current state. properties: + DiskUUID: + description: DiskUUID is the ID obtained when volume is + attached to a VM. + type: string attached: description: |- + Attached indicates the attach status of a PVC. If volume is not attached, Attached will be set to false. If volume is attached, Attached will be set to true. If volume is detached successfully, its entry will be removed from VolumeStatus. @@ -120,10 +140,6 @@ spec: cnsVolumeId: description: CnsVolumeID is the volume ID for the PVC. type: string - diskuuid: - description: Diskuuid is the ID obtained when volume is - attached to a VM. - type: string error: description: Error indicates the error which may have occurred during attach/detach. @@ -151,4 +167,4 @@ status: kind: "" plural: "" conditions: [] - storedVersions: [] + storedVersions: [] \ No newline at end of file diff --git a/pkg/apis/cnsoperator/config/config.go b/pkg/apis/cnsoperator/config/config.go index 9f9b30e054..12dd335afb 100644 --- a/pkg/apis/cnsoperator/config/config.go +++ b/pkg/apis/cnsoperator/config/config.go @@ -8,7 +8,7 @@ var EmbedCnsNodeVmAttachmentCRFile embed.FS const EmbedCnsNodeVmAttachmentCRFileName = "cns.vmware.com_cnsnodevmattachments.yaml" //go:embed cns.vmware.com_cnsnodevmbatchattachments.yaml -var EmbedCnsNodeVmBatchAttachmentCRFile embed.FS +var EmbedCnsNodeVMBatchAttachmentCRFile embed.FS const EmbedCnsNodeVmABatchttachmentCRFileName = "cns.vmware.com_cnsnodevmbatchattachments.yaml" diff --git a/pkg/apis/cnsoperator/register.go b/pkg/apis/cnsoperator/register.go index 08975973fa..cfddb142da 100644 --- a/pkg/apis/cnsoperator/register.go +++ b/pkg/apis/cnsoperator/register.go @@ -51,8 +51,8 @@ var ( CnsNodeVMAttachmentSingular = "cnsnodevmattachment" // CnsNodeVMAttachmentPlural is plural of CnsNodeVmAttachment CnsNodeVMAttachmentPlural = "cnsnodevmattachments" - // CnsNodeVmBatchAttachmentPlural is plural of CnsNodeVmBatchAttachment - CnsNodeVmBatchAttachmentPlural = "cnsnodevmbatchattachments" + // CnsNodeVMBatchAttachmentPlural is plural of CnsNodeVMBatchAttachment + CnsNodeVMBatchAttachmentPlural = "cnsnodevmbatchattachments" // CnsVolumeMetadataSingular is Singular of CnsVolumeMetadata CnsVolumeMetadataSingular = "cnsvolumemetadata" // CnsVolumeMetadataPlural is plural of CnsVolumeMetadata @@ -133,8 +133,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes( SchemeGroupVersion, - &cnsnodevmbatchattachmentv1alpha1.CnsNodeVmBatchAttachment{}, - &cnsnodevmbatchattachmentv1alpha1.CnsNodeVmBatchAttachmentList{}, + &cnsnodevmbatchattachmentv1alpha1.CnsNodeVMBatchAttachment{}, + &cnsnodevmbatchattachmentv1alpha1.CnsNodeVMBatchAttachmentList{}, ) scheme.AddKnownTypes( diff --git a/pkg/common/cns-lib/volume/manager.go b/pkg/common/cns-lib/volume/manager.go index ab6706cfcd..22b52fcea4 100644 --- a/pkg/common/cns-lib/volume/manager.go +++ b/pkg/common/cns-lib/volume/manager.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "strconv" "strings" "sync" "time" @@ -3532,23 +3531,11 @@ func constructBatchAttachSpecList(ctx context.Context, vm *cnsvsphere.VirtualMac } // Set controllerKey and unitNumber only if they are provided by the user. - if volume.ControllerKey != "" { - // Convert to int64 - controllerKey, err := strconv.ParseInt(volume.ControllerKey, 10, 64) - if err != nil { - log.Errorf("failed to convert controllerKey %s to integer", controllerKey) - return cnsAttachSpecList, err - } - cnsAttachDetachSpec.ControllerKey = controllerKey + if volume.ControllerKey != nil { + cnsAttachDetachSpec.ControllerKey = volume.ControllerKey } - if volume.UnitNumber != "" { - // Convert to int64 - unitNumber, err := strconv.ParseInt(volume.UnitNumber, 10, 64) - if err != nil { - log.Errorf("failed to convert unitNumber %s to integer", unitNumber) - return cnsAttachSpecList, err - } - cnsAttachDetachSpec.UnitNumber = unitNumber + if volume.UnitNumber != nil { + cnsAttachDetachSpec.UnitNumber = volume.UnitNumber } cnsAttachSpecList = append(cnsAttachSpecList, cnsAttachDetachSpec) } diff --git a/pkg/common/cns-lib/volume/util.go b/pkg/common/cns-lib/volume/util.go index 6b8fb6d372..c964027de6 100644 --- a/pkg/common/cns-lib/volume/util.go +++ b/pkg/common/cns-lib/volume/util.go @@ -41,14 +41,14 @@ import ( type BatchAttachRequest struct { // The volume ID for the given PVC. VolumeID string - // SharingMode indicates the shraring mode if the virtual disk while attaching. + // SharingMode indicates the sharing mode if the virtual disk while attaching. SharingMode string // DiskMode is the desired mode to use when attaching the volume DiskMode string // ControllerKey is the object key for the controller object for this device. - ControllerKey string + ControllerKey *int32 // UnitNumber of this device on its controller. - UnitNumber string + UnitNumber *int32 } // BatchAttachResult is the result of calling batch CNS Attach for multiple volumes. diff --git a/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go b/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go index f6558b949a..4a6ea52450 100644 --- a/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go +++ b/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go @@ -95,12 +95,12 @@ func Add(mgr manager.Manager, clusterFlavor cnstypes.CnsClusterFlavor, configInfo *config.ConfigurationInfo, volumeManager volumes.Manager) error { ctx, log := logger.GetNewContextWithLogger() if clusterFlavor != cnstypes.CnsClusterFlavorWorkload { - log.Debug("Not initializing the CnsNodeVmBatchAttachment Controller as its a non-WCP CSI deployment") + log.Debug("Not initializing the CnsNodeVMBatchAttachment Controller as its a non-WCP CSI deployment") return nil } if !commonco.ContainerOrchestratorUtility.IsFSSEnabled(ctx, common.SharedDiskFss) { - log.Debug("Not initializing the CnsNodeVmBatchAttachment Controller as SharedDisk FSS is not enabled") + log.Debug("Not initializing the CnsNodeVMBatchAttachment Controller as SharedDisk FSS is not enabled") return nil } @@ -157,7 +157,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { // Create a new controller. err := ctrl.NewControllerManagedBy(mgr). Named("cnsnodevmbatchattachment-controller"). - For(&v1alpha1.CnsNodeVmBatchAttachment{}). + For(&v1alpha1.CnsNodeVMBatchAttachment{}). WithEventFilter(predicate.GenerationChangedPredicate{}). WithOptions(controller.Options{ MaxConcurrentReconciles: maxWorkerThreads, @@ -173,7 +173,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { return nil } -// Reconciler reconciles a CnsNodeVmBatchAttachment object. +// Reconciler reconciles a CnsNodeVMBatchAttachment object. type Reconciler struct { // This client, initialized using mgr.Client() above, is a split client // that reads objects from the cache and writes to the apiserver @@ -188,13 +188,13 @@ type Reconciler struct { instanceLock sync.Map } -// Reconcile over CnsNodeVmBatchAttachment CR. +// Reconcile over CnsNodeVMBatchAttachment CR. // Reconcile stops when all volumes have been attached or detached successfully. func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { ctx = logger.NewContextWithLogger(ctx) reconcileLog := logger.GetLogger(ctx) - reconcileLog.Infof("Received Reconcile for CnsNodeVmBatchAttachment request: %q", request.NamespacedName) + reconcileLog.Infof("Received Reconcile for CnsNodeVMBatchAttachment request: %q", request.NamespacedName) // Creating new context as kubernetes supplied context can get canceled. // This is required to ensure CNS operations won't get prematurely canceled by the controller runtime’s @@ -229,20 +229,20 @@ func (r *Reconciler) Reconcile(ctx context.Context, log.Infof("Released lock for instance %s", request.NamespacedName.String()) }() - instance := &v1alpha1.CnsNodeVmBatchAttachment{} + instance := &v1alpha1.CnsNodeVMBatchAttachment{} err := r.client.Get(batchAttachCtx, request.NamespacedName, instance) if err != nil { if apierrors.IsNotFound(err) { - log.Info("CnsNodeVmBatchAttachment resource not found. Ignoring since object must be deleted.") + log.Info("CnsNodeVMBatchAttachment resource not found. Ignoring since object must be deleted.") return reconcile.Result{}, nil } - log.Errorf("Error reading the CnsNodeVmBatchAttachment with name: %q on namespace: %q. Err: %+v", + log.Errorf("Error reading the CnsNodeVMBatchAttachment with name: %q on namespace: %q. Err: %+v", request.Name, request.Namespace, err) // Error reading the object - return with err. return reconcile.Result{RequeueAfter: timeout}, nil } - log.Debugf("Reconciling CnsNodeVmBatchAttachment with Request.Name: %q instance %q timeout %q seconds", + log.Debugf("Reconciling CnsNodeVMBatchAttachment with Request.Name: %q instance %q timeout %q seconds", request.Name, instance.Name, timeout) // Initialise volumeStatus if it is set to nil @@ -267,13 +267,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, if vm == nil { // If VM is nil, it means it is deleted from the vCenter. if instance.DeletionTimestamp == nil { - // If VM is deleted from the VC but CnsNodeVmBatchAttachment is not being deleted, it is an error. + // If VM is deleted from the VC but CnsNodeVMBatchAttachment is not being deleted, it is an error. err := fmt.Errorf("virtual Machine with UUID %s on vCenter does not exist. "+ "Vm is CR is deleted or is being deleted but"+ - "CnsNodeVmBatchAttachmentInstance %s is not being deleted", instance.Spec.NodeUUID, instance.Name) + "CnsNodeVMBatchAttachmentInstance %s is not being deleted", instance.Spec.NodeUUID, instance.Name) return r.completeReconciliationWithError(batchAttachCtx, instance, request.NamespacedName, timeout, err) } - // If CnsNodeVmBatchAttachment is also being deleted, then all volumes on the instance can be considered detached. + // If CnsNodeVMBatchAttachment is also being deleted, then all volumes on the instance can be considered detached. log.Infof("VM is deleted from vCenter and instance %s deletion timestamp. Considering all volumes as detached.", request.NamespacedName) } else { @@ -306,7 +306,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, patchErr := removeFinalizerFromCRDInstance(batchAttachCtx, instance, r.client) if patchErr != nil { recordEvent(batchAttachCtx, r, instance, v1.EventTypeWarning, patchErr.Error()) - log.Errorf("failed to update CnsNodeVmBatchAttachment %s. Err: +%v", instance.Name, patchErr) + log.Errorf("failed to update CnsNodeVMBatchAttachment %s. Err: +%v", instance.Name, patchErr) return reconcile.Result{RequeueAfter: timeout}, nil } log.Infof("Successfully removed finalizer %s from instance %s", @@ -316,7 +316,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, delete(backOffDuration, request.NamespacedName) backOffDurationMapMutex.Unlock() - msg := fmt.Sprintf("ReconcileCnsNodeVmBatchAttachment: Successfully processed instance %s", + msg := fmt.Sprintf("ReconcileCnsNodeVMBatchAttachment: Successfully processed instance %s", request.NamespacedName.String()) recordEvent(batchAttachCtx, r, instance, v1.EventTypeNormal, msg) return reconcile.Result{}, nil @@ -362,7 +362,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, return r.completeReconciliationWithSuccess(batchAttachCtx, instance, request.NamespacedName, timeout) } - reconcileLog.Infof("Reconcile for CnsNodeVmBatchAttachment request: %q completed.", request.NamespacedName) + reconcileLog.Infof("Reconcile for CnsNodeVMBatchAttachment request: %q completed.", request.NamespacedName) return reconcile.Result{}, nil } @@ -370,7 +370,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, // As the instance is being deleted, we do not need to attach anything. func (r *Reconciler) reconcileInstanceWithDeletionTimestamp(ctx context.Context, k8sClient kubernetes.Interface, - instance *v1alpha1.CnsNodeVmBatchAttachment, + instance *v1alpha1.CnsNodeVMBatchAttachment, volumesToDetach map[string]string, vm *cnsvsphere.VirtualMachine) error { log := logger.GetLogger(ctx) @@ -389,7 +389,7 @@ func (r *Reconciler) reconcileInstanceWithDeletionTimestamp(ctx context.Context, // and CNS detach for the volumes volumesToDetach. func (r *Reconciler) reconcileInstanceWithoutDeletionTimestamp(ctx context.Context, k8sClient kubernetes.Interface, - instance *v1alpha1.CnsNodeVmBatchAttachment, + instance *v1alpha1.CnsNodeVMBatchAttachment, volumesToDetach map[string]string, vm *cnsvsphere.VirtualMachine) error { log := logger.GetLogger(ctx) @@ -418,7 +418,7 @@ func (r *Reconciler) reconcileInstanceWithoutDeletionTimestamp(ctx context.Conte func (r *Reconciler) processDetach(ctx context.Context, k8sClient kubernetes.Interface, vm *cnsvsphere.VirtualMachine, - instance *v1alpha1.CnsNodeVmBatchAttachment, volumesToDetach map[string]string) error { + instance *v1alpha1.CnsNodeVMBatchAttachment, volumesToDetach map[string]string) error { log := logger.GetLogger(ctx) log.Debugf("Calling detach volume for PVC %+v", volumesToDetach) @@ -440,7 +440,7 @@ func (r *Reconciler) processDetach(ctx context.Context, func (r *Reconciler) detachVolumes(ctx context.Context, k8sClient kubernetes.Interface, vm *cnsvsphere.VirtualMachine, volumesToDetach map[string]string, - instance *v1alpha1.CnsNodeVmBatchAttachment) []string { + instance *v1alpha1.CnsNodeVMBatchAttachment) []string { log := logger.GetLogger(ctx) volumesThatFailedToDetach := make([]string, 0) @@ -482,7 +482,7 @@ func (r *Reconciler) detachVolumes(ctx context.Context, // removes its entry from the instance status if it is successful. // If removing the finalizer fails, it adds the volume to volumesThatFailedToDetach list. func removeFinalizerAndStatusEntry(ctx context.Context, client client.Client, k8sClient kubernetes.Interface, - instance *v1alpha1.CnsNodeVmBatchAttachment, pvc string, + instance *v1alpha1.CnsNodeVMBatchAttachment, pvc string, volumesThatFailedToDetach []string) []string { log := logger.GetLogger(ctx) @@ -503,7 +503,7 @@ func removeFinalizerAndStatusEntry(ctx context.Context, client client.Client, k8 // and then calls CNS batch attach for them. func (r *Reconciler) processBatchAttach(ctx context.Context, k8sClient kubernetes.Interface, vm *cnsvsphere.VirtualMachine, - instance *v1alpha1.CnsNodeVmBatchAttachment) error { + instance *v1alpha1.CnsNodeVMBatchAttachment) error { log := logger.GetLogger(ctx) // Construct batch attach request @@ -555,7 +555,7 @@ func (r *Reconciler) processBatchAttach(ctx context.Context, k8sClient kubernete // appropriately and logs the message. // backOffDuration is reset to 1 second on success and doubled on failure. func recordEvent(ctx context.Context, r *Reconciler, - instance *v1alpha1.CnsNodeVmBatchAttachment, eventtype string, msg string) { + instance *v1alpha1.CnsNodeVMBatchAttachment, eventtype string, msg string) { log := logger.GetLogger(ctx) namespacedName := types.NamespacedName{ Name: instance.Name, @@ -581,7 +581,7 @@ func recordEvent(ctx context.Context, r *Reconciler, } // completeReconciliationWithSuccess updates the instance with success and records successful event as well. -func (r *Reconciler) completeReconciliationWithSuccess(ctx context.Context, instance *v1alpha1.CnsNodeVmBatchAttachment, +func (r *Reconciler) completeReconciliationWithSuccess(ctx context.Context, instance *v1alpha1.CnsNodeVMBatchAttachment, namespaceName types.NamespacedName, timeout time.Duration) (reconcile.Result, error) { log := logger.GetLogger(ctx) @@ -589,7 +589,7 @@ func (r *Reconciler) completeReconciliationWithSuccess(ctx context.Context, inst updateErr := updateInstanceStatus(ctx, r.client, instance) if updateErr != nil { recordEvent(ctx, r, instance, v1.EventTypeWarning, updateErr.Error()) - log.Errorf("failed to update CnsNodeVmBatchAttachment %s. Err: +%v", namespaceName, updateErr) + log.Errorf("failed to update CnsNodeVMBatchAttachment %s. Err: +%v", namespaceName, updateErr) return reconcile.Result{RequeueAfter: timeout}, nil } @@ -597,21 +597,21 @@ func (r *Reconciler) completeReconciliationWithSuccess(ctx context.Context, inst delete(backOffDuration, namespaceName) backOffDurationMapMutex.Unlock() - msg := fmt.Sprintf("ReconcileCnsNodeVmBatchAttachment: Successfully processed instance %s "+ + msg := fmt.Sprintf("ReconcileCnsNodeVMBatchAttachment: Successfully processed instance %s "+ "in namespace %q.", namespaceName, namespaceName) recordEvent(ctx, r, instance, v1.EventTypeNormal, msg) return reconcile.Result{}, nil } // completeReconciliationWithError updates the instance with failure and records failure event as well. -func (r *Reconciler) completeReconciliationWithError(ctx context.Context, instance *v1alpha1.CnsNodeVmBatchAttachment, +func (r *Reconciler) completeReconciliationWithError(ctx context.Context, instance *v1alpha1.CnsNodeVMBatchAttachment, namespaceName types.NamespacedName, timeout time.Duration, err error) (reconcile.Result, error) { log := logger.GetLogger(ctx) instance.Status.Error = err.Error() updateErr := updateInstanceStatus(ctx, r.client, instance) if updateErr != nil { recordEvent(ctx, r, instance, v1.EventTypeWarning, updateErr.Error()) - log.Errorf("failed to update CnsNodeVmBatchAttachment %s. Err: +%v", namespaceName, updateErr) + log.Errorf("failed to update CnsNodeVMBatchAttachment %s. Err: +%v", namespaceName, updateErr) return reconcile.Result{RequeueAfter: timeout}, nil } recordEvent(ctx, r, instance, v1.EventTypeWarning, err.Error()) diff --git a/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go b/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go index d6695c9b59..c2fcf7b3b9 100644 --- a/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go +++ b/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go @@ -56,13 +56,13 @@ const ( // removeFinalizerFromCRDInstance will remove the CNS Finalizer, cns.vmware.com, // from a given nodevmbatchattachment instance. func removeFinalizerFromCRDInstance(ctx context.Context, - instance *v1alpha1.CnsNodeVmBatchAttachment, + instance *v1alpha1.CnsNodeVMBatchAttachment, c client.Client) error { log := logger.GetLogger(ctx) finalizersOnInstance := instance.Finalizers for i, finalizer := range instance.Finalizers { if finalizer == cnsoperatortypes.CNSFinalizer { - log.Infof("Removing %q finalizer from CnsNodeVmBatchAttachment instance with name: %q on namespace: %q", + log.Infof("Removing %q finalizer from CnsNodeVMBatchAttachment instance with name: %q on namespace: %q", cnsoperatortypes.CNSFinalizer, instance.Name, instance.Namespace) finalizersOnInstance = append(instance.Finalizers[:i], instance.Finalizers[i+1:]...) break @@ -79,7 +79,7 @@ func getNamespacedPvcName(namespace string, pvcName string) string { // getVolumesToDetachFromInstance finds out which are the volumes to detach by finding out which are // the volumes present in attachedFCDs but not in spec of the instance. func getVolumesToDetachFromInstance(ctx context.Context, - instance *v1alpha1.CnsNodeVmBatchAttachment, + instance *v1alpha1.CnsNodeVMBatchAttachment, attachedFCDs map[string]bool, volumeIdsInSpec map[string]string) (pvcsToDetach map[string]string, err error) { log := logger.GetLogger(ctx) @@ -136,7 +136,7 @@ func getVolumesToDetachFromInstance(ctx context.Context, func removeStaleEntriesFromInstanceStatus(ctx context.Context, client client.Client, k8sClient kubernetes.Interface, - instance *v1alpha1.CnsNodeVmBatchAttachment, + instance *v1alpha1.CnsNodeVMBatchAttachment, pvcsToDetach map[string]string, volumeNamesInSpec map[string]string) error { log := logger.GetLogger(ctx) @@ -170,7 +170,7 @@ func removeStaleEntriesFromInstanceStatus(ctx context.Context, // getVolumesToDetach returns list of volumes to detach by taking a diff of // volumes in spec and in attachedFCDs list. func getVolumesToDetachForVmFromVC(ctx context.Context, - instance *v1alpha1.CnsNodeVmBatchAttachment, + instance *v1alpha1.CnsNodeVMBatchAttachment, client client.Client, k8sClient kubernetes.Interface, attachedFCDs map[string]bool) (map[string]string, error) { @@ -212,7 +212,7 @@ func getVolumesToDetachForVmFromVC(ctx context.Context, // But they both have the same entry in the status which is wrong. By adding the suffix, // the volume name entry for the PVC getting detached becomes unique. func updatePvcStatusEntryName(ctx context.Context, - instance *v1alpha1.CnsNodeVmBatchAttachment, pvcsToDetach map[string]string) { + instance *v1alpha1.CnsNodeVMBatchAttachment, pvcsToDetach map[string]string) { log := logger.GetLogger(ctx) for i, volume := range instance.Status.VolumeStatus { @@ -229,11 +229,11 @@ func updatePvcStatusEntryName(ctx context.Context, // updateInstanceStatus updates the given nodevmbatchattachment instance's status. func updateInstanceStatus(ctx context.Context, cnsoperatorclient client.Client, - instance *v1alpha1.CnsNodeVmBatchAttachment) error { + instance *v1alpha1.CnsNodeVMBatchAttachment) error { log := logger.GetLogger(ctx) err := cnsoperatorclient.Status().Update(ctx, instance) if err != nil { - log.Errorf("failed to update CnsNodeVmBatchAttachment instance: %q on namespace: %q. Error: %+v", + log.Errorf("failed to update CnsNodeVMBatchAttachment instance: %q on namespace: %q. Error: %+v", instance.Name, instance.Namespace, err) return err } @@ -243,7 +243,7 @@ func updateInstanceStatus(ctx context.Context, cnsoperatorclient client.Client, // updateInstanceWithAttachVolumeResult finds the given's volumeName's status in the instance status // and updates it with error. // It will add a new status for the volume if it does not already exist. -func updateInstanceWithAttachVolumeResult(instance *v1alpha1.CnsNodeVmBatchAttachment, +func updateInstanceWithAttachVolumeResult(instance *v1alpha1.CnsNodeVMBatchAttachment, volumeName string, pvc string, result volumes.BatchAttachResult) { errMsg := "" @@ -260,7 +260,7 @@ func updateInstanceWithAttachVolumeResult(instance *v1alpha1.CnsNodeVmBatchAttac Attached: attached, Error: errMsg, CnsVolumeID: result.VolumeID, - Diskuuid: result.DiskUUID, + DiskUUID: result.DiskUUID, }, } @@ -279,7 +279,7 @@ func updateInstanceWithAttachVolumeResult(instance *v1alpha1.CnsNodeVmBatchAttac // updateInstanceWithErrorVolumeName finds the given's PVC's status in the instance status // and updates it with error. -func updateInstanceWithErrorForPvc(instance *v1alpha1.CnsNodeVmBatchAttachment, +func updateInstanceWithErrorForPvc(instance *v1alpha1.CnsNodeVMBatchAttachment, pvc string, errMsg string) { for i, volume := range instance.Status.VolumeStatus { if volume.PersistentVolumeClaim.ClaimName != pvc { @@ -291,7 +291,7 @@ func updateInstanceWithErrorForPvc(instance *v1alpha1.CnsNodeVmBatchAttachment, } // deleteVolumeFromStatus finds the status of the given volumeName in an instance and deletes its entry. -func deleteVolumeFromStatus(pvc string, instance *v1alpha1.CnsNodeVmBatchAttachment) { +func deleteVolumeFromStatus(pvc string, instance *v1alpha1.CnsNodeVMBatchAttachment) { instance.Status.VolumeStatus = slices.DeleteFunc(instance.Status.VolumeStatus, func(e v1alpha1.VolumeStatus) bool { return e.PersistentVolumeClaim.ClaimName == pvc @@ -303,7 +303,7 @@ func deleteVolumeFromStatus(pvc string, instance *v1alpha1.CnsNodeVmBatchAttachm // 1. volumeID to PVC name // 2. VolumeName to PVC name func getVolumeNameVolumeIdMapsInSpec(ctx context.Context, - instance *v1alpha1.CnsNodeVmBatchAttachment) (volumeIdsInSpec map[string]string, + instance *v1alpha1.CnsNodeVMBatchAttachment) (volumeIdsInSpec map[string]string, volumeNamesInSpec map[string]string, err error) { log := logger.GetLogger(ctx) @@ -325,7 +325,7 @@ func getVolumeNameVolumeIdMapsInSpec(ctx context.Context, } // getPvcsInSpec returns map of PVCs and their volumeIDs. -func getPvcsInSpec(instance *v1alpha1.CnsNodeVmBatchAttachment) (map[string]string, error) { +func getPvcsInSpec(instance *v1alpha1.CnsNodeVMBatchAttachment) (map[string]string, error) { pvcsInSpec := make(map[string]string) for _, volume := range instance.Spec.Volumes { namespacedPvcName := getNamespacedPvcName(instance.Namespace, volume.PersistentVolumeClaim.ClaimName) @@ -379,7 +379,7 @@ func listAttachedFcdsForVM(ctx context.Context, // constructs the batchAttach request for each of them. // It also validates each of the requests to make sure user input is correct. func constructBatchAttachRequest(ctx context.Context, - instance *v1alpha1.CnsNodeVmBatchAttachment) (pvcsInSpec map[string]string, + instance *v1alpha1.CnsNodeVMBatchAttachment) (pvcsInSpec map[string]string, volumeIdsInSpec map[string]string, batchAttachRequest []volumes.BatchAttachRequest, err error) { log := logger.GetLogger(ctx) @@ -427,7 +427,7 @@ func constructBatchAttachRequest(ctx context.Context, // If VM retrieval from vCenter fails with NotFound error, // then it is not considered an error because VM CR is probably being deleted. func getVmObject(ctx context.Context, client client.Client, configInfo config.ConfigurationInfo, - instance *v1alpha1.CnsNodeVmBatchAttachment) (*cnsvsphere.VirtualMachine, error) { + instance *v1alpha1.CnsNodeVMBatchAttachment) (*cnsvsphere.VirtualMachine, error) { log := logger.GetLogger(ctx) // Get vm from vCenter. @@ -447,7 +447,7 @@ func getVmObject(ctx context.Context, client client.Client, configInfo config.Co // getVolumesToDetach checks if: // Instance is being deleted, then it adds all the volumes in the spec for detach. // If instance is not being deleted then finds the volumes to be detached by querying vCenter. -func getVolumesToDetach(ctx context.Context, instance *v1alpha1.CnsNodeVmBatchAttachment, +func getVolumesToDetach(ctx context.Context, instance *v1alpha1.CnsNodeVMBatchAttachment, vm *cnsvsphere.VirtualMachine, client client.Client, k8sClient kubernetes.Interface) (map[string]string, error) { log := logger.GetLogger(ctx) @@ -476,7 +476,7 @@ func getVolumesToDetach(ctx context.Context, instance *v1alpha1.CnsNodeVmBatchAt // which have to be detached from the VM. func getVolumesToDetachFromVM(ctx context.Context, client client.Client, k8sClient kubernetes.Interface, - instance *v1alpha1.CnsNodeVmBatchAttachment, + instance *v1alpha1.CnsNodeVMBatchAttachment, vm *cnsvsphere.VirtualMachine) (map[string]string, error) { log := logger.GetLogger(ctx) diff --git a/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_test.go b/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_test.go index f1a51f87aa..8b53bf7999 100644 --- a/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_test.go +++ b/pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_test.go @@ -48,25 +48,25 @@ import ( var ( testBufferSize = 1024 - testCnsNodeVmBatchAttachmentName = "test-cnsnodevmbatchattachemnt" + testCnsNodeVMBatchAttachmentName = "test-cnsnodevmbatchattachemnt" testNamespace = "test-ns" ) -// setupTestCnsNodeVmBatchAttachment created CnsNodeVmBatchAttachment CR with volumes for testing. -func setupTestCnsNodeVmBatchAttachment() v1alpha1.CnsNodeVmBatchAttachment { +// setupTestCnsNodeVMBatchAttachment created CnsNodeVMBatchAttachment CR with volumes for testing. +func setupTestCnsNodeVMBatchAttachment() v1alpha1.CnsNodeVMBatchAttachment { var ( testNodeUUID = "test-1" disk1 = "disk-1" disk2 = "disk-2" pvc1 = "pvc-1" pvc2 = "pvc-2" - testCnsNodeVmBatchAttachment = v1alpha1.CnsNodeVmBatchAttachment{ + testCnsNodeVMBatchAttachment = v1alpha1.CnsNodeVMBatchAttachment{ ObjectMeta: metav1.ObjectMeta{ - Name: testCnsNodeVmBatchAttachmentName, + Name: testCnsNodeVMBatchAttachmentName, Namespace: testNamespace, ResourceVersion: "1", }, - Spec: v1alpha1.CnsNodeVmBatchAttachmentSpec{ + Spec: v1alpha1.CnsNodeVMBatchAttachmentSpec{ NodeUUID: testNodeUUID, Volumes: []v1alpha1.VolumeSpec{ { @@ -83,13 +83,13 @@ func setupTestCnsNodeVmBatchAttachment() v1alpha1.CnsNodeVmBatchAttachment { }, }, }, - Status: v1alpha1.CnsNodeVmBatchAttachmentStatus{ + Status: v1alpha1.CnsNodeVMBatchAttachmentStatus{ VolumeStatus: []v1alpha1.VolumeStatus{ { Name: disk1, PersistentVolumeClaim: v1alpha1.PersistentVolumeClaimStatus{ ClaimName: pvc1, - Diskuuid: "123456", + DiskUUID: "123456", CnsVolumeID: "67890", Attached: true, }, @@ -98,7 +98,7 @@ func setupTestCnsNodeVmBatchAttachment() v1alpha1.CnsNodeVmBatchAttachment { Name: disk2, PersistentVolumeClaim: v1alpha1.PersistentVolumeClaimStatus{ ClaimName: pvc2, - Diskuuid: "123456", + DiskUUID: "123456", CnsVolumeID: "67890", Attached: true, }, @@ -108,13 +108,13 @@ func setupTestCnsNodeVmBatchAttachment() v1alpha1.CnsNodeVmBatchAttachment { } ) - return testCnsNodeVmBatchAttachment + return testCnsNodeVMBatchAttachment } -func setTestEnvironment(testCnsNodeVmBatchAttachment *v1alpha1.CnsNodeVmBatchAttachment, +func setTestEnvironment(testCnsNodeVMBatchAttachment *v1alpha1.CnsNodeVMBatchAttachment, setDeletionTimestamp bool) *Reconciler { - cnsNodeVmBatchAttachment := testCnsNodeVmBatchAttachment.DeepCopy() + cnsNodeVmBatchAttachment := testCnsNodeVMBatchAttachment.DeepCopy() //objs := []runtime.Object{cnsNodeVmBatchAttachment} if setDeletionTimestamp { @@ -200,16 +200,16 @@ func getClientSetWithPvc() *k8sFake.Clientset { return clientset } -func TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsError(t *testing.T) { - t.Run("TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsError", func(t *testing.T) { - testCnsNodeVmBatchAttachment := setupTestCnsNodeVmBatchAttachment() - testCnsNodeVmBatchAttachment.Spec.NodeUUID = "test-2" +func TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsError(t *testing.T) { + t.Run("TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsError", func(t *testing.T) { + testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment() + testCnsNodeVMBatchAttachment.Spec.NodeUUID = "test-2" - r := setTestEnvironment(&testCnsNodeVmBatchAttachment, false) + r := setTestEnvironment(&testCnsNodeVMBatchAttachment, false) req := reconcile.Request{ NamespacedName: types.NamespacedName{ - Name: testCnsNodeVmBatchAttachmentName, + Name: testCnsNodeVMBatchAttachmentName, Namespace: testNamespace, }, } @@ -223,27 +223,27 @@ func TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsError(t *testing.T) { expectedReconcileResult := reconcile.Result{RequeueAfter: time.Second} assert.Equal(t, expectedReconcileResult, res) - updatedCnsNodeVmBatchAttachment := &v1alpha1.CnsNodeVmBatchAttachment{} - if err := r.client.Get(context.TODO(), req.NamespacedName, updatedCnsNodeVmBatchAttachment); err != nil { + updatedCnsNodeVMBatchAttachment := &v1alpha1.CnsNodeVMBatchAttachment{} + if err := r.client.Get(context.TODO(), req.NamespacedName, updatedCnsNodeVMBatchAttachment); err != nil { t.Fatalf("failed to get cnsnodevmbatchattachemnt instance") } expectedReconcileError := fmt.Errorf("some error occurred while getting VM") - assert.EqualError(t, expectedReconcileError, updatedCnsNodeVmBatchAttachment.Status.Error) + assert.EqualError(t, expectedReconcileError, updatedCnsNodeVMBatchAttachment.Status.Error) }) } -func TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsNotFoundError(t *testing.T) { +func TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsNotFoundError(t *testing.T) { - t.Run("TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsNotFoundError", func(t *testing.T) { - testCnsNodeVmBatchAttachment := setupTestCnsNodeVmBatchAttachment() - testCnsNodeVmBatchAttachment.Spec.NodeUUID = "test-3" + t.Run("TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsNotFoundError", func(t *testing.T) { + testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment() + testCnsNodeVMBatchAttachment.Spec.NodeUUID = "test-3" - r := setTestEnvironment(&testCnsNodeVmBatchAttachment, true) + r := setTestEnvironment(&testCnsNodeVMBatchAttachment, true) req := reconcile.Request{ NamespacedName: types.NamespacedName{ - Name: testCnsNodeVmBatchAttachmentName, + Name: testCnsNodeVMBatchAttachmentName, Namespace: testNamespace, }, } @@ -267,8 +267,8 @@ func TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsNotFoundError(t *testing. assert.Equal(t, expectedReconcileResult, res) assert.Equal(t, expectedReconcileError, err) - updatedCnsNodeVmBatchAttachment := &v1alpha1.CnsNodeVmBatchAttachment{} - err = r.client.Get(context.TODO(), req.NamespacedName, updatedCnsNodeVmBatchAttachment) + updatedCnsNodeVMBatchAttachment := &v1alpha1.CnsNodeVMBatchAttachment{} + err = r.client.Get(context.TODO(), req.NamespacedName, updatedCnsNodeVMBatchAttachment) if err == nil { t.Fatalf("failed to get cnsnodevmbatchattachemnt instance") } @@ -277,23 +277,23 @@ func TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsNotFoundError(t *testing. if statusErr, ok := err.(*errors.StatusError); ok { assert.Equal(t, metav1.StatusReasonNotFound, statusErr.Status().Reason) } else { - t.Fatalf("Unable to verify CnsNodeVmBatchAttachment error") + t.Fatalf("Unable to verify CnsNodeVMBatchAttachment error") } }) } -func TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsNotFoundErrorAndInstanceIsNotDeleted(t *testing.T) { - t.Run("TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsNotFoundErrorAndInstanceIsNotDeleted", +func TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsNotFoundErrorAndInstanceIsNotDeleted(t *testing.T) { + t.Run("TestCnsNodeVMBatchAttachmentWhenVmOnVcenterReturnsNotFoundErrorAndInstanceIsNotDeleted", func(t *testing.T) { - testCnsNodeVmBatchAttachment := setupTestCnsNodeVmBatchAttachment() + testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment() nodeUUID := "test-3" - testCnsNodeVmBatchAttachment.Spec.NodeUUID = nodeUUID + testCnsNodeVMBatchAttachment.Spec.NodeUUID = nodeUUID - r := setTestEnvironment(&testCnsNodeVmBatchAttachment, false) + r := setTestEnvironment(&testCnsNodeVMBatchAttachment, false) req := reconcile.Request{ NamespacedName: types.NamespacedName{ - Name: testCnsNodeVmBatchAttachmentName, + Name: testCnsNodeVMBatchAttachmentName, Namespace: testNamespace, }, } @@ -313,24 +313,24 @@ func TestCnsNodeVmBatchAttachmentWhenVmOnVcenterReturnsNotFoundErrorAndInstanceI expectedReconcileResult := reconcile.Result{RequeueAfter: time.Second} assert.Equal(t, expectedReconcileResult, res) - updatedCnsNodeVmBatchAttachment := &v1alpha1.CnsNodeVmBatchAttachment{} - if err := r.client.Get(context.TODO(), req.NamespacedName, updatedCnsNodeVmBatchAttachment); err != nil { + updatedCnsNodeVMBatchAttachment := &v1alpha1.CnsNodeVMBatchAttachment{} + if err := r.client.Get(context.TODO(), req.NamespacedName, updatedCnsNodeVMBatchAttachment); err != nil { t.Fatalf("failed to get cnsnodevmbatchattachemnt instance") } expectedReconcileError := fmt.Errorf("virtual Machine with UUID %s on vCenter does not exist. "+ "Vm is CR is deleted or is being deleted but"+ - "CnsNodeVmBatchAttachmentInstance %s is not being deleted", nodeUUID, testCnsNodeVmBatchAttachmentName) + "CnsNodeVMBatchAttachmentInstance %s is not being deleted", nodeUUID, testCnsNodeVMBatchAttachmentName) expectedErrorMsg := expectedReconcileError.Error() - assert.Equal(t, expectedErrorMsg, updatedCnsNodeVmBatchAttachment.Status.Error) + assert.Equal(t, expectedErrorMsg, updatedCnsNodeVMBatchAttachment.Status.Error) }) } func TestReconcileWithDeletionTimestamp(t *testing.T) { t.Run("TestReconcileWithDeletionTimestamp", func(t *testing.T) { - testCnsNodeVmBatchAttachment := setupTestCnsNodeVmBatchAttachment() - r := setTestEnvironment(&testCnsNodeVmBatchAttachment, false) + testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment() + r := setTestEnvironment(&testCnsNodeVMBatchAttachment, false) mockVolumeManager := &unittestcommon.MockVolumeManager{} commonco.ContainerOrchestratorUtility = &unittestcommon.FakeK8SOrchestrator{} @@ -345,15 +345,15 @@ func TestReconcileWithDeletionTimestamp(t *testing.T) { vm := &cnsvsphere.VirtualMachine{} err := r.reconcileInstanceWithDeletionTimestamp(context.TODO(), clientset, - &testCnsNodeVmBatchAttachment, volumesToDetach, vm) + &testCnsNodeVMBatchAttachment, volumesToDetach, vm) assert.NoError(t, err) }) } func TestReconcileWithDeletionTimestampWhenDetachFails(t *testing.T) { t.Run("TestReconcileWithDeletionTimestampWhenDetachFails", func(t *testing.T) { - testCnsNodeVmBatchAttachment := setupTestCnsNodeVmBatchAttachment() - r := setTestEnvironment(&testCnsNodeVmBatchAttachment, false) + testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment() + r := setTestEnvironment(&testCnsNodeVMBatchAttachment, false) mockVolumeManager := &unittestcommon.MockVolumeManager{} r.volumeManager = mockVolumeManager @@ -372,7 +372,7 @@ func TestReconcileWithDeletionTimestampWhenDetachFails(t *testing.T) { commonco.ContainerOrchestratorUtility = &unittestcommon.FakeK8SOrchestrator{} err := r.reconcileInstanceWithDeletionTimestamp(context.TODO(), clientset, - &testCnsNodeVmBatchAttachment, volumesToDetach, vm) + &testCnsNodeVMBatchAttachment, volumesToDetach, vm) if err == nil { t.Fatal("Expected reconcile error") } @@ -385,8 +385,8 @@ func TestReconcileWithDeletionTimestampWhenDetachFails(t *testing.T) { func TestReconcileWithoutDeletionTimestamp(t *testing.T) { t.Run("TestReconcileWithoutDeletionTimestamp", func(t *testing.T) { - testCnsNodeVmBatchAttachment := setupTestCnsNodeVmBatchAttachment() - r := setTestEnvironment(&testCnsNodeVmBatchAttachment, false) + testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment() + r := setTestEnvironment(&testCnsNodeVMBatchAttachment, false) mockVolumeManager := &unittestcommon.MockVolumeManager{} r.volumeManager = mockVolumeManager commonco.ContainerOrchestratorUtility = &unittestcommon.FakeK8SOrchestrator{} @@ -400,7 +400,7 @@ func TestReconcileWithoutDeletionTimestamp(t *testing.T) { err := r.reconcileInstanceWithoutDeletionTimestamp(context.TODO(), clientset, - &testCnsNodeVmBatchAttachment, volumesToDetach, vm) + &testCnsNodeVMBatchAttachment, volumesToDetach, vm) assert.NoError(t, err) }) } @@ -408,8 +408,8 @@ func TestReconcileWithoutDeletionTimestamp(t *testing.T) { func TestReconcileWithoutDeletionTimestampWhenAttachFails(t *testing.T) { t.Run("TestReconcileWithoutDeletionTimestamp", func(t *testing.T) { - testCnsNodeVmBatchAttachment := setupTestCnsNodeVmBatchAttachment() - r := setTestEnvironment(&testCnsNodeVmBatchAttachment, false) + testCnsNodeVMBatchAttachment := setupTestCnsNodeVMBatchAttachment() + r := setTestEnvironment(&testCnsNodeVMBatchAttachment, false) mockVolumeManager := &unittestcommon.MockVolumeManager{} r.volumeManager = mockVolumeManager commonco.ContainerOrchestratorUtility = &unittestcommon.FakeK8SOrchestrator{} @@ -419,10 +419,10 @@ func TestReconcileWithoutDeletionTimestampWhenAttachFails(t *testing.T) { } // Update PVC to fail-attach-pvc-3 to mock failure in attach - for i, volume := range testCnsNodeVmBatchAttachment.Spec.Volumes { + for i, volume := range testCnsNodeVMBatchAttachment.Spec.Volumes { if volume.PersistentVolumeClaim.ClaimName == "pvc-2" { volume.PersistentVolumeClaim.ClaimName = "fail-attach-pvc-3" - testCnsNodeVmBatchAttachment.Spec.Volumes[i] = volume + testCnsNodeVMBatchAttachment.Spec.Volumes[i] = volume break } } @@ -432,7 +432,7 @@ func TestReconcileWithoutDeletionTimestampWhenAttachFails(t *testing.T) { err := r.reconcileInstanceWithoutDeletionTimestamp(context.TODO(), clientset, - &testCnsNodeVmBatchAttachment, volumesToDetach, vm) + &testCnsNodeVMBatchAttachment, volumesToDetach, vm) if err == nil { t.Fatal("Expected reconcile error") } diff --git a/pkg/syncer/cnsoperator/manager/init.go b/pkg/syncer/cnsoperator/manager/init.go index 0bb7559a8b..7fed3b4a73 100644 --- a/pkg/syncer/cnsoperator/manager/init.go +++ b/pkg/syncer/cnsoperator/manager/init.go @@ -127,12 +127,12 @@ func InitCnsOperator(ctx context.Context, clusterFlavor cnstypes.CnsClusterFlavo if cnsOperator.coCommonInterface.IsFSSEnabled(ctx, common.SharedDiskFss) { - // Create CnsNodeVmBatchAttachment CRD + // Create CnsNodeVMBatchAttachment CRD err = k8s.CreateCustomResourceDefinitionFromManifest(ctx, - cnsoperatorconfig.EmbedCnsNodeVmBatchAttachmentCRFile, + cnsoperatorconfig.EmbedCnsNodeVMBatchAttachmentCRFile, cnsoperatorconfig.EmbedCnsNodeVmABatchttachmentCRFileName) if err != nil { - crdNameNodeVmBatchAttachment := cnsoperatorv1alpha1.CnsNodeVmBatchAttachmentPlural + + crdNameNodeVmBatchAttachment := cnsoperatorv1alpha1.CnsNodeVMBatchAttachmentPlural + "." + cnsoperatorv1alpha1.SchemeGroupVersion.Group log.Errorf("failed to create %q CRD. Err: %+v", crdNameNodeVmBatchAttachment, err) return err