Skip to content

Commit

Permalink
Merge pull request #102 from fuweid/fix-stale-list
Browse files Browse the repository at this point in the history
api/types: stale list doesn't support pagination
  • Loading branch information
fuweid authored Mar 5, 2024
2 parents c0cc67d + 6c26eff commit fc1a5d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions api/types/load_traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ func (r WeightedRequest) Validate() error {

switch {
case r.StaleList != nil:
return r.StaleList.Validate()
return r.StaleList.Validate(true)
case r.QuorumList != nil:
return r.QuorumList.Validate()
return r.QuorumList.Validate(false)
case r.StaleGet != nil:
return r.StaleGet.Validate()
case r.QuorumGet != nil:
Expand All @@ -207,14 +207,18 @@ func (r WeightedRequest) Validate() error {
}

// RequestList validates RequestList type.
func (r *RequestList) Validate() error {
func (r *RequestList) Validate(stale bool) error {
if err := r.KubeGroupVersionResource.Validate(); err != nil {
return fmt.Errorf("kube metadata: %v", err)
}

if r.Limit < 0 {
return fmt.Errorf("limit must >= 0")
}

if stale && r.Limit != 0 {
return fmt.Errorf("stale list doesn't support pagination option: https://github.com/kubernetes/kubernetes/issues/108003")
}
return nil
}

Expand Down
7 changes: 5 additions & 2 deletions api/types/load_traffic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ spec:
rate: 100
total: 10000
conns: 2
client: 1
contentType: json
requests:
- staleGet:
group: core
Expand All @@ -36,7 +38,6 @@ spec:
version: v1
resource: pods
namespace: default
limit: 10000
seletor: app=x2
shares: 200
- quorumList:
Expand Down Expand Up @@ -91,7 +92,7 @@ spec:
assert.Equal(t, "v1", target.Spec.Requests[2].StaleList.Version)
assert.Equal(t, "core", target.Spec.Requests[0].StaleGet.Group)
assert.Equal(t, "default", target.Spec.Requests[2].StaleList.Namespace)
assert.Equal(t, 10000, target.Spec.Requests[2].StaleList.Limit)
assert.Equal(t, 0, target.Spec.Requests[2].StaleList.Limit)
assert.Equal(t, "app=x2", target.Spec.Requests[2].StaleList.Selector)

assert.NotNil(t, target.Spec.Requests[3].QuorumList)
Expand All @@ -114,6 +115,8 @@ spec:
assert.Equal(t, "main", target.Spec.Requests[5].GetPodLog.Container)
assert.Equal(t, int64(1000), *target.Spec.Requests[5].GetPodLog.TailLines)
assert.Equal(t, int64(1024), *target.Spec.Requests[5].GetPodLog.LimitBytes)

assert.NoError(t, target.Validate())
}

func TestWeightedRequest(t *testing.T) {
Expand Down

0 comments on commit fc1a5d3

Please sign in to comment.