@@ -290,11 +290,30 @@ type CanaryAnalysis struct {
290
290
type SessionAffinity struct {
291
291
// CookieName is the key that will be used for the session affinity cookie.
292
292
CookieName string `json:"cookieName,omitempty"`
293
- // MaxAge indicates the number of seconds until the session affinity cookie will expire.
294
293
// ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
294
+ // Domain defines the host to which the cookie will be sent.
295
+ // +optional
296
+ Domain string `json:"domain,omitempty"`
297
+ // HttpOnly forbids JavaScript from accessing the cookie, for example, through the Document.cookie property.
298
+ // +optional
299
+ HttpOnly bool `json:"httpOnly,omitempty"`
300
+ // MaxAge indicates the number of seconds until the session affinity cookie will expire.
295
301
// The default value is 86,400 seconds, i.e. a day.
296
302
// +optional
297
303
MaxAge int `json:"maxAge,omitempty"`
304
+ // Partitioned indicates that the cookie should be stored using partitioned storage.
305
+ // +optional
306
+ Partitioned bool `json:"partitioned,omitempty"`
307
+ // Path indicates the path that must exist in the requested URL for the browser to send the Cookie header.
308
+ // +optional
309
+ Path string `json:"path,omitempty"`
310
+ // SameSite controls whether or not a cookie is sent with cross-site requests.
311
+ // +optional
312
+ // +kubebuilder:validation:Enum=Strict;Lax;None
313
+ SameSite string `json:"sameSite,omitempty"`
314
+ // Secure indicates that the cookie is sent to the server only when a request is made with the https: scheme (except on localhost)
315
+ // +optional
316
+ Secure bool `json:"secure,omitempty"`
298
317
// PrimaryCookieName is the key that will be used for the primary session affinity cookie.
299
318
// +optional
300
319
PrimaryCookieName string `json:"primaryCookieName,omitempty"`
@@ -640,3 +659,36 @@ func (c *Canary) SkipAnalysis() bool {
640
659
}
641
660
return c .Spec .SkipAnalysis
642
661
}
662
+
663
+ // BuildCookie returns the cookie that should be used as the value of a Set-Cookie header
664
+ func (s * SessionAffinity ) BuildCookie (cookieName string ) string {
665
+ cookie := fmt .Sprintf ("%s; %s=%d" , cookieName , "Max-Age" ,
666
+ s .GetMaxAge (),
667
+ )
668
+
669
+ if s .Domain != "" {
670
+ cookie += fmt .Sprintf ("; %s=%s" , "Domain" , s .Domain )
671
+ }
672
+
673
+ if s .HttpOnly {
674
+ cookie += fmt .Sprintf ("; %s" , "HttpOnly" )
675
+ }
676
+
677
+ if s .Partitioned {
678
+ cookie += fmt .Sprintf ("; %s" , "Partitioned" )
679
+ }
680
+
681
+ if s .Path != "" {
682
+ cookie += fmt .Sprintf ("; %s=%s" , "Path" , s .Path )
683
+ }
684
+
685
+ if s .SameSite != "" {
686
+ cookie += fmt .Sprintf ("; %s=%s" , "SameSite" , s .SameSite )
687
+ }
688
+
689
+ if s .Secure {
690
+ cookie += fmt .Sprintf ("; %s" , "Secure" )
691
+ }
692
+
693
+ return cookie
694
+ }
0 commit comments