Skip to content

Commit f469cd6

Browse files
committed
AV-239701: Add secret to pass authentication details to health monitor (#1816)
* Add secret index * Add UT * Address comments
1 parent db6c1cc commit f469cd6

File tree

10 files changed

+1001
-45
lines changed

10 files changed

+1001
-45
lines changed

ako-crd-operator/api/v1alpha1/healthmonitor_types.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242
)
4343

4444
// HealthMonitorSpec defines the desired state of HealthMonitor
45-
// +kubebuilder:validation:XValidation:rule="(!has(self.http_monitor) || !has(self.http_monitor.auth_type) || has(self.authentication.username) && has(self.authentication.password))",message="If auth_type is set, both username and password must be set in authentication"
45+
// +kubebuilder:validation:XValidation:rule="(!has(self.http_monitor) || !has(self.http_monitor.auth_type) || has(self.authentication.secret_ref))",message="If auth_type is set, secret_ref must be set in authentication"
4646
type HealthMonitorSpec struct {
4747
// SendInterval is the frequency, in seconds, that pings are sent.
4848
// +kubebuilder:validation:Minimum=1
@@ -102,14 +102,9 @@ type HealthMonitorSpec struct {
102102

103103
// HealthMonitorInfo defines authentication information for HTTP/HTTPS monitors.
104104
type HealthMonitorInfo struct {
105-
// Username for server authentication.
106-
// +kubebuilder:validation:MinLength=1
107-
// +kubebuilder:validation:MaxLength=128
108-
Username string `json:"username"`
109-
// Password for server authentication.
110-
// +kubebuilder:validation:MinLength=1
111-
// +kubebuilder:validation:MaxLength=128
112-
Password string `json:"password"`
105+
// +kubebuilder:validation:Required
106+
// SecretRef is the reference to the secret containing the username and password.
107+
SecretRef string `json:"secret_ref,omitempty"`
113108
}
114109

115110
// TCPMonitor defines the TCP monitor configuration.
@@ -201,6 +196,9 @@ type HealthMonitorStatus struct {
201196
Conditions []metav1.Condition `json:"conditions,omitempty"`
202197
// BackendObjectName is the name of the backend object
203198
BackendObjectName string `json:"backendObjectName,omitempty"`
199+
// DependencySum is the checksum of all the dependencies for the health monitor
200+
// +optional
201+
DependencySum uint32 `json:"dependencySum,omitempty"`
204202
}
205203

206204
// +genclient

ako-crd-operator/config/crd/bases/ako.vmware.com_healthmonitors.yaml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,12 @@ spec:
4545
description: Authentication defines the authentication information
4646
for HTTP/HTTPS monitors.
4747
properties:
48-
password:
49-
description: Password for server authentication.
50-
maxLength: 128
51-
minLength: 1
52-
type: string
53-
username:
54-
description: Username for server authentication.
55-
maxLength: 128
56-
minLength: 1
48+
secret_ref:
49+
description: SecretRef is the reference to the secret containing
50+
the username and password.
5751
type: string
5852
required:
59-
- password
60-
- username
53+
- secret_ref
6154
type: object
6255
failed_checks:
6356
default: 2
@@ -220,10 +213,9 @@ spec:
220213
- type
221214
type: object
222215
x-kubernetes-validations:
223-
- message: If auth_type is set, both username and password must be set
224-
in authentication
216+
- message: If auth_type is set, secret_ref must be set in authentication
225217
rule: (!has(self.http_monitor) || !has(self.http_monitor.auth_type)
226-
|| has(self.authentication.username) && has(self.authentication.password))
218+
|| has(self.authentication.secret_ref))
227219
status:
228220
description: Status defines the observed state of HealthMonitor
229221
properties:
@@ -287,6 +279,11 @@ spec:
287279
- type
288280
type: object
289281
type: array
282+
dependencySum:
283+
description: DependencySum is the checksum of all the dependencies
284+
for the health monitor
285+
format: int32
286+
type: integer
290287
lastUpdated:
291288
description: LastUpdated is the timestamp the object was last updated
292289
format: date-time

ako-crd-operator/config/rbac/role.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ kind: ClusterRole
44
metadata:
55
name: manager-role
66
rules:
7+
- apiGroups:
8+
- ""
9+
resources:
10+
- secrets
11+
verbs:
12+
- get
13+
- list
14+
- watch
715
- apiGroups:
816
- ako.vmware.com
917
resources:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: healthmonitor-secret
5+
namespace: default
6+
type: ako.vmware.com/basic-auth
7+
data:
8+
username: YWJjZA==
9+
password: ZWZnaA==

ako-crd-operator/helm/ako-crd-operator/chart/templates/crd/ako.vmware.com_healthmonitors.yaml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,12 @@ spec:
4545
description: Authentication defines the authentication information
4646
for HTTP/HTTPS monitors.
4747
properties:
48-
password:
49-
description: Password for server authentication.
50-
maxLength: 128
51-
minLength: 1
52-
type: string
53-
username:
54-
description: Username for server authentication.
55-
maxLength: 128
56-
minLength: 1
48+
secret_ref:
49+
description: SecretRef is the reference to the secret containing
50+
the username and password.
5751
type: string
5852
required:
59-
- password
60-
- username
53+
- secret_ref
6154
type: object
6255
failed_checks:
6356
default: 2
@@ -220,10 +213,9 @@ spec:
220213
- type
221214
type: object
222215
x-kubernetes-validations:
223-
- message: If auth_type is set, both username and password must be set
224-
in authentication
216+
- message: If auth_type is set, secret_ref must be set in authentication
225217
rule: (!has(self.http_monitor) || !has(self.http_monitor.auth_type)
226-
|| has(self.authentication.username) && has(self.authentication.password))
218+
|| has(self.authentication.secret_ref))
227219
status:
228220
description: Status defines the observed state of HealthMonitor
229221
properties:
@@ -287,6 +279,11 @@ spec:
287279
- type
288280
type: object
289281
type: array
282+
dependencySum:
283+
description: DependencySum is the checksum of all the dependencies
284+
for the health monitor
285+
format: int32
286+
type: integer
290287
lastUpdated:
291288
description: LastUpdated is the timestamp the object was last updated
292289
format: date-time

ako-crd-operator/internal/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ const (
88
Sensitive = "<sensitive>"
99
ApplicationProfileFinalizer = "applicationprofile.ako.vmware.com/finalizer"
1010
ApplicationProfileURL = "/api/applicationprofile"
11+
HealthMonitorSecretType = "ako.vmware.com/basic-auth"
1112
RequeueInterval = 5 * time.Minute
1213
)

0 commit comments

Comments
 (0)