-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GCE: Fix subnets vs zones formatting of instance groups
- Loading branch information
Showing
7 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["instancegroup.go"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/apis/kops:go_default_library", | ||
"//pkg/apis/kops/model:go_default_library", | ||
"//vendor/github.com/golang/glog:go_default_library", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "go_default_test", | ||
srcs = ["instancegroup_test.go"], | ||
library = ":go_default_library", | ||
deps = ["//pkg/apis/kops:go_default_library"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package formatter | ||
|
||
import ( | ||
"github.com/golang/glog" | ||
"k8s.io/kops/pkg/apis/kops" | ||
"k8s.io/kops/pkg/apis/kops/model" | ||
"strings" | ||
) | ||
|
||
// InstanceGroupRenderFunction is a render function for an InstanceGroup | ||
type InstanceGroupRenderFunction func(ig *kops.InstanceGroup) string | ||
|
||
//RenderInstanceGroupSubnets renders the subnet names for an InstanceGroup | ||
func RenderInstanceGroupSubnets(cluster *kops.Cluster) InstanceGroupRenderFunction { | ||
return func(ig *kops.InstanceGroup) string { | ||
return strings.Join(ig.Spec.Subnets, ",") | ||
} | ||
} | ||
|
||
//RenderInstanceGroupZones renders the zone names for an InstanceGroup | ||
func RenderInstanceGroupZones(cluster *kops.Cluster) InstanceGroupRenderFunction { | ||
return func(ig *kops.InstanceGroup) string { | ||
zones, err := model.FindZonesForInstanceGroup(cluster, ig) | ||
if err != nil { | ||
glog.Warningf("error fetch zones for instancegroup: %v", err) | ||
return "" | ||
} | ||
return strings.Join(zones, ",") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package formatter | ||
|
||
import ( | ||
"k8s.io/kops/pkg/apis/kops" | ||
"testing" | ||
) | ||
|
||
func TestRenderInstanceGroupZones(t *testing.T) { | ||
cluster := &kops.Cluster{ | ||
Spec: kops.ClusterSpec{ | ||
Subnets: []kops.ClusterSubnetSpec{ | ||
{Name: "subnet1", Zone: "subnet1zone"}, | ||
{Name: "subnet2", Zone: "subnet2zone"}, | ||
{Name: "subnet3", Zone: "subnet3zone"}, | ||
}, | ||
}, | ||
} | ||
|
||
grid := []struct { | ||
ig *kops.InstanceGroup | ||
expected string | ||
}{ | ||
{ | ||
ig: &kops.InstanceGroup{ | ||
Spec: kops.InstanceGroupSpec{ | ||
Zones: []string{"test1", "test2"}, | ||
}, | ||
}, | ||
expected: "test1,test2", | ||
}, | ||
{ | ||
ig: &kops.InstanceGroup{ | ||
Spec: kops.InstanceGroupSpec{ | ||
Subnets: []string{"subnet1", "subnet2"}, | ||
}, | ||
}, | ||
expected: "subnet1zone,subnet2zone", | ||
}, | ||
{ | ||
ig: &kops.InstanceGroup{ | ||
Spec: kops.InstanceGroupSpec{ | ||
Subnets: []string{"badsubnet"}, | ||
}, | ||
}, | ||
expected: "", | ||
}, | ||
} | ||
for _, g := range grid { | ||
f := RenderInstanceGroupZones(cluster) | ||
actual := f(g.ig) | ||
if actual != g.expected { | ||
t.Errorf("unexpected output: %q vs %q", g.expected, actual) | ||
continue | ||
} | ||
} | ||
} |