Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tolerate non zonal NEG included in the AggregatedList API response #820

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions pkg/neg/types/cloudprovideradapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ limitations under the License.
package types

import (
"fmt"
"strings"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"
"k8s.io/klog"
"k8s.io/legacy-cloud-providers/gce"
)

const (
// aggregatedListZonalKeyPrefix is the prefix for the zonal key from AggregatedList
aggregatedListZonalKeyPrefix = "zones"
// aggregatedListGlobalKey is the global key from AggregatedList
aggregatedListGlobalKey = "global"
)

// NewAdapter takes a Cloud and returns a NetworkEndpointGroupCloud.
func NewAdapter(g *gce.Cloud) NetworkEndpointGroupCloud {
return &cloudProviderAdapter{
Expand Down Expand Up @@ -72,10 +79,19 @@ func (a *cloudProviderAdapter) AggregatedListNetworkEndpointGroup() (map[string]
}
ret := map[string][]*compute.NetworkEndpointGroup{}
for key, byZone := range all {
// key is "zones/<zone name>"
// key is scope
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a documentation link

// zonal key is "zones/<zone name>"
// regional key is "regions/<region name>"
// global key is "global"
// TODO: use cloud provider meta.KeyType and scope name as key
parts := strings.Split(key, "/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.V(4) the parts

if len(parts) != 2 {
return nil, fmt.Errorf("invalid key for AggregatedListNetworkEndpointGroup: %q", key)
if len(parts) == 1 && parts[0] == aggregatedListGlobalKey {
klog.V(4).Infof("Ignoring key %q as it is global", key)
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should log at level V(3)

}
if len(parts) != 2 || parts[0] != aggregatedListZonalKeyPrefix {
klog.Warningf("Key %q is not in a known format, ignoring", key)
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should definitely be logged as a warning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning

}
zone := parts[1]
ret[zone] = append(ret[zone], byZone...)
Expand Down