Skip to content

Commit cca3701

Browse files
committed
Test Instascale machine set functionality
Co-authored-by: Karel Suta [email protected] Co-authored-by: Fiona Waters [email protected]
1 parent 2ddc14f commit cca3701

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package e2e
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/gomega"
7+
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
8+
9+
batchv1 "k8s.io/api/batch/v1"
10+
corev1 "k8s.io/api/core/v1"
11+
12+
. "github.com/project-codeflare/codeflare-operator/test/support"
13+
)
14+
15+
func TestInstascaleMachineSet(t *testing.T) {
16+
test := With(t)
17+
test.T().Parallel()
18+
19+
namespace := test.NewTestNamespace()
20+
21+
// Test configuration
22+
testConfigData := map[string][]byte{
23+
// pip requirements
24+
"requirements.txt": ReadFile(test, "mnist_pip_requirements.txt"),
25+
// MNIST training script
26+
"mnist.py": ReadFile(test, "mnist.py"),
27+
}
28+
cm := CreateConfigMap(test, namespace.Name, testConfigData)
29+
30+
// look for machine set with aw name - expect to find it
31+
test.Expect(MachineSets(test)).Should(ContainElement(WithTransform(MachineSetId, Equal("test-instascale"))))
32+
// look for machine set replica - expect not to find it
33+
test.Expect(MachineExists(test)).Should(BeFalse())
34+
35+
// // Setup batch job and AppWrapper
36+
job, aw, err := createInstaScaleJobAppWrapper(test, namespace, cm)
37+
test.Expect(err).NotTo(HaveOccurred())
38+
39+
//look for machine set replica - expect to find it
40+
test.Expect(MachineExists(test)).Should(BeTrue())
41+
42+
// Assert that the job has completed
43+
test.T().Logf("Waiting for Job %s/%s to complete", job.Namespace, job.Name)
44+
test.Eventually(Job(test, job.Namespace, job.Name), TestTimeoutLong).Should(
45+
Or(
46+
WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)),
47+
WithTransform(ConditionStatus(batchv1.JobFailed), Equal(corev1.ConditionTrue)),
48+
))
49+
50+
// // Assert the job has completed successfully
51+
test.Expect(GetJob(test, job.Namespace, job.Name)).
52+
To(WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)))
53+
54+
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutShort).
55+
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateCompleted)))
56+
57+
// look for machine set replica - expect not to find it
58+
test.Expect(MachineExists(test)).Should(BeFalse())
59+
60+
}

test/support/client.go

+13
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ import (
2626
"k8s.io/client-go/tools/clientcmd"
2727

2828
imagev1 "github.com/openshift/client-go/image/clientset/versioned"
29+
machinev1 "github.com/openshift/client-go/machine/clientset/versioned"
2930
routev1 "github.com/openshift/client-go/route/clientset/versioned"
3031
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
3132
// to ensure that exec-entrypoint and run can make use of them.
3233
)
3334

3435
type Client interface {
3536
Core() kubernetes.Interface
37+
Machine() machinev1.Interface
3638
Route() routev1.Interface
3739
Image() imagev1.Interface
3840
MCAD() mcadclient.Interface
@@ -42,6 +44,7 @@ type Client interface {
4244

4345
type testClient struct {
4446
core kubernetes.Interface
47+
machine machinev1.Interface
4548
route routev1.Interface
4649
image imagev1.Interface
4750
mcad mcadclient.Interface
@@ -55,6 +58,10 @@ func (t *testClient) Core() kubernetes.Interface {
5558
return t.core
5659
}
5760

61+
func (t *testClient) Machine() machinev1.Interface {
62+
return t.machine
63+
}
64+
5865
func (t *testClient) Route() routev1.Interface {
5966
return t.route
6067
}
@@ -88,6 +95,11 @@ func newTestClient() (Client, error) {
8895
return nil, err
8996
}
9097

98+
machineClient, err := machinev1.NewForConfig(cfg)
99+
if err != nil {
100+
return nil, err
101+
}
102+
91103
routeClient, err := routev1.NewForConfig(cfg)
92104
if err != nil {
93105
return nil, err
@@ -115,6 +127,7 @@ func newTestClient() (Client, error) {
115127

116128
return &testClient{
117129
core: kubeClient,
130+
machine: machineClient,
118131
route: routeClient,
119132
image: imageClient,
120133
mcad: mcadClient,

test/support/clustersets.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package support
2+
3+
import (
4+
"github.com/onsi/gomega"
5+
6+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
8+
v1beta1 "github.com/openshift/api/machine/v1beta1"
9+
)
10+
11+
func MachineSets(t Test) ([]v1beta1.MachineSet, error) {
12+
ms, err := t.Client().Machine().MachineV1beta1().MachineSets("openshift-machine-api").List(t.Ctx(), v1.ListOptions{})
13+
t.Expect(err).NotTo(gomega.HaveOccurred())
14+
return ms.Items, err
15+
}
16+
17+
func MachineExists(t Test) (foundReplica bool) {
18+
machineSetList, err := MachineSets(t)
19+
t.Expect(err).NotTo(gomega.HaveOccurred())
20+
for _, ms := range machineSetList {
21+
if ms.Name == "test-instascale" && &ms.Status.AvailableReplicas == Int32(1) {
22+
foundReplica = true
23+
}
24+
}
25+
return foundReplica
26+
}
27+
28+
func MachineSetId(machineSet v1beta1.MachineSet) string {
29+
return machineSet.Name
30+
}

test/support/utils.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ func WriteToOutputDir(t Test, fileName string, fileType OutputType, data []byte)
3939
t.Expect(os.WriteFile(path.Join(t.OutputDir(), fileName+"."+string(fileType)), data, fs.ModePerm)).
4040
To(gomega.Succeed())
4141
}
42+
43+
func Int32(v int32) *int32 {
44+
return &v
45+
}

0 commit comments

Comments
 (0)