Skip to content

Commit

Permalink
fix(kuma-cp) remove SetPagination
Browse files Browse the repository at this point in the history
Now we use GetPagination and use the accessors to the Total and NextOffset
fields.

Signed-off-by: Nikolay Nikolaev <nikolay.nikolaev@konghq.com>
  • Loading branch information
Nikolay Nikolaev committed May 11, 2020
1 parent abf1cdd commit da4bf11
Show file tree
Hide file tree
Showing 19 changed files with 16 additions and 55 deletions.
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ func (l *DataplaneResourceList) AddItem(r model.Resource) error {
func (l *DataplaneResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *DataplaneResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&DataplaneResource{})
Expand Down
4 changes: 0 additions & 4 deletions pkg/core/resources/apis/mesh/dataplane_insight.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ func (l *DataplaneInsightResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}

func (l *DataplaneInsightResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&DataplaneInsightResource{})
registry.RegistryListType(&DataplaneInsightResourceList{})
Expand Down
4 changes: 0 additions & 4 deletions pkg/core/resources/apis/mesh/dataplane_overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ func (l *DataplaneOverviewResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}

func (l *DataplaneOverviewResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func NewDataplaneOverviews(dataplanes DataplaneResourceList, insights DataplaneInsightResourceList) DataplaneOverviewResourceList {
insightsByKey := map[model.ResourceKey]*DataplaneInsightResource{}
for _, insight := range insights.Items {
Expand Down
4 changes: 0 additions & 4 deletions pkg/core/resources/apis/mesh/fault_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ func (l *FaultInjectionResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}

func (l *FaultInjectionResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&FaultInjectionResource{})
registry.RegistryListType(&FaultInjectionResourceList{})
Expand Down
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ func (l *HealthCheckResourceList) AddItem(r model.Resource) error {
func (l *HealthCheckResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *HealthCheckResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&HealthCheckResource{})
Expand Down
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (l *MeshResourceList) AddItem(r model.Resource) error {
func (l *MeshResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *MeshResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&MeshResource{})
Expand Down
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/proxytemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (l *ProxyTemplateResourceList) AddItem(r model.Resource) error {
func (l *ProxyTemplateResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *ProxyTemplateResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&ProxyTemplateResource{})
Expand Down
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/traffic_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (l *TrafficLogResourceList) AddItem(r model.Resource) error {
func (l *TrafficLogResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *TrafficLogResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&TrafficLogResource{})
Expand Down
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/traffic_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (l *TrafficPermissionResourceList) AddItem(r model.Resource) error {
func (l *TrafficPermissionResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *TrafficPermissionResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func (t *TrafficPermissionResource) Sources() []*mesh_proto.Selector {
return t.Spec.GetSources()
Expand Down
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/traffic_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (l *TrafficRouteResourceList) AddItem(r model.Resource) error {
func (l *TrafficRouteResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *TrafficRouteResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&TrafficRouteResource{})
Expand Down
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/traffic_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (l *TrafficTraceResourceList) AddItem(r model.Resource) error {
func (l *TrafficTraceResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *TrafficTraceResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&TrafficTraceResource{})
Expand Down
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/system/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ func (l *SecretResourceList) AddItem(r model.Resource) error {
func (l *SecretResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *SecretResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&SecretResource{})
Expand Down
9 changes: 8 additions & 1 deletion pkg/core/resources/model/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ type ResourceList interface {
NewItem() Resource
AddItem(Resource) error
GetPagination() *Pagination
SetPagination(Pagination)
}

type Pagination struct {
Expand All @@ -101,6 +100,14 @@ func (p *Pagination) SetTotal(total uint32) {
p.Total = total
}

func (p *Pagination) GetNextOffset() string {
return p.NextOffset
}

func (p *Pagination) SetNextOffset(nextOffset string) {
p.NextOffset = nextOffset
}

func ErrorInvalidItemType(expected, actual interface{}) error {
return fmt.Errorf("Invalid argument type: expected=%q got=%q", reflect.TypeOf(expected), reflect.TypeOf(actual))
}
4 changes: 4 additions & 0 deletions pkg/plugins/resources/k8s/native/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa v0.0.0-20200124205748-db4b343e48c1/go.mod h1:HNVadOiXCy7Jk3R2knJ+qm++zkncJxxBMpjdGgJ+UJc=
github.com/cncf/udpa v0.0.0-20200313221541-5f7e5dd04533 h1:quwtEox7jWa1KDl5BlhjkpK3lOgDPmX6KmpthELUrzc=
github.com/cncf/udpa v0.0.0-20200313221541-5f7e5dd04533/go.mod h1:HNVadOiXCy7Jk3R2knJ+qm++zkncJxxBMpjdGgJ+UJc=
github.com/cncf/udpa/go v0.0.0-20200313221541-5f7e5dd04533 h1:8wZizuKuZVu5COB7EsBYxBQz8nRcXXn5d4Gt91eJLvU=
github.com/cncf/udpa/go v0.0.0-20200313221541-5f7e5dd04533/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -77,6 +80,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191108215040-b0f2cec0e187 h1:EhxjyBkHbn/4tmZpvYtUBOdjdMmT26/b1kAUqDL77VI=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191108215040-b0f2cec0e187/go.mod h1:G1fbsNGAFpC1aaERrShZQVdUV2ZuZuv6FCl2v9JNSxQ=
github.com/envoyproxy/go-control-plane v0.9.5 h1:lRJIqDD8yjV1YyPRqecMdytjDLs2fTXq363aCib5xPU=
github.com/envoyproxy/go-control-plane v0.9.5/go.mod h1:OXl5to++W0ctG+EHWTFUjiypVxC/Y4VLc/KFU+al13s=
github.com/envoyproxy/protoc-gen-validate v0.0.0-20190405222122-d6164de49109/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=
Expand Down
4 changes: 1 addition & 3 deletions pkg/plugins/resources/k8s/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ func (c *SimpleConverter) ToCoreList(in k8s_model.KubernetesList, out core_model
_ = out.AddItem(r)
}
}
out.SetPagination(core_model.Pagination{
NextOffset: in.GetContinue(),
})
out.GetPagination().SetNextOffset(in.GetContinue())
return nil
}
4 changes: 1 addition & 3 deletions pkg/plugins/resources/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ func (c *memoryStore) List(_ context.Context, rs model.ResourceList, fs ...store
if offset+pageSize < len(records) { // set new offset only if we did not reach the end of the collection
nextOffset = strconv.Itoa(offset + opts.PageSize)
}
rs.SetPagination(model.Pagination{
NextOffset: nextOffset,
})
rs.GetPagination().SetNextOffset(nextOffset)
}

rs.GetPagination().SetTotal(uint32(len(records)))
Expand Down
4 changes: 1 addition & 3 deletions pkg/plugins/resources/postgres/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ func (r *postgresResourceStore) List(_ context.Context, resources model.Resource
if items > opts.PageSize { // set new offset only if there is next page
nextOffset = strconv.Itoa(offset + opts.PageSize)
}
resources.SetPagination(model.Pagination{
NextOffset: nextOffset,
})
resources.GetPagination().SetNextOffset(nextOffset)
}

total, err := r.countRows(string(resources.GetItemType()), opts.Mesh)
Expand Down
4 changes: 1 addition & 3 deletions pkg/plugins/resources/remote/unmarshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ func UnmarshalList(b []byte, rs model.ResourceList) error {
// we do not preserve here the size of the page, but since it is used in kumactl
// user will rerun command with the page size of his choice
if offset != "" {
rs.SetPagination(model.Pagination{
NextOffset: offset,
})
rs.GetPagination().SetNextOffset(offset)
}
}
rs.GetPagination().SetTotal(rsr.ResourceList.Total)
Expand Down
3 changes: 0 additions & 3 deletions pkg/test/resources/apis/sample/sample_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ func (l *TrafficRouteResourceList) AddItem(r model.Resource) error {
func (l *TrafficRouteResourceList) GetPagination() *model.Pagination {
return &l.Pagination
}
func (l *TrafficRouteResourceList) SetPagination(pagination model.Pagination) {
l.Pagination = pagination
}

func init() {
registry.RegisterType(&TrafficRouteResource{})
Expand Down

0 comments on commit da4bf11

Please sign in to comment.