Skip to content

Commit

Permalink
fix: implement a file based test for session persistence
Browse files Browse the repository at this point in the history
Signed-off-by: Kensei Nakada <handbomusic@gmail.com>
  • Loading branch information
sanposhiho committed Jul 18, 2024
1 parent 6ed0db1 commit 0f45c69
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 282 deletions.
2 changes: 1 addition & 1 deletion internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (t *Translator) processHTTPRouteRule(httpRoute *HTTPRouteContext, ruleIdx i
if err != nil {
return nil, err

Check warning on line 330 in internal/gatewayapi/route.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/route.go#L326-L330

Added lines #L326 - L330 were not covered by tests
}
sessionPersistence.Cookie.TTL = &ttl
sessionPersistence.Cookie.TTL = &metav1.Duration{Duration: ttl}

Check warning on line 332 in internal/gatewayapi/route.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/route.go#L332

Added line #L332 was not covered by tests
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/http"
"net/netip"
"reflect"
"time"

"golang.org/x/exp/slices"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -588,7 +587,7 @@ type SessionPersistence struct {
// CookieBasedSessionPersistence defines the configuration for cookie-based session persistence.
// +k8s:deepcopy-gen=true
type CookieBasedSessionPersistence struct {
TTL *time.Duration `json:"ttl,omitempty" yaml:"ttl,omitempty"`
TTL *metav1.Duration `json:"ttl,omitempty" yaml:"ttl,omitempty"`
}

// HeaderBasedSessionPersistence defines the configuration for header-based session persistence.
Expand Down
3 changes: 1 addition & 2 deletions internal/ir/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/xds/translator/session_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *sessionPersistence) patchHCM(mgr *hcmv3.HttpConnectionManager, irListen
Cookie: &httpv3.Cookie{
Name: sp.SessionName,
Path: routePathToCookiePath(route.PathMatch),
Ttl: durationpb.New(*sp.Cookie.TTL),
Ttl: durationpb.New(sp.Cookie.TTL.Duration),
},
}
case sp.Header != nil:
Expand Down
276 changes: 0 additions & 276 deletions internal/xds/translator/session_persistence_test.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
http:
- name: "first-listener"
address: "0.0.0.0"
port: 10080
hostnames:
- "*"
path:
mergeSlashes: true
escapedSlashesAction: UnescapeAndRedirect
routes:
- name: "header-based-session-persistence-route"
hostname: "*"
pathMatch:
safeRegex: "/v1/.*"
sessionPersistence:
sessionName: "session1"
header: {}
destination:
name: "regex-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
- name: "cookie-based-session-persistence-route-regex"
hostname: "*"
pathMatch:
safeRegex: "/v1/.*/hoge"
sessionPersistence:
sessionName: "session1"
cookie:
ttl: "1h"
destination:
name: "regex-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
- name: "cookie-based-session-persistence-route-prefix"
hostname: "*"
pathMatch:
prefix: "/v2/"
sessionPersistence:
sessionName: "session1"
cookie:
ttl: "1h"
destination:
name: "regex-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
- name: "cookie-based-session-persistence-route-exact"
hostname: "*"
pathMatch:
exact: "/v3/user"
sessionPersistence:
sessionName: "session1"
cookie:
ttl: "1h"
destination:
name: "regex-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000

Check failure on line 65 in internal/xds/translator/testdata/in/xds-ir/http-route-session-persistence.yaml

View workflow job for this annotation

GitHub Actions / lint

65:22 [new-line-at-end-of-file] no new line character at the end of file

Check failure on line 65 in internal/xds/translator/testdata/in/xds-ir/http-route-session-persistence.yaml

View workflow job for this annotation

GitHub Actions / lint

65:22 [new-line-at-end-of-file] no new line character at the end of file
Loading

0 comments on commit 0f45c69

Please sign in to comment.