Skip to content

Commit d7b26f6

Browse files
authored
Add Target fallback support (#340)
* Update go-kong * Update JSON schema * Add failover target test
1 parent 5c53eb1 commit d7b26f6

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/hashicorp/go-retryablehttp v0.7.7
2020
github.com/hexops/gotextdiff v1.0.3
2121
github.com/kong/deck v1.50.0
22-
github.com/kong/go-kong v0.67.0
22+
github.com/kong/go-kong v0.68.0
2323
github.com/samber/lo v1.50.0
2424
github.com/shirou/gopsutil/v3 v3.24.5
2525
github.com/ssgelm/cookiejarparser v1.0.1

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ github.com/kong/go-apiops v0.1.47 h1:2Y4m36WY4YTOJPBFzaoa9BzKK7fu9c2IYznEwOaPC0c
224224
github.com/kong/go-apiops v0.1.47/go.mod h1:hKnHJ3UyeuG932SkI/yMpuT/PqSqGXNTS1zhno1lDqg=
225225
github.com/kong/go-kong v0.67.0 h1:54zXKc58IZpZdlJCv8p95SJjejTxT+cwbWXw97icCak=
226226
github.com/kong/go-kong v0.67.0/go.mod h1:J0vGB3wsZ2i99zly1zTRe3v7rOKpkhQZRwbcTFP76qM=
227+
github.com/kong/go-kong v0.67.1-0.20250912114108-d80cef212ee2 h1:Z7sbkIILPRhTFZJkvg7+mpBLd1/dDV0vLA0jCqFLa0U=
228+
github.com/kong/go-kong v0.67.1-0.20250912114108-d80cef212ee2/go.mod h1:J0vGB3wsZ2i99zly1zTRe3v7rOKpkhQZRwbcTFP76qM=
229+
github.com/kong/go-kong v0.68.0 h1:rQrLYRKXD6/xf41GBXj9Ns+woAH9p6a4VvcXNMiPZPI=
230+
github.com/kong/go-kong v0.68.0/go.mod h1:J0vGB3wsZ2i99zly1zTRe3v7rOKpkhQZRwbcTFP76qM=
227231
github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY=
228232
github.com/kong/go-slugify v1.0.0/go.mod h1:dbR2h3J2QKXQ1k0aww6cN7o4cIcwlWflr6RKRdcoaiw=
229233
github.com/kong/kubernetes-configuration v1.4.2 h1:/OafLbl2NucvgQV7Xf/uneIgjxmPPUeE92BrssfVAQY=

pkg/file/kong_json_schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,9 @@
12901290
},
12911291
"weight": {
12921292
"type": "integer"
1293+
},
1294+
"failover": {
1295+
"type": "boolean"
12931296
}
12941297
},
12951298
"additionalProperties": false,
@@ -2088,6 +2091,9 @@
20882091
},
20892092
"weight": {
20902093
"type": "integer"
2094+
},
2095+
"failover": {
2096+
"type": "boolean"
20912097
}
20922098
},
20932099
"additionalProperties": false,

tests/integration/sync_test.go

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,17 @@ var (
691691
},
692692
}
693693

694+
target_failover = []*kong.Target{
695+
{
696+
Target: kong.String("198.51.100.11:80"),
697+
Upstream: &kong.Upstream{
698+
ID: kong.String("a6f89ffc-1e53-4b01-9d3d-7a142bcd"),
699+
},
700+
Weight: kong.Int(100),
701+
Failover: kong.Bool(true),
702+
},
703+
}
704+
694705
targetZeroWeight = []*kong.Target{
695706
{
696707
Target: kong.String("198.51.100.11:80"),
@@ -2890,6 +2901,42 @@ func Test_Sync_Upstream_Target_With_Sticky_Sessions(t *testing.T) {
28902901
}
28912902
}
28922903

2904+
// test scope:
2905+
// - 3.11
2906+
func Test_Sync_Upstream_Failover_Target(t *testing.T) {
2907+
// setup stage
2908+
client, err := getTestClient()
2909+
if err != nil {
2910+
t.Fatal(err.Error())
2911+
}
2912+
2913+
tests := []struct {
2914+
name string
2915+
initialKongFile string
2916+
kongFile string
2917+
expectedState utils.KongRawState
2918+
}{
2919+
{
2920+
name: "creates a failover target",
2921+
kongFile: "testdata/sync/045-create-upstream-and-failover-target/kong.yaml",
2922+
expectedState: utils.KongRawState{
2923+
Upstreams: upstream,
2924+
Targets: target_failover,
2925+
},
2926+
},
2927+
}
2928+
2929+
for _, tc := range tests {
2930+
t.Run(tc.name, func(t *testing.T) {
2931+
runWhen(t, "enterprise", ">=3.12.0")
2932+
setup(t)
2933+
2934+
sync(tc.kongFile)
2935+
testKongState(t, client, false, tc.expectedState, nil)
2936+
})
2937+
}
2938+
}
2939+
28932940
// test scope:
28942941
// - 3.x
28952942
func Test_Sync_Upstream_Target_From_3x(t *testing.T) {
@@ -3094,9 +3141,9 @@ func Test_Sync_Upstreams_Target_ZeroWeight_3x(t *testing.T) {
30943141
}
30953142

30963143
tests := []struct {
3097-
name string
3098-
kongFile string
3099-
expectedState utils.KongRawState
3144+
name string
3145+
kongFile string
3146+
expectedState utils.KongRawState
31003147
runWhenVersion string
31013148
}{
31023149
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
_format_version: "3.0"
2+
upstreams:
3+
- name: upstream1
4+
targets:
5+
- target: 198.51.100.11:80
6+
failover: true

0 commit comments

Comments
 (0)