Skip to content

Commit 8fef048

Browse files
committed
test/e2e: add MC smoke test
Far away from being the right tests we need to test this whole workload but it's a start. Just making sure we can see the daemon (1) actually converge to the new config. (Next step would be to deploy a pod with an hostPath referencing an MC file, exec into this pod and verify the file is rightly there) Signed-off-by: Antonio Murdaca <[email protected]>
1 parent b4ddac1 commit 8fef048

File tree

1 file changed

+109
-3
lines changed

1 file changed

+109
-3
lines changed

test/e2e/mcd_test.go

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
package e2e_test
22

33
import (
4-
"testing"
4+
"fmt"
55
"strings"
6+
"testing"
7+
"time"
68

9+
ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
710
"k8s.io/api/core/v1"
811
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
912
"k8s.io/apimachinery/pkg/labels"
13+
"k8s.io/apimachinery/pkg/util/uuid"
14+
"k8s.io/apimachinery/pkg/util/wait"
1015

1116
"github.com/openshift/machine-config-operator/cmd/common"
17+
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
1218
)
1319

1420
// Test case for https://github.com/openshift/machine-config-operator/issues/358
1521
func TestMCDToken(t *testing.T) {
1622
cb, err := common.NewClientBuilder("")
17-
if err != nil{
23+
if err != nil {
1824
t.Errorf("%#v", err)
1925
}
20-
k := cb.KubeClientOrDie("sanity-test")
26+
k := cb.KubeClientOrDie("mcd-token-test")
2127

2228
listOptions := metav1.ListOptions{
2329
LabelSelector: labels.SelectorFromSet(labels.Set{"k8s-app": "machine-config-daemon"}).String(),
@@ -40,3 +46,103 @@ func TestMCDToken(t *testing.T) {
4046
}
4147
}
4248
}
49+
50+
func mcLabelForWorkers() map[string]string {
51+
mcLabels := make(map[string]string)
52+
mcLabels["machineconfiguration.openshift.io/role"] = "worker"
53+
return mcLabels
54+
}
55+
56+
func createMCFile(path, content string, mode int) ignv2_2types.File {
57+
return ignv2_2types.File{
58+
FileEmbedded1: ignv2_2types.FileEmbedded1{
59+
Contents: ignv2_2types.FileContents{
60+
Source: content,
61+
},
62+
Mode: &mode,
63+
},
64+
Node: ignv2_2types.Node{
65+
Filesystem: "root",
66+
Path: path,
67+
},
68+
}
69+
}
70+
71+
func TestMCDeployed(t *testing.T) {
72+
cb, err := common.NewClientBuilder("")
73+
if err != nil {
74+
t.Errorf("%#v", err)
75+
}
76+
mcClient := cb.MachineConfigClientOrDie("mc-file-add")
77+
k := cb.KubeClientOrDie("mc-file-add")
78+
79+
// create a dummy MC
80+
mcName := fmt.Sprintf("00-0add-a-file-%s", uuid.NewUUID())
81+
mcadd := &mcv1.MachineConfig{}
82+
mcadd.ObjectMeta = metav1.ObjectMeta{
83+
Name: mcName,
84+
Labels: mcLabelForWorkers(),
85+
}
86+
mcadd.Spec = mcv1.MachineConfigSpec{
87+
Config: ignv2_2types.Config{
88+
Ignition: ignv2_2types.Ignition{
89+
Version: "2.2.0",
90+
},
91+
Storage: ignv2_2types.Storage{
92+
Files: []ignv2_2types.File{
93+
createMCFile("/etc/mytestconf", "data:,test", 420),
94+
},
95+
},
96+
},
97+
}
98+
99+
// create the dummy MC now
100+
_, err = mcClient.MachineconfigurationV1().MachineConfigs().Create(mcadd)
101+
if err != nil {
102+
t.Errorf("failed to create machine config %v", err)
103+
}
104+
105+
// grab the latest worker- MC
106+
var newMCName string
107+
err = wait.Poll(2*time.Second, 5*time.Minute, func() (bool, error) {
108+
mcp, err := mcClient.MachineconfigurationV1().MachineConfigPools().Get("worker", metav1.GetOptions{})
109+
if err != nil {
110+
return false, err
111+
}
112+
for _, mc := range mcp.Status.Configuration.Source {
113+
if mc.Name == mcName {
114+
newMCName = mcp.Status.Configuration.Name
115+
return true, nil
116+
}
117+
}
118+
return false, nil
119+
})
120+
121+
listOptions := metav1.ListOptions{
122+
LabelSelector: labels.SelectorFromSet(labels.Set{"k8s-app": "machine-config-daemon"}).String(),
123+
}
124+
125+
err = wait.Poll(3*time.Second, 5*time.Minute, func() (bool, error) {
126+
mcdList, err := k.CoreV1().Pods("openshift-machine-config-operator").List(listOptions)
127+
if err != nil {
128+
return false, err
129+
}
130+
131+
for _, pod := range mcdList.Items {
132+
res, err := k.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{}).DoRaw()
133+
if err != nil {
134+
// do not error out, we may be rebooting, that's why we list at every iteration
135+
return false, nil
136+
}
137+
for _, line := range strings.Split(string(res), "\n") {
138+
if strings.Contains(line, "completed update for config "+newMCName) {
139+
return true, nil
140+
}
141+
}
142+
}
143+
return false, nil
144+
})
145+
if err != nil {
146+
t.Errorf("machine config didn't result in file being on any worker: %v", err)
147+
}
148+
}

0 commit comments

Comments
 (0)