Skip to content

Commit

Permalink
Move GetClusterZones() to e2enode
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenichi Omichi committed Mar 10, 2020
1 parent 307bafb commit c586d88
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 30 deletions.
21 changes: 21 additions & 0 deletions test/e2e/framework/node/resource.go
Expand Up @@ -471,3 +471,24 @@ func PodNodePairs(c clientset.Interface, ns string) ([]PodNode, error) {

return result, nil
}

// GetClusterZones returns the values of zone label collected from all nodes.
func GetClusterZones(c clientset.Interface) (sets.String, error) {
nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, fmt.Errorf("Error getting nodes while attempting to list cluster zones: %v", err)
}

// collect values of zone label from all nodes
zones := sets.NewString()
for _, node := range nodes.Items {
if zone, found := node.Labels[v1.LabelZoneFailureDomain]; found {
zones.Insert(zone)
}

if zone, found := node.Labels[v1.LabelZoneFailureDomainStable]; found {
zones.Insert(zone)
}
}
return zones, nil
}
1 change: 1 addition & 0 deletions test/e2e/framework/skipper/BUILD
Expand Up @@ -16,6 +16,7 @@ go_library(
"//staging/src/k8s.io/client-go/dynamic:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//test/e2e/framework:go_default_library",
"//test/e2e/framework/node:go_default_library",
"//test/e2e/framework/ssh:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
],
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/framework/skipper/skipper.go
Expand Up @@ -38,6 +38,7 @@ import (
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/test/e2e/framework"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
)

Expand Down Expand Up @@ -178,7 +179,7 @@ func SkipUnlessProviderIs(supportedProviders ...string) {

// SkipUnlessMultizone skips if the cluster does not have multizone.
func SkipUnlessMultizone(c clientset.Interface) {
zones, err := framework.GetClusterZones(c)
zones, err := e2enode.GetClusterZones(c)
if err != nil {
skipInternalf(1, "Error listing cluster zones")
}
Expand All @@ -189,7 +190,7 @@ func SkipUnlessMultizone(c clientset.Interface) {

// SkipIfMultizone skips if the cluster has multizone.
func SkipIfMultizone(c clientset.Interface) {
zones, err := framework.GetClusterZones(c)
zones, err := e2enode.GetClusterZones(c)
if err != nil {
skipInternalf(1, "Error listing cluster zones")
}
Expand Down
21 changes: 0 additions & 21 deletions test/e2e/framework/util.go
Expand Up @@ -1911,27 +1911,6 @@ func DsFromData(data []byte) (*appsv1.DaemonSet, error) {
return &ds, nil
}

// GetClusterZones returns the values of zone label collected from all nodes.
func GetClusterZones(c clientset.Interface) (sets.String, error) {
nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, fmt.Errorf("Error getting nodes while attempting to list cluster zones: %v", err)
}

// collect values of zone label from all nodes
zones := sets.NewString()
for _, node := range nodes.Items {
if zone, found := node.Labels[v1.LabelZoneFailureDomain]; found {
zones.Insert(zone)
}

if zone, found := node.Labels[v1.LabelZoneFailureDomainStable]; found {
zones.Insert(zone)
}
}
return zones, nil
}

// GetFileModeRegex returns a file mode related regex which should be matched by the mounttest pods' output.
// If the given mask is nil, then the regex will contain the default OS file modes, which are 0644 for Linux and 0775 for Windows.
func GetFileModeRegex(filePath string, mask *int32) string {
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/scheduling/ubernetes_lite.go
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2erc "k8s.io/kubernetes/test/e2e/framework/rc"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
Expand Down Expand Up @@ -113,7 +114,7 @@ func SpreadServiceOrFail(f *framework.Framework, replicaCount int, image string)
framework.ExpectNoError(err)

// Now make sure they're spread across zones
zoneNames, err := framework.GetClusterZones(f.ClientSet)
zoneNames, err := e2enode.GetClusterZones(f.ClientSet)
framework.ExpectNoError(err)
checkZoneSpreading(f.ClientSet, pods, zoneNames.List())
}
Expand All @@ -131,7 +132,7 @@ func getZoneNameForNode(node v1.Node) (string, error) {

// Return the number of zones in which we have nodes in this cluster.
func getZoneCount(c clientset.Interface) (int, error) {
zoneNames, err := framework.GetClusterZones(c)
zoneNames, err := e2enode.GetClusterZones(c)
if err != nil {
return -1, err
}
Expand Down Expand Up @@ -227,7 +228,7 @@ func SpreadRCOrFail(f *framework.Framework, replicaCount int32, image string, ar
framework.ExpectNoError(err)

// Now make sure they're spread across zones
zoneNames, err := framework.GetClusterZones(f.ClientSet)
zoneNames, err := e2enode.GetClusterZones(f.ClientSet)
framework.ExpectNoError(err)
checkZoneSpreading(f.ClientSet, pods, zoneNames.List())
}
3 changes: 2 additions & 1 deletion test/e2e/scheduling/ubernetes_lite_volumes.go
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/kubernetes/test/e2e/framework"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
"k8s.io/kubernetes/test/e2e/framework/providers/gce"
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
Expand Down Expand Up @@ -189,7 +190,7 @@ func PodsUseStaticPVsOrFail(f *framework.Framework, podCount int, image string)
c := f.ClientSet
ns := f.Namespace.Name

zones, err := framework.GetClusterZones(c)
zones, err := e2enode.GetClusterZones(c)
framework.ExpectNoError(err)
zonelist := zones.List()
ginkgo.By("Creating static PVs across zones")
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/storage/regional_pd.go
Expand Up @@ -40,6 +40,7 @@ import (
volumehelpers "k8s.io/cloud-provider/volume/helpers"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/test/e2e/framework"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
Expand Down Expand Up @@ -140,7 +141,7 @@ func testVolumeProvisioning(c clientset.Interface, ns string) {

err := checkGCEPD(volume, "pd-standard")
framework.ExpectNoError(err, "checkGCEPD")
zones, err := framework.GetClusterZones(c)
zones, err := e2enode.GetClusterZones(c)
framework.ExpectNoError(err, "GetClusterZones")
err = verifyZonesInPV(volume, zones, false /* match */)
framework.ExpectNoError(err, "verifyZonesInPV")
Expand Down Expand Up @@ -547,7 +548,7 @@ func newPodTemplate(labels map[string]string) *v1.PodTemplateSpec {
}

func getTwoRandomZones(c clientset.Interface) []string {
zones, err := framework.GetClusterZones(c)
zones, err := e2enode.GetClusterZones(c)
framework.ExpectNoError(err)
gomega.Expect(zones.Len()).To(gomega.BeNumerically(">=", 2),
"The test should only be run in multizone clusters.")
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/storage/volume_provisioning.go
Expand Up @@ -46,6 +46,7 @@ import (
storageutil "k8s.io/kubernetes/pkg/apis/storage/v1/util"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/auth"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
"k8s.io/kubernetes/test/e2e/framework/providers/gce"
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
Expand Down Expand Up @@ -1056,7 +1057,7 @@ func deleteProvisionedVolumesAndDisks(c clientset.Interface, pvs []*v1.Persisten
}

func getRandomClusterZone(c clientset.Interface) string {
zones, err := framework.GetClusterZones(c)
zones, err := e2enode.GetClusterZones(c)
framework.ExpectNoError(err)
framework.ExpectNotEqual(len(zones), 0)

Expand Down

0 comments on commit c586d88

Please sign in to comment.