Skip to content

Commit

Permalink
test/e2e: check MC deployed on every node
Browse files Browse the repository at this point in the history
TestMCDeployed wasn't checking that the MC was indeed deployed on every
node (worker). Fix that by checking every node. The test is going to
take a little longer but it's more robust as well.

Signed-off-by: Antonio Murdaca <runcom@linux.com>
  • Loading branch information
runcom committed Feb 17, 2019
1 parent 745693c commit 64b2987
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions test/e2e/mcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"

"github.com/openshift/machine-config-operator/cmd/common"
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/openshift/machine-config-operator/pkg/daemon/constants"
)

// Test case for https://github.com/openshift/machine-config-operator/issues/358
Expand Down Expand Up @@ -104,7 +106,7 @@ func TestMCDeployed(t *testing.T) {

// grab the latest worker- MC
var newMCName string
err = wait.Poll(2*time.Second, 5*time.Minute, func() (bool, error) {
if err := wait.PollImmediate(2*time.Second, 5*time.Minute, func() (bool, error) {
mcp, err := mcClient.MachineconfigurationV1().MachineConfigPools().Get("worker", metav1.GetOptions{})
if err != nil {
return false, err
Expand All @@ -116,33 +118,41 @@ func TestMCDeployed(t *testing.T) {
}
}
return false, nil
})

listOptions := metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(labels.Set{"k8s-app": "machine-config-daemon"}).String(),
}); err != nil {
t.Errorf("machine config hasn't been picked by the pool: %v", err)
}

err = wait.Poll(3*time.Second, 5*time.Minute, func() (bool, error) {
mcdList, err := k.CoreV1().Pods("openshift-machine-config-operator").List(listOptions)
visited := make(map[string]bool)
if err := wait.Poll(2*time.Second, 5*time.Minute, func() (bool, error) {
nodes, err := getNodesByRole(k, "worker")
if err != nil {
return false, err
}

for _, pod := range mcdList.Items {
res, err := k.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{}).DoRaw()
if err != nil {
// do not error out, we may be rebooting, that's why we list at every iteration
return false, nil
for _, node := range nodes {
if visited[node.Name] {
continue
}
for _, line := range strings.Split(string(res), "\n") {
if strings.Contains(line, "completed update for config "+newMCName) {
if node.Annotations[constants.CurrentMachineConfigAnnotationKey] == newMCName {
visited[node.Name] = true
if len(visited) == len(nodes) {
return true, nil
}
continue
}
}
return false, nil
})
if err != nil {
}); err != nil {
t.Errorf("machine config didn't result in file being on any worker: %v", err)
}
}

func getNodesByRole(k kubernetes.Interface, role string) ([]v1.Node, error) {
listOptions := metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(labels.Set{fmt.Sprintf("node-role.kubernetes.io/%s", role): ""}).String(),
}
nodes, err := k.CoreV1().Nodes().List(listOptions)
if err != nil {
return nil, err
}
return nodes.Items, nil
}

0 comments on commit 64b2987

Please sign in to comment.