Skip to content

Commit 46d0e78

Browse files
committed
add persistense profile crd controller
1 parent a46b512 commit 46d0e78

File tree

7 files changed

+433
-75
lines changed

7 files changed

+433
-75
lines changed

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

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,44 +53,37 @@ const (
5353
)
5454

5555
// PersistenceProfileSpec defines the desired state of PersistenceProfile
56+
// +kubebuilder:validation:XValidation:rule="((self.persistence_type == 'PERSISTENCE_TYPE_CLIENT_IP_ADDRESS' || self.persistence_type == 'PERSISTENCE_TYPE_CLIENT_IPV6_ADDRESS') && has(self.ip_persistence_profile) && !has(self.hdr_persistence_profile) && !has(self.app_cookie_persistence_profile) && !has(self.http_cookie_persistence_profile)) || (self.persistence_type == 'PERSISTENCE_TYPE_CUSTOM_HTTP_HEADER' && has(self.hdr_persistence_profile) && !has(self.ip_persistence_profile) && !has(self.app_cookie_persistence_profile) && !has(self.http_cookie_persistence_profile)) || (self.persistence_type == 'PERSISTENCE_TYPE_APP_COOKIE' && has(self.app_cookie_persistence_profile) && !has(self.ip_persistence_profile) && !has(self.hdr_persistence_profile) && !has(self.http_cookie_persistence_profile)) || (self.persistence_type == 'PERSISTENCE_TYPE_HTTP_COOKIE' && has(self.http_cookie_persistence_profile) && !has(self.ip_persistence_profile) && !has(self.hdr_persistence_profile) && !has(self.app_cookie_persistence_profile)) || (self.persistence_type == 'PERSISTENCE_TYPE_TLS' && !has(self.ip_persistence_profile) && !has(self.hdr_persistence_profile) && !has(self.app_cookie_persistence_profile) && !has(self.http_cookie_persistence_profile))", message="Invalid profile configuration for persistence_type. When persistence_type is CLIENT_IP_ADDRESS, CLIENT_IPV6_ADDRESS, CUSTOM_HTTP_HEADER, APP_COOKIE, or HTTP_COOKIE, its corresponding profile field (e.g. ipPersistenceProfile) must be set and other profile fields must be absent. For types like TLS, none of these specific profile fields should be set."
5657
type PersistenceProfileSpec struct {
57-
// Name is a user-friendly name for the persistence profile.
58-
// +kubebuilder:validation:Required
59-
// +kubebuilder:validation:MaxLength=256
60-
Name string `json:"name"`
6158

6259
// ServerHmDownRecovery specifies behavior when a persistent server has been marked down by a health monitor.
6360
// +kubebuilder:default:=HM_DOWN_PICK_NEW_SERVER
64-
ServerHmDownRecovery ServerHmDownRecovery `json:"serverHmDownRecovery,omitempty"`
61+
ServerHmDownRecovery ServerHmDownRecovery `json:"server_hm_down_recovery,omitempty"`
6562

6663
// PersistenceType is the method used to persist clients to the same server.
6764
// +kubebuilder:default:=PERSISTENCE_TYPE_CLIENT_IP_ADDRESS
6865
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="type is immutable"
69-
PersistenceType PersistenceType `json:"persistenceType,omitempty"`
66+
PersistenceType PersistenceType `json:"persistence_type,omitempty"`
7067

7168
// IPPersistenceProfile specifies the Client IP Persistence profile parameters.
7269
// +optional
73-
// +kubebuilder:validation:XValidation:rule="self.persistenceType == 'PERSISTENCE_TYPE_CLIENT_IP_ADDRESS'",message="ipPersistenceProfile can only be set when persistenceType is PERSISTENCE_TYPE_CLIENT_IP_ADDRESS"
74-
IPPersistenceProfile *IPPersistenceProfile `json:"ipPersistenceProfile,omitempty"`
70+
IPPersistenceProfile *IPPersistenceProfile `json:"ip_persistence_profile,omitempty"`
7571

7672
// HdrPersistenceProfile specifies the custom HTTP Header Persistence profile parameters.
7773
// +optional
78-
// +kubebuilder:validation:XValidation:rule="self.persistenceType == 'PERSISTPERSISTENCE_TYPE_CUSTOM_HTTP_HEADER'",message="hdrPersistenceProfile can only be set when persistenceType is PERSISTENCE_TYPE_CUSTOM_HTTP_HEADER"
79-
HdrPersistenceProfile *HdrPersistenceProfile `json:"hdrPersistenceProfile,omitempty"`
74+
HdrPersistenceProfile *HdrPersistenceProfile `json:"hdr_persistence_profile,omitempty"`
8075

8176
// AppCookiePersistenceProfile specifies the Application Cookie Persistence profile parameters.
8277
// +optional
83-
// +kubebuilder:validation:XValidation:rule="self.persistenceType == 'PERSISTENCE_TYPE_APP_COOKIE'",message="appCookiePersistenceProfile can only be set when persistenceType is PERSISTENCE_TYPE_APP_COOKIE"
84-
AppCookiePersistenceProfile *AppCookiePersistenceProfile `json:"appCookiePersistenceProfile,omitempty"`
78+
AppCookiePersistenceProfile *AppCookiePersistenceProfile `json:"app_cookie_persistence_profile,omitempty"`
8579

8680
// HTTPCookiePersistenceProfile specifies the HTTP Cookie Persistence profile parameters.
8781
// +optional
88-
// +kubebuilder:validation:XValidation:rule="self.persistenceType == 'PERSISTENCE_TYPE_HTTP_COOKIE'",message="httpCookiePersistenceProfile can only be set when persistenceType is PERSISTENCE_TYPE_HTTP_COOKIE"
89-
HTTPCookiePersistenceProfile *HTTPCookiePersistenceProfile `json:"httpCookiePersistenceProfile,omitempty"`
82+
HTTPCookiePersistenceProfile *HTTPCookiePersistenceProfile `json:"http_cookie_persistence_profile,omitempty"`
9083

9184
// IsFederated describes the object's replication scope.
9285
// +kubebuilder:default:=false
93-
IsFederated bool `json:"isFederated,omitempty"`
86+
IsFederated bool `json:"is_federated,omitempty"`
9487

9588
// Description is a user-friendly description of the persistence profile.
9689
// +optional
@@ -103,26 +96,26 @@ type IPPersistenceProfile struct {
10396
// +kubebuilder:default:=5
10497
// +kubebuilder:validation:Minimum=1
10598
// +kubebuilder:validation:Maximum=720
106-
IPPersistentTimeout int32 `json:"ipPersistentTimeout,omitempty"`
99+
IPPersistentTimeout int32 `json:"ip_persistent_timeout,omitempty"`
107100

108101
// IPMask is the mask to be applied on client IP.
109102
// +kubebuilder:validation:Minimum=0
110103
// +kubebuilder:validation:Maximum=128
111-
IPMask int32 `json:"ipMask,omitempty"`
104+
IPMask int32 `json:"ip_mask,omitempty"`
112105
}
113106

114107
// HdrPersistenceProfile specifies the custom HTTP Header Persistence profile parameters.
115108
type HdrPersistenceProfile struct {
116109
// PrstHdrName is the header name for custom header persistence.
117110
// +kubebuilder:validation:MaxLength=128
118-
PrstHdrName string `json:"prstHdrName,omitempty"`
111+
PrstHdrName string `json:"prst_hdr_name,omitempty"`
119112
}
120113

121114
// AppCookiePersistenceProfile specifies the Application Cookie Persistence profile parameters.
122115
type AppCookiePersistenceProfile struct {
123116
// PrstHdrName is the header or cookie name for application cookie persistence.
124117
// +kubebuilder:validation:MaxLength=128
125-
PrstHdrName string `json:"prstHdrName,omitempty"`
118+
PrstHdrName string `json:"prst_hdr_name,omitempty"`
126119

127120
// Timeout is the length of time after a client's connections have closed before expiring the client's persistence to a server.
128121
// +kubebuilder:default:=20
@@ -132,14 +125,14 @@ type AppCookiePersistenceProfile struct {
132125

133126
// EncryptionKey is the key to use for cookie encryption.
134127
// +kubebuilder:validation:MaxLength=1024
135-
EncryptionKey string `json:"encryptionKey,omitempty"`
128+
EncryptionKey string `json:"encryption_key,omitempty"`
136129
}
137130

138131
// HTTPCookiePersistenceProfile specifies the HTTP Cookie Persistence profile parameters.
139132
type HTTPCookiePersistenceProfile struct {
140133
// CookieName is the HTTP cookie name for cookie persistence.
141134
// +kubebuilder:validation:MaxLength=128
142-
CookieName string `json:"cookieName,omitempty"`
135+
CookieName string `json:"cookie_name,omitempty"`
143136

144137
// Timeout is the maximum lifetime of any session cookie.
145138
// +kubebuilder:validation:Minimum=0
@@ -148,15 +141,15 @@ type HTTPCookiePersistenceProfile struct {
148141

149142
// AlwaysSendCookie indicates if a persistence cookie should always be sent.
150143
// +kubebuilder:default:=false
151-
AlwaysSendCookie bool `json:"alwaysSendCookie,omitempty"`
144+
AlwaysSendCookie bool `json:"always_send_cookie,omitempty"`
152145

153146
// HTTPOnly sets the HttpOnly attribute in the cookie.
154147
// +kubebuilder:default:=false
155-
HTTPOnly bool `json:"httpOnly,omitempty"`
148+
HTTPOnly bool `json:"http_only,omitempty"`
156149

157150
// IsPersistentCookie indicates if the cookie is a persistent cookie.
158151
// +kubebuilder:default:=false
159-
IsPersistentCookie bool `json:"isPersistentCookie,omitempty"`
152+
IsPersistentCookie bool `json:"is_persistent_cookie,omitempty"`
160153
}
161154

162155
// PersistenceProfileStatus defines the observed state of PersistenceProfile

ako-crd-operator/cmd/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ func main() {
8888
// setup controller properties
8989
sessionManager := session2.NewSession(kubeClient, eventManager)
9090
sessionManager.PopulateControllerProperties(ctx)
91-
sessionManager.CreateAviClients(ctx, 1)
91+
sessionManager.CreateAviClients(ctx, 2)
9292
aviClients := sessionManager.GetAviClients()
9393

9494
cacheManager := cache.NewCache(sessionManager)
95-
if err := cacheManager.PopulateCache(constants.HealthMonitorURL); err != nil {
95+
if err := cacheManager.PopulateCache(constants.HealthMonitorURL, constants.PersistenProfileURL); err != nil {
9696
setupLog.Error(err, "unable to populate cacheManager")
9797
os.Exit(1)
9898
}
@@ -108,8 +108,10 @@ func main() {
108108
os.Exit(1)
109109
}
110110
if err := (&controller.PersistenceProfileReconciler{
111-
Client: mgr.GetClient(),
112-
Scheme: mgr.GetScheme(),
111+
Client: mgr.GetClient(),
112+
Scheme: mgr.GetScheme(),
113+
AviClient: aviClients.AviClient[1],
114+
Cache: cacheManager,
113115
}).SetupWithManager(mgr); err != nil {
114116
setupLog.Error(err, "unable to create controller", "controller", "PersistenceProfile")
115117
os.Exit(1)

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

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ spec:
4242
spec:
4343
description: Spec defines the desired state of PersistenceProfile
4444
properties:
45-
appCookiePersistenceProfile:
45+
app_cookie_persistence_profile:
4646
description: AppCookiePersistenceProfile specifies the Application
4747
Cookie Persistence profile parameters.
4848
properties:
49-
encryptionKey:
49+
encryption_key:
5050
description: EncryptionKey is the key to use for cookie encryption.
5151
maxLength: 1024
5252
type: string
53-
prstHdrName:
53+
prst_hdr_name:
5454
description: PrstHdrName is the header or cookie name for application
5555
cookie persistence.
5656
maxLength: 128
@@ -64,46 +64,38 @@ spec:
6464
minimum: 1
6565
type: integer
6666
type: object
67-
x-kubernetes-validations:
68-
- message: appCookiePersistenceProfile can only be set when persistenceType
69-
is PERSISTENCE_TYPE_APP_COOKIE
70-
rule: self.persistenceType == 'PERSISTENCE_TYPE_APP_COOKIE'
7167
description:
7268
description: Description is a user-friendly description of the persistence
7369
profile.
7470
type: string
75-
hdrPersistenceProfile:
71+
hdr_persistence_profile:
7672
description: HdrPersistenceProfile specifies the custom HTTP Header
7773
Persistence profile parameters.
7874
properties:
79-
prstHdrName:
75+
prst_hdr_name:
8076
description: PrstHdrName is the header name for custom header
8177
persistence.
8278
maxLength: 128
8379
type: string
8480
type: object
85-
x-kubernetes-validations:
86-
- message: hdrPersistenceProfile can only be set when persistenceType
87-
is PERSISTENCE_TYPE_CUSTOM_HTTP_HEADER
88-
rule: self.persistenceType == 'PERSISTPERSISTENCE_TYPE_CUSTOM_HTTP_HEADER'
89-
httpCookiePersistenceProfile:
81+
http_cookie_persistence_profile:
9082
description: HTTPCookiePersistenceProfile specifies the HTTP Cookie
9183
Persistence profile parameters.
9284
properties:
93-
alwaysSendCookie:
85+
always_send_cookie:
9486
default: false
9587
description: AlwaysSendCookie indicates if a persistence cookie
9688
should always be sent.
9789
type: boolean
98-
cookieName:
90+
cookie_name:
9991
description: CookieName is the HTTP cookie name for cookie persistence.
10092
maxLength: 128
10193
type: string
102-
httpOnly:
94+
http_only:
10395
default: false
10496
description: HTTPOnly sets the HttpOnly attribute in the cookie.
10597
type: boolean
106-
isPersistentCookie:
98+
is_persistent_cookie:
10799
default: false
108100
description: IsPersistentCookie indicates if the cookie is a persistent
109101
cookie.
@@ -115,21 +107,17 @@ spec:
115107
minimum: 0
116108
type: integer
117109
type: object
118-
x-kubernetes-validations:
119-
- message: httpCookiePersistenceProfile can only be set when persistenceType
120-
is PERSISTENCE_TYPE_HTTP_COOKIE
121-
rule: self.persistenceType == 'PERSISTENCE_TYPE_HTTP_COOKIE'
122-
ipPersistenceProfile:
110+
ip_persistence_profile:
123111
description: IPPersistenceProfile specifies the Client IP Persistence
124112
profile parameters.
125113
properties:
126-
ipMask:
114+
ip_mask:
127115
description: IPMask is the mask to be applied on client IP.
128116
format: int32
129117
maximum: 128
130118
minimum: 0
131119
type: integer
132-
ipPersistentTimeout:
120+
ip_persistent_timeout:
133121
default: 5
134122
description: IPPersistentTimeout is the length of time after a
135123
client's connections have closed before expiring the client's
@@ -139,19 +127,11 @@ spec:
139127
minimum: 1
140128
type: integer
141129
type: object
142-
x-kubernetes-validations:
143-
- message: ipPersistenceProfile can only be set when persistenceType
144-
is PERSISTENCE_TYPE_CLIENT_IP_ADDRESS
145-
rule: self.persistenceType == 'PERSISTENCE_TYPE_CLIENT_IP_ADDRESS'
146-
isFederated:
130+
is_federated:
147131
default: false
148132
description: IsFederated describes the object's replication scope.
149133
type: boolean
150-
name:
151-
description: Name is a user-friendly name for the persistence profile.
152-
maxLength: 256
153-
type: string
154-
persistenceType:
134+
persistence_type:
155135
default: PERSISTENCE_TYPE_CLIENT_IP_ADDRESS
156136
description: PersistenceType is the method used to persist clients
157137
to the same server.
@@ -166,7 +146,7 @@ spec:
166146
x-kubernetes-validations:
167147
- message: type is immutable
168148
rule: self == oldSelf
169-
serverHmDownRecovery:
149+
server_hm_down_recovery:
170150
default: HM_DOWN_PICK_NEW_SERVER
171151
description: ServerHmDownRecovery specifies behavior when a persistent
172152
server has been marked down by a health monitor.
@@ -175,9 +155,29 @@ spec:
175155
- HM_DOWN_ABORT_CONNECTION
176156
- HM_DOWN_CONTINUE_PERSISTENT_SERVER
177157
type: string
178-
required:
179-
- name
180158
type: object
159+
x-kubernetes-validations:
160+
- message: Invalid profile configuration for persistence_type. When persistence_type
161+
is CLIENT_IP_ADDRESS, CLIENT_IPV6_ADDRESS, CUSTOM_HTTP_HEADER, APP_COOKIE,
162+
or HTTP_COOKIE, its corresponding profile field (e.g. ipPersistenceProfile)
163+
must be set and other profile fields must be absent. For types like
164+
TLS, none of these specific profile fields should be set.
165+
rule: ((self.persistence_type == 'PERSISTENCE_TYPE_CLIENT_IP_ADDRESS'
166+
|| self.persistence_type == 'PERSISTENCE_TYPE_CLIENT_IPV6_ADDRESS')
167+
&& has(self.ip_persistence_profile) && !has(self.hdr_persistence_profile)
168+
&& !has(self.app_cookie_persistence_profile) && !has(self.http_cookie_persistence_profile))
169+
|| (self.persistence_type == 'PERSISTENCE_TYPE_CUSTOM_HTTP_HEADER'
170+
&& has(self.hdr_persistence_profile) && !has(self.ip_persistence_profile)
171+
&& !has(self.app_cookie_persistence_profile) && !has(self.http_cookie_persistence_profile))
172+
|| (self.persistence_type == 'PERSISTENCE_TYPE_APP_COOKIE' && has(self.app_cookie_persistence_profile)
173+
&& !has(self.ip_persistence_profile) && !has(self.hdr_persistence_profile)
174+
&& !has(self.http_cookie_persistence_profile)) || (self.persistence_type
175+
== 'PERSISTENCE_TYPE_HTTP_COOKIE' && has(self.http_cookie_persistence_profile)
176+
&& !has(self.ip_persistence_profile) && !has(self.hdr_persistence_profile)
177+
&& !has(self.app_cookie_persistence_profile)) || (self.persistence_type
178+
== 'PERSISTENCE_TYPE_TLS' && !has(self.ip_persistence_profile) &&
179+
!has(self.hdr_persistence_profile) && !has(self.app_cookie_persistence_profile)
180+
&& !has(self.http_cookie_persistence_profile))
181181
status:
182182
description: Status defines the observed state of PersistenceProfile
183183
properties:

0 commit comments

Comments
 (0)