@@ -9,10 +9,11 @@ import (
99 "github.com/validator-labs/validator/pkg/validationrule"
1010
1111 "github.com/validator-labs/validator-plugin-vsphere/api/vcenter"
12+ "github.com/validator-labs/validator-plugin-vsphere/api/vcenter/entity"
1213 "github.com/validator-labs/validator-plugin-vsphere/pkg/constants"
1314)
1415
15- // VsphereValidatorSpec defines the desired state of VsphereValidator
16+ // VsphereValidatorSpec defines the desired state of a vSphere validator.
1617type VsphereValidatorSpec struct {
1718 Auth VsphereAuth `json:"auth" yaml:"auth"`
1819 Datacenter string `json:"datacenter" yaml:"datacenter"`
@@ -29,173 +30,187 @@ func (s VsphereValidatorSpec) PluginCode() string {
2930 return constants .PluginCode
3031}
3132
32- // ResultCount returns the number of validation results expected for an VsphereValidatorSpec.
33+ // ResultCount returns the number of validation results expected for a VsphereValidatorSpec.
3334func (s VsphereValidatorSpec ) ResultCount () int {
3435 return len (s .PrivilegeValidationRules ) + len (s .ComputeResourceRules ) +
3536 len (s .TagValidationRules ) + len (s .NTPValidationRules )
3637}
3738
38- // VsphereAuth defines authentication configuration for an VsphereValidator .
39+ // VsphereAuth defines authentication configuration for a vSphere validator .
3940type VsphereAuth struct {
40- // SecretName is the name of the secret containing the vSphere credentials
41+ // SecretName is the name of the secret containing vCenter credentials.
4142 SecretName string `json:"secretName,omitempty" yaml:"secretName,omitempty"`
4243
43- // Account is the vCenter account to use for authentication
44+ // Account is the vCenter account to use for authentication.
4445 Account * vcenter.Account `json:"account,omitempty" yaml:"account,omitempty"`
4546}
4647
47- // NTPValidationRule defines the NTP validation rule
48+ // NTPValidationRule defines an NTP validation rule.
4849type NTPValidationRule struct {
4950 validationrule.ManuallyNamed `json:",inline" yaml:",omitempty"`
5051
51- // RuleName is the name of the NTP validation rule
52+ // RuleName is the name of the NTP validation rule.
5253 RuleName string `json:"name" yaml:"name"`
5354
54- // ClusterName is required when the vCenter Host(s) reside beneath a Cluster in the vCenter object hierarchy
55+ // ClusterName is required when the vCenter Host(s) reside beneath a Cluster in the vCenter object hierarchy.
5556 ClusterName string `json:"clusterName,omitempty" yaml:"clusterName,omitempty"`
5657
57- // Hosts is the list of vCenter Hosts to validate NTP configuration
58+ // Hosts is the list of vCenter Hosts to validate NTP configuration for.
5859 Hosts []string `json:"hosts" yaml:"hosts"`
5960}
6061
6162var _ validationrule.Interface = (* NTPValidationRule )(nil )
6263
63- // Name returns the name of the NTPValidationRule .
64+ // Name returns the name of the NTP validation rule .
6465func (r NTPValidationRule ) Name () string {
6566 return r .RuleName
6667}
6768
68- // SetName sets the name of the NTPValidationRule .
69+ // SetName sets the name of the NTP validation rule .
6970func (r * NTPValidationRule ) SetName (name string ) {
7071 r .RuleName = name
7172}
7273
73- // ComputeResourceRule defines the compute resource validation rule
74+ // ComputeResourceRule defines a compute resource validation rule.
7475type ComputeResourceRule struct {
7576 validationrule.ManuallyNamed `json:",inline" yaml:",omitempty"`
7677
77- // RuleName is the name of the compute resource validation rule
78+ // RuleName is the name of the compute resource validation rule.
7879 RuleName string `json:"name" yaml:"name"`
7980
80- // ClusterName is required when the vCenter Entity resides beneath a Cluster in the vCenter object hierarchy
81+ // ClusterName is required when the vCenter entity resides beneath a Cluster in the vCenter object hierarchy.
8182 ClusterName string `json:"clusterName,omitempty" yaml:"clusterName"`
8283
83- // Scope is the scope of the compute resource validation rule
84- Scope vcenter .Entity `json:"scope" yaml:"scope"`
84+ // Scope is the scope of the compute resource validation rule.
85+ Scope entity .Entity `json:"scope" yaml:"scope"`
8586
86- // EntityName is the name of the entity to validate
87+ // EntityName is the name of the entity to validate.
8788 EntityName string `json:"entityName" yaml:"entityName"`
8889
89- // NodepoolResourceRequirements is the list of nodepool resource requirements
90+ // NodepoolResourceRequirements is the list of nodepool resource requirements.
9091 NodepoolResourceRequirements []NodepoolResourceRequirement `json:"nodepoolResourceRequirements" yaml:"nodepoolResourceRequirements"`
9192}
9293
9394var _ validationrule.Interface = (* ComputeResourceRule )(nil )
9495
95- // Name returns the name of the ComputeResourceRule .
96+ // Name returns the name of the compute resource validation rule .
9697func (r ComputeResourceRule ) Name () string {
9798 return r .RuleName
9899}
99100
100- // SetName sets the name of the ComputeResourceRule .
101+ // SetName sets the name of the compute resource validation rule .
101102func (r * ComputeResourceRule ) SetName (name string ) {
102103 r .RuleName = name
103104}
104105
105- // PrivilegeValidationRule defines the privilege validation rule
106+ // PrivilegeValidationRule defines a privilege validation rule.
106107type PrivilegeValidationRule struct {
107108 validationrule.ManuallyNamed `json:",inline" yaml:",omitempty"`
108109
109- // RuleName is the name of the entity privilege validation rule
110+ // RuleName is the name of the privilege validation rule.
110111 RuleName string `json:"name" yaml:"name"`
111112
112- // Username is the username to validate against
113- Username string `json:"username" yaml:"username"`
114-
115- // ClusterName is required when the vCenter Entity resides beneath a Cluster in the vCenter object hierarchy
113+ // ClusterName is required when the vCenter entity resides beneath a Cluster in the vCenter object hierarchy.
116114 ClusterName string `json:"clusterName,omitempty" yaml:"clusterName,omitempty"`
117115
118- // EntityType is the type of the entity to validate
119- EntityType vcenter .Entity `json:"entityType" yaml:"entityType"`
116+ // EntityType is the type of the vCenter entity to validate.
117+ EntityType entity .Entity `json:"entityType" yaml:"entityType"`
120118
121- // EntityName is the name of the entity to validate
119+ // EntityName is the name of the vCenter entity to validate privileges on.
122120 EntityName string `json:"entityName" yaml:"entityName"`
123121
124- // Privileges is the list of privileges to validate that the user has
122+ // Privileges is the list of privileges to validate that the user has with respect to the designated vCenter entity.
125123 Privileges []string `json:"privileges" yaml:"privileges"`
126124
127- // TODO: consider propagation somehow
125+ // Propagation validation configuration for permissions that grant the user privileges on the vCenter entity.
126+ Propagation Propagation `json:"propagation,omitempty" yaml:"propagation,omitempty"`
127+ }
128+
129+ // Propagation contains configuration related to propagation validation.
130+ type Propagation struct {
131+ // Enabled controls whether propagation validation is performed.
132+ Enabled bool `json:"enabled" yaml:"enabled"`
133+
134+ // GroupPrincipals is an optional list of vCenter group principals that the user is a member of.
135+ // Group membership can be determined dynamically by a vSphere admin user, but specifying
136+ // group principals manually allows privilege validation for non-admin users.
137+ // Group principals must be of the format DOMAIN\group-name, e.g., VSPHERE.LOCAL\my-custom-group.
138+ GroupPrincipals []string `json:"groupPrincipals,omitempty" yaml:"groupPrincipals,omitempty"`
139+
140+ // Propagated indicates whether the permission that grants privileges to the user for the rule's
141+ // entity is expected to be propagated or not.
142+ Propagated bool `json:"propagated" yaml:"propagated"`
128143}
129144
130145var _ validationrule.Interface = (* PrivilegeValidationRule )(nil )
131146
132- // Name returns the name of the PrivilegeValidationRule .
147+ // Name returns the name of the privilege validation rule .
133148func (r PrivilegeValidationRule ) Name () string {
134149 return r .RuleName
135150}
136151
137- // SetName sets the name of the PrivilegeValidationRule .
152+ // SetName sets the name of the privilege validation rule .
138153func (r * PrivilegeValidationRule ) SetName (name string ) {
139154 r .RuleName = name
140155}
141156
142- // TagValidationRule defines the tag validation rule
157+ // TagValidationRule defines a tag validation rule.
143158type TagValidationRule struct {
144159 validationrule.ManuallyNamed `json:",inline" yaml:",omitempty"`
145160
146- // RuleName is the name of the tag validation rule
161+ // RuleName is the name of the tag validation rule.
147162 RuleName string `json:"name" yaml:"name"`
148163
149- // ClusterName is required when the vCenter Entity resides beneath a Cluster in the vCenter object hierarchy
164+ // ClusterName is required when the vCenter entity resides beneath a Cluster in the vCenter object hierarchy.
150165 ClusterName string `json:"clusterName,omitempty" yaml:"clusterName"`
151166
152- // EntityType is the type of the entity to validate
153- EntityType vcenter .Entity `json:"entityType" yaml:"entityType"`
167+ // EntityType is the type of the vCenter entity to validate.
168+ EntityType entity .Entity `json:"entityType" yaml:"entityType"`
154169
155- // EntityName is the name of the entity to validate
170+ // EntityName is the name of the vCenter entity to validate tags on.
156171 EntityName string `json:"entityName" yaml:"entityName"`
157172
158- // Tag is the tag to validate on the entity
173+ // Tag is the tag to validate on the vCenter entity.
159174 Tag string `json:"tag" yaml:"tag"`
160175}
161176
162177var _ validationrule.Interface = (* TagValidationRule )(nil )
163178
164- // Name returns the name of the TagValidationRule .
179+ // Name returns the name of the tag validation rule .
165180func (r TagValidationRule ) Name () string {
166181 return r .RuleName
167182}
168183
169- // SetName sets the name of the TagValidationRule .
184+ // SetName sets the name of the tag validation rule .
170185func (r * TagValidationRule ) SetName (name string ) {
171186 r .RuleName = name
172187}
173188
174- // NodepoolResourceRequirement defines the resource requirements for a nodepool
189+ // NodepoolResourceRequirement defines the resource requirements for a node pool.
175190type NodepoolResourceRequirement struct {
176- // Name is the name of the nodepool
191+ // Name is the name of the node pool.
177192 Name string `json:"name" yaml:"name"`
178193
179- // NumberOfNodes is the number of nodes in the nodepool
194+ // NumberOfNodes is the number of nodes in the node pool.
180195 NumberOfNodes int `json:"numberOfNodes" yaml:"numberOfNodes"`
181196
182- // CPU is the CPU requirement for the nodepool
197+ // CPU is the CPU requirement for the node pool.
183198 CPU string `json:"cpu" yaml:"cpu"`
184199
185- // Memory is the memory requirement for the nodepool
200+ // Memory is the memory requirement for the node pool.
186201 Memory string `json:"memory" yaml:"memory"`
187202
188- // DiskSpace is the disk space requirement for the nodepool
203+ // DiskSpace is the disk space requirement for the node pool.
189204 DiskSpace string `json:"diskSpace" yaml:"diskSpace"`
190205}
191206
192- // VsphereValidatorStatus defines the observed state of VsphereValidator
207+ // VsphereValidatorStatus defines the observed state of a vSphere validator.
193208type VsphereValidatorStatus struct {}
194209
195210//+kubebuilder:object:root=true
196211//+kubebuilder:subresource:status
197212
198- // VsphereValidator is the Schema for the vspherevalidators API
213+ // VsphereValidator is the Schema for the vspherevalidators API.
199214type VsphereValidator struct {
200215 metav1.TypeMeta `json:",inline"`
201216 metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -214,14 +229,14 @@ func (v VsphereValidator) PluginCode() string {
214229 return v .Spec .PluginCode ()
215230}
216231
217- // ResultCount returns the number of validation results expected for a VsphereValidator .
232+ // ResultCount returns the number of validation results expected for a vSphere validator .
218233func (v VsphereValidator ) ResultCount () int {
219234 return v .Spec .ResultCount ()
220235}
221236
222237//+kubebuilder:object:root=true
223238
224- // VsphereValidatorList contains a list of VsphereValidator
239+ // VsphereValidatorList contains a list of vSphere validator.
225240type VsphereValidatorList struct {
226241 metav1.TypeMeta `json:",inline"`
227242 metav1.ListMeta `json:"metadata,omitempty"`
0 commit comments