Skip to content

Commit 9a3d713

Browse files
authored
feat: support inline auth for vCenter (#338)
## Issue ## Description Modifies the auth struct to also support directly passing account credentials If a secretName is referenced in the auth, we will still default to pulling creds from the secret.
1 parent 1ec82f4 commit 9a3d713

12 files changed

Lines changed: 199 additions & 79 deletions

api/v1alpha1/vspherevalidator_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
77

88
"github.com/validator-labs/validator-plugin-vsphere/pkg/constants"
9+
"github.com/validator-labs/validator-plugin-vsphere/pkg/vsphere"
910
)
1011

1112
// VsphereValidatorSpec defines the desired state of VsphereValidator
@@ -33,7 +34,9 @@ func (s VsphereValidatorSpec) ResultCount() int {
3334
// VsphereAuth defines authentication configuration for an VsphereValidator.
3435
type VsphereAuth struct {
3536
// SecretName is the name of the secret containing the vSphere credentials
36-
SecretName string `json:"secretName" yaml:"secretName"`
37+
SecretName string `json:"secretName,omitempty" yaml:"secretName,omitempty"`
38+
// CloudAccount is the vSphere cloud account to use for authentication
39+
CloudAccount *vsphere.CloudAccount `json:"cloudAccount,omitempty" yaml:"cloudAccount,omitempty"`
3740
}
3841

3942
// NTPValidationRule defines the NTP validation rule

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chart/validator-plugin-vsphere/crds/validation.spectrocloud.labs_vspherevalidators.yaml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,39 @@ spec:
4343
description: VsphereAuth defines authentication configuration for
4444
an VsphereValidator.
4545
properties:
46+
cloudAccount:
47+
description: CloudAccount is the vSphere cloud account to use
48+
for authentication
49+
properties:
50+
insecure:
51+
description: Insecure is a flag that controls whether to validate
52+
the vSphere server's certificate.
53+
type: boolean
54+
password:
55+
description: |-
56+
password
57+
Required: true
58+
type: string
59+
username:
60+
description: |-
61+
username
62+
Required: true
63+
type: string
64+
vcenterServer:
65+
description: |-
66+
VcenterServer is the address of the vSphere endpoint
67+
Required: true
68+
type: string
69+
required:
70+
- insecure
71+
- password
72+
- username
73+
- vcenterServer
74+
type: object
4675
secretName:
4776
description: SecretName is the name of the secret containing the
4877
vSphere credentials
4978
type: string
50-
required:
51-
- secretName
5279
type: object
5380
computeResourceRules:
5481
items:

config/crd/bases/validation.spectrocloud.labs_vspherevalidators.yaml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,39 @@ spec:
4343
description: VsphereAuth defines authentication configuration for
4444
an VsphereValidator.
4545
properties:
46+
cloudAccount:
47+
description: CloudAccount is the vSphere cloud account to use
48+
for authentication
49+
properties:
50+
insecure:
51+
description: Insecure is a flag that controls whether to validate
52+
the vSphere server's certificate.
53+
type: boolean
54+
password:
55+
description: |-
56+
password
57+
Required: true
58+
type: string
59+
username:
60+
description: |-
61+
username
62+
Required: true
63+
type: string
64+
vcenterServer:
65+
description: |-
66+
VcenterServer is the address of the vSphere endpoint
67+
Required: true
68+
type: string
69+
required:
70+
- insecure
71+
- password
72+
- username
73+
- vcenterServer
74+
type: object
4675
secretName:
4776
description: SecretName is the name of the secret containing the
4877
vSphere credentials
4978
type: string
50-
required:
51-
- secretName
5279
type: object
5380
computeResourceRules:
5481
items:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: validation.spectrocloud.labs/v1alpha1
2+
kind: VsphereValidator
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: vspherevalidator
6+
app.kubernetes.io/instance: vspherevalidator-sample
7+
app.kubernetes.io/part-of: validator-plugin-vsphere
8+
app.kubernetes.io/managed-by: kustomize
9+
app.kubernetes.io/created-by: validator-plugin-vsphere
10+
name: vspherevalidator-compute
11+
namespace: validator
12+
spec:
13+
datacenter: "Datacenter"
14+
computeResourceRules:
15+
- name: "rp-cluster2-palette-advanced-projects check resources"
16+
clusterName: Cluster2
17+
scope: resourcepool
18+
entityName: "rp-cluster2-palette-advanced-projects"
19+
nodepoolResourceRequirements:
20+
- name: control-plane-pool
21+
numberOfNodes: 3
22+
cpu: "1GHz"
23+
memory: 8Gi
24+
diskSpace: 80Gi
25+
- name: worker-pool
26+
numberOfNodes: 2
27+
cpu: "2GHz"
28+
memory: 8Gi
29+
diskSpace: 100Gi
30+
auth:
31+
secretName: vsphere-creds
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: validation.spectrocloud.labs/v1alpha1
2+
kind: VsphereValidator
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: vspherevalidator
6+
app.kubernetes.io/instance: vspherevalidator-sample
7+
app.kubernetes.io/part-of: validator-plugin-vsphere
8+
app.kubernetes.io/managed-by: kustomize
9+
app.kubernetes.io/created-by: validator-plugin-vsphere
10+
name: vspherevalidator-entity-privilege
11+
namespace: validator
12+
spec:
13+
datacenter: "Datacenter"
14+
auth:
15+
secretName: vsphere-creds
16+
entityPrivilegeValidationRules:
17+
- name: "Deploy VM to vapp test-vapp"
18+
username: prakash@vsphere.local
19+
entityName: "sp-prakash"
20+
entityType: "folder"
21+
privileges:
22+
- "VirtualMachine.Config.AddExistingDisk"
23+
- "VirtualMachine.Config.AddNewDisk"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: validation.spectrocloud.labs/v1alpha1
2+
kind: VsphereValidator
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: vspherevalidator
6+
app.kubernetes.io/instance: vspherevalidator-sample
7+
app.kubernetes.io/part-of: validator-plugin-vsphere
8+
app.kubernetes.io/managed-by: kustomize
9+
app.kubernetes.io/created-by: validator-plugin-vsphere
10+
name: vspherevalidator-explicit-auth
11+
namespace: validator
12+
spec:
13+
datacenter: "Datacenter"
14+
auth:
15+
cloudAccount:
16+
insecure: true
17+
username: "user@vsphere.local"
18+
password: "password"
19+
vcenterServer: "vcenter.example.com"
20+
tagValidationRules:
21+
- name: "Folder tag validation"
22+
clusterName: "Cluster2"
23+
entityType: "folder"
24+
entityName: "sp-prakash"
25+
tag: "owner"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
app.kubernetes.io/part-of: validator-plugin-vsphere
88
app.kubernetes.io/managed-by: kustomize
99
app.kubernetes.io/created-by: validator-plugin-vsphere
10-
name: vspherevalidator
10+
name: vspherevalidator-ntp
1111
namespace: validator
1212
spec:
1313
datacenter: "Datacenter"
@@ -19,4 +19,4 @@ spec:
1919
- 10.10.20.111
2020
- 10.10.20.112
2121
auth:
22-
secretName: validator-secret
22+
secretName: vsphere-creds
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: validation.spectrocloud.labs/v1alpha1
2+
kind: VsphereValidator
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: vspherevalidator
6+
app.kubernetes.io/instance: vspherevalidator-sample
7+
app.kubernetes.io/part-of: validator-plugin-vsphere
8+
app.kubernetes.io/managed-by: kustomize
9+
app.kubernetes.io/created-by: validator-plugin-vsphere
10+
name: vspherevalidator-role-privilege
11+
namespace: validator
12+
spec:
13+
datacenter: "Datacenter"
14+
auth:
15+
secretName: vsphere-creds
16+
rolePrivilegeValidationRules:
17+
- username: tmpadmin@vsphere.local
18+
privileges:
19+
- Cns.Searchable
20+
- Datastore.Browse
21+
- InventoryService.Tagging.CreateTag
22+
- InventoryService.Tagging.EditTag
23+
- Network.Assign
24+
- Sessions.ValidateSession
25+
- StorageProfile.View
26+
- StorageViews.View

config/samples/validation_v1alpha1_vspherevalidator.yaml renamed to config/samples/vsphere-validator-tag.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ metadata:
77
app.kubernetes.io/part-of: validator-plugin-vsphere
88
app.kubernetes.io/managed-by: kustomize
99
app.kubernetes.io/created-by: validator-plugin-vsphere
10-
name: vspherevalidator-sample
10+
name: vspherevalidator
11+
namespace: validator
1112
spec:
12-
# TODO(user): Add fields here
13+
datacenter: "Datacenter"
14+
auth:
15+
secretName: vsphere-creds
16+
tagValidationRules:
17+
- name: "Folder tag validation"
18+
clusterName: "Cluster2"
19+
entityType: "folder"
20+
entityName: "sp-prakash"
21+
tag: "owner"

0 commit comments

Comments
 (0)