mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 21:25:09 +00:00
Update Google Cloud DNS List implementation to perform a paged walk of lists to aggregate all the DNS records.
The current `List()` implementation just lists the DNS resorce records in a given managed zone once and retruns the list. It neither performs a paged walk nor does it consider the `page_token` in the returned response. This change walks all the pages and aggregates the records in the pages and returns the aggregated list. This is potentially dangerous as it can blow up memory if there are a huge number of records in the given managed zone. But this is the best we can do without changing the provider interface too much. Next step is to define a new paged list interface and implement it.
This commit is contained in:
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package interfaces
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/api/googleapi"
|
||||
"k8s.io/kubernetes/federation/pkg/dnsprovider/rrstype"
|
||||
)
|
||||
@@ -172,8 +174,8 @@ type (
|
||||
|
||||
ResourceRecordSetsListCall interface {
|
||||
// Context(ctx context.Context) *ResourceRecordSetsListCall // TODO: Add as needed
|
||||
// Do(opts ...googleapi.CallOption) (*ResourceRecordSetsListResponse, error) // TODO: Add as needed
|
||||
Do(opts ...googleapi.CallOption) (ResourceRecordSetsListResponse, error)
|
||||
Pages(ctx context.Context, f func(ResourceRecordSetsListResponse) error) error
|
||||
// Fields(s ...googleapi.Field) *ResourceRecordSetsListCall // TODO: Add as needed
|
||||
// IfNoneMatch(entityTag string) *ResourceRecordSetsListCall // TODO: Add as needed
|
||||
// MaxResults(maxResults int64) *ResourceRecordSetsListCall // TODO: Add as needed
|
||||
|
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
dns "google.golang.org/api/dns/v1"
|
||||
"google.golang.org/api/googleapi"
|
||||
"k8s.io/kubernetes/federation/pkg/dnsprovider/providers/google/clouddns/internal/interfaces"
|
||||
@@ -34,6 +36,12 @@ func (call *ResourceRecordSetsListCall) Do(opts ...googleapi.CallOption) (interf
|
||||
return &ResourceRecordSetsListResponse{response}, err
|
||||
}
|
||||
|
||||
func (call *ResourceRecordSetsListCall) Pages(ctx context.Context, f func(interfaces.ResourceRecordSetsListResponse) error) error {
|
||||
return call.impl.Pages(ctx, func(page *dns.ResourceRecordSetsListResponse) error {
|
||||
return f(&ResourceRecordSetsListResponse{page})
|
||||
})
|
||||
}
|
||||
|
||||
func (call *ResourceRecordSetsListCall) Name(name string) interfaces.ResourceRecordSetsListCall {
|
||||
call.impl.Name(name)
|
||||
return call
|
||||
|
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package stubs
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/api/googleapi"
|
||||
"k8s.io/kubernetes/federation/pkg/dnsprovider/providers/google/clouddns/internal/interfaces"
|
||||
)
|
||||
@@ -35,6 +37,10 @@ func (call *ResourceRecordSetsListCall) Do(opts ...googleapi.CallOption) (interf
|
||||
return call.Response_, call.Err_
|
||||
}
|
||||
|
||||
func (call *ResourceRecordSetsListCall) Pages(ctx context.Context, f func(interfaces.ResourceRecordSetsListResponse) error) error {
|
||||
return f(call.Response_)
|
||||
}
|
||||
|
||||
func (call *ResourceRecordSetsListCall) Name(name string) interfaces.ResourceRecordSetsListCall {
|
||||
call.Name_ = name
|
||||
return call
|
||||
|
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package clouddns
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/kubernetes/federation/pkg/dnsprovider"
|
||||
"k8s.io/kubernetes/federation/pkg/dnsprovider/providers/google/clouddns/internal/interfaces"
|
||||
"k8s.io/kubernetes/federation/pkg/dnsprovider/rrstype"
|
||||
@@ -30,15 +32,26 @@ type ResourceRecordSets struct {
|
||||
impl interfaces.ResourceRecordSetsService
|
||||
}
|
||||
|
||||
// List returns a list of resource records in the given project and
|
||||
// managed zone.
|
||||
// !!CAUTION!! Your memory might explode if you have a huge number of
|
||||
// records in your managed zone.
|
||||
func (rrsets ResourceRecordSets) List() ([]dnsprovider.ResourceRecordSet, error) {
|
||||
response, err := rrsets.impl.List(rrsets.project(), rrsets.zone.impl.Name()).Do()
|
||||
var list []dnsprovider.ResourceRecordSet
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
call := rrsets.impl.List(rrsets.project(), rrsets.zone.impl.Name())
|
||||
err := call.Pages(ctx, func(page interfaces.ResourceRecordSetsListResponse) error {
|
||||
for _, rrset := range page.Rrsets() {
|
||||
list = append(list, ResourceRecordSet{rrset, &rrsets})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]dnsprovider.ResourceRecordSet, len(response.Rrsets()))
|
||||
for i, rrset := range response.Rrsets() {
|
||||
list[i] = ResourceRecordSet{rrset, &rrsets}
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user