@@ -2,25 +2,36 @@ package machine_config
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
6
+ "io/ioutil"
5
7
"path/filepath"
8
+ "time"
6
9
10
+ "github.com/ghodss/yaml"
7
11
g "github.com/onsi/ginkgo/v2"
8
12
o "github.com/onsi/gomega"
13
+ //e2e "k8s.io/kubernetes/test/e2e/framework"
9
14
15
+ mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
16
+ //mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
17
+ //ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
10
18
corev1 "k8s.io/api/core/v1"
11
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
20
21
+ mcClient "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
13
22
exutil "github.com/openshift/origin/test/extended/util"
23
+
24
+ "k8s.io/apimachinery/pkg/util/wait"
14
25
)
15
26
16
27
var (
17
28
MCOMachineConfigBaseDir = exutil .FixturePath ("testdata" , "machine_config" )
18
- oc = exutil .NewCLIWithoutNamespace ("machine-config" )
29
+ oc = exutil .NewCLIWithoutNamespace ("machine-config" )
19
30
)
20
31
21
32
var _ = g .BeforeSuite (func () {
22
33
inputPullSecretName := "my-input-pull"
23
- ps , err := oc .AsAdmin ().AdminKubeClient ().CoreV1 ().Secrets ("openshift-config" ).Get (context .Background (), "pull-secret" , metav1.GetOptions {})
34
+ ps , err := oc .AsAdmin ().AdminKubeClient ().CoreV1 ().Secrets ("openshift-config" ).Get (context .TODO (), "pull-secret" , metav1.GetOptions {})
24
35
o .Expect (err ).NotTo (o .HaveOccurred (), "Get pull-secret from openshift-config" )
25
36
localInputPullSecret := & corev1.Secret {
26
37
ObjectMeta : metav1.ObjectMeta {
@@ -29,14 +40,14 @@ var _ = g.BeforeSuite(func() {
29
40
Data : ps .Data ,
30
41
Type : ps .Type ,
31
42
}
32
- _ , err = oc .KubeClient ().CoreV1 ().Secrets (mcoNamespace ).Create (context .Background (), localInputPullSecret , metav1.CreateOptions {})
43
+ _ , err = oc .KubeClient ().CoreV1 ().Secrets (mcoNamespace ).Create (context .TODO (), localInputPullSecret , metav1.CreateOptions {})
33
44
o .Expect (err ).NotTo (o .HaveOccurred (), "Create my-input-pull secret in openshift-machine-config" )
34
45
35
46
longLivedTokenName := "long-live-token"
36
47
serviceAccountName := "builder"
37
48
localTokenPullSecret := & corev1.Secret {
38
49
ObjectMeta : metav1.ObjectMeta {
39
- Name : longLivedTokenName ,
50
+ Name : longLivedTokenName ,
40
51
Namespace : mcoNamespace ,
41
52
Annotations : map [string ]string {
42
53
corev1 .ServiceAccountNameKey : serviceAccountName ,
@@ -53,27 +64,114 @@ var _ = g.Describe("[sig-mco][OCPFeatureGate:OnClusterBuild][Serial] Run tests s
53
64
defer g .GinkgoRecover ()
54
65
var (
55
66
moscFixture = filepath .Join (MCOMachineConfigBaseDir , "machineosconfigurations" , "machineosconfig.yaml" )
56
- mcpFixture = filepath .Join (MCOMachineConfigBaseDir , "machineconfigpool" , "machineconfigpool.yaml" )
67
+ mcpFixture = filepath .Join (MCOMachineConfigBaseDir , "machineconfigpool" , "machineconfigpool.yaml" )
57
68
)
58
69
59
70
g .BeforeEach (func (ctx context.Context ) {
60
71
//skip this test on single node platforms
61
-
72
+
62
73
//skipOnSingleNodeTopology(oc)
63
74
})
64
75
65
76
g .AfterEach (func () {
66
77
// Clear out boot image configuration between tests
67
-
78
+
68
79
//err := oc.Run("apply").Args("-f", noneMachineSetFixture).Execute()
69
80
//o.Expect(err).NotTo(o.HaveOccurred())
70
81
})
71
82
72
83
g .It ("Should update opted in MCP with the build image from the dockerfile mentioned in MOSC [apigroup:machineconfiguration.openshift.io]" , func () {
73
- OneNodePoolOptInTest (oc , moscFixture , mcpFixture )
84
+ AllNodePoolOptInTest (oc , moscFixture , mcpFixture )
74
85
})
75
86
76
87
})
77
88
78
- func OneNodePoolOptInTest (oc * exutil.CLI , moscfixture string , mcpFixture string ) {
89
+ func AllNodePoolOptInTest (oc * exutil.CLI , moscFixture string , mcpFixture string ) {
90
+
91
+ err := oc .Run ("apply" ).Args ("-f" , mcpFixture ).Execute ()
92
+ o .Expect (err ).NotTo (o .HaveOccurred (), "Create MCP Infra" )
93
+
94
+ nodes , err := oc .KubeClient ().CoreV1 ().Nodes ().List (context .TODO (), metav1.ListOptions {})
95
+ o .Expect (err ).NotTo (o .HaveOccurred (), "Get all nodes" )
96
+ for _ , node := range nodes .Items {
97
+ err = oc .AsAdmin ().Run ("label" ).Args ("node" , node .Name , "node-role.kubernetes.io/infra=" + "" ).Execute ()
98
+ o .Expect (err ).NotTo (o .HaveOccurred (), fmt .Sprintf ("Add node %s to MCP infra" , node .Name ))
99
+ }
100
+ err = oc .Run ("apply" ).Args ("-f" , moscFixture ).Execute ()
101
+ o .Expect (err ).NotTo (o .HaveOccurred (), "Create MOSC Infra and opt in Infra pool into OCL" )
102
+
103
+ machineConfigClient , err := mcClient .NewForConfig (oc .KubeFramework ().ClientConfig ())
104
+ o .Expect (err ).NotTo (o .HaveOccurred ())
105
+
106
+ mcp , err := getMCPFromFixture (mcpFixture )
107
+ o .Expect (err ).NotTo (o .HaveOccurred ())
108
+
109
+ waitTime := time .Minute * 20
110
+ ctx , cancel := context .WithTimeout (context .Background (), waitTime )
111
+ defer cancel ()
112
+
113
+ // Wait for MOSB to be created
114
+ err = waitForBuild (ctx , machineConfigClient , mcp )
115
+ o .Expect (err ).NotTo (o .HaveOccurred (), "Waiting for MOSB to be created and builder pod to Succeed" )
116
+
117
+ // Wait for the build Image to be applied to all nodes
118
+ }
119
+
120
+ func getMCPFromFixture (path string ) (* mcfgv1.MachineConfigPool , error ) {
121
+ data , err := ioutil .ReadFile (path )
122
+ if err != nil {
123
+ return nil , err
124
+ }
125
+
126
+ mcp := new (mcfgv1.MachineConfigPool )
127
+ err = yaml .Unmarshal (data , mcp )
128
+ if err != nil {
129
+ return nil , err
130
+ }
131
+
132
+ return mcp , err
133
+ }
134
+
135
+ func waitForBuild (ctx context.Context , clientset * mcClient.Clientset , mcp * mcfgv1.MachineConfigPool ) error {
136
+ return wait .PollUntilContextCancel (ctx , time .Second , true , func (ctx context.Context ) (done bool , err error ) {
137
+
138
+ mosbList , err := clientset .MachineconfigurationV1alpha1 ().MachineOSBuilds ().List (ctx , metav1.ListOptions {})
139
+ if err != nil {
140
+ return false , err
141
+ }
142
+ /*
143
+ isPending := false
144
+ isBuilding := false
145
+ isSuccess := false
146
+ start := time.Now()
147
+ */
148
+ for _ , mosb := range mosbList .Items {
149
+ if mosb .Spec .DesiredConfig .Name == mcp .Spec .Configuration .Name {
150
+ /*
151
+ state := ctrlcommon.NewMachineOSBuildState(mosb)
152
+
153
+ if !isPending && state.IsBuildPending() {
154
+ isPending = true
155
+ e2e.Logf("Build %s is now pending after %s", mosb.Name, time.Since(start))
156
+ }
157
+
158
+ if !isBuilding && state.IsBuilding() {
159
+ isBuilding = true
160
+ e2e.Logf("Build %s is now running after %s", mosb.Name, time.Since(start))
161
+ }
162
+
163
+ if !isSuccess && state.IsBuildSuccess() {
164
+ isSuccess = true
165
+ e2e.Logf("Build %s is complete after %s", mosb.Name, time.Since(start))
166
+ return true, nil
167
+ }
168
+
169
+ if state.IsBuildFailure() {
170
+ return false, fmt.Errorf("build %s failed after %s", mosb.Name, time.Since(start))
171
+ }
172
+ */
173
+ }
174
+ }
175
+ return false , nil
176
+ })
79
177
}
0 commit comments