forked from submariner-io/submariner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper functions for e2e tests (submariner-io#198)
* Add helper functions for e2e tests Added some helper functions for upcoming e2e enhancements. Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
- Loading branch information
Showing
6 changed files
with
186 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package framework | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// FindNodesByGatewayLabel finds the nodes in a given cluster by matching 'submariner.io/gateway' value. A missing label | ||
// is treated as false. Note the control plane node labeled as master is ignored. | ||
func (f *Framework) FindNodesByGatewayLabel(cluster ClusterIndex, isGateway bool) []*v1.Node { | ||
nodes := AwaitUntil("list nodes", func() (interface{}, error) { | ||
// Ignore the control plane node labeled as master as it doesn't allow scheduling of pods | ||
return f.ClusterClients[cluster].CoreV1().Nodes().List(metav1.ListOptions{ | ||
LabelSelector: "!node-role.kubernetes.io/master", | ||
}) | ||
}, NoopCheckResult).(*v1.NodeList) | ||
|
||
expLabelValue := strconv.FormatBool(isGateway) | ||
retNodes := []*v1.Node{} | ||
for i := range nodes.Items { | ||
value, exists := nodes.Items[i].Labels[GatewayLabel] | ||
if !exists { | ||
value = "false" | ||
} | ||
|
||
if value == expLabelValue { | ||
retNodes = append(retNodes, &nodes.Items[i]) | ||
} | ||
} | ||
|
||
return retNodes | ||
} | ||
|
||
// SetGatewayLabelOnNode sets the 'submariner.io/gateway' value for a node to the specified value. | ||
func (f *Framework) SetGatewayLabelOnNode(cluster ClusterIndex, nodeName string, isGateway bool) { | ||
// Escape the '/' char in the label name with the special sequence "~1" so it isn't treated as part of the path | ||
DoPatchOperation("/metadata/labels/"+strings.Replace(GatewayLabel, "/", "~1", -1), strconv.FormatBool(isGateway), | ||
func(pt types.PatchType, payload []byte) error { | ||
_, err := f.ClusterClients[cluster].CoreV1().Nodes().Patch(nodeName, pt, payload) | ||
return err | ||
}) | ||
} |
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,37 @@ | ||
package framework | ||
|
||
import ( | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// AwaitPodsByAppLabel finds pods in a given cluster whose 'app' label value matches a specified value. If the specified | ||
// expectedCount >= 0, the function waits until the number of pods equals the expectedCount. | ||
func (f *Framework) AwaitPodsByAppLabel(cluster ClusterIndex, appName string, namespace string, expectedCount int) *v1.PodList { | ||
return AwaitUntil("find pods for app "+appName, func() (interface{}, error) { | ||
return f.ClusterClients[cluster].CoreV1().Pods(namespace).List(metav1.ListOptions{ | ||
LabelSelector: "app=" + appName, | ||
}) | ||
}, func(result interface{}) (bool, error) { | ||
pods := result.(*v1.PodList) | ||
if expectedCount < 0 || len(pods.Items) == expectedCount { | ||
return true, nil | ||
} | ||
|
||
Logf("Actual pod count %d does not match the expected pod count %d - retrying...", len(pods.Items), expectedCount) | ||
return false, nil | ||
}).(*v1.PodList) | ||
} | ||
|
||
// AwaitSubmarinerEnginePod finds the submariner engine pod in a given cluster, waiting if necessary for a period of time | ||
// for the pod to materialize. | ||
func (f *Framework) AwaitSubmarinerEnginePod(cluster ClusterIndex) *v1.Pod { | ||
return &f.AwaitPodsByAppLabel(cluster, SubmarinerEngine, TestContext.SubmarinerNamespace, 1).Items[0] | ||
} | ||
|
||
// DeletePod deletes the pod for the given name and namespace. | ||
func (f *Framework) DeletePod(cluster ClusterIndex, podName string, namespace string) { | ||
AwaitUntil("list pods", func() (interface{}, error) { | ||
return nil, f.ClusterClients[cluster].CoreV1().Pods(namespace).Delete(podName, &metav1.DeleteOptions{}) | ||
}, NoopCheckResult) | ||
} |
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