Skip to content

Commit 8c60290

Browse files
Fiona-Watersopenshift-ci[bot]
authored andcommitted
addressing feedback
1 parent 7d4eea3 commit 8c60290

7 files changed

+65
-142
lines changed

test/e2e/instascale_app_wrapper.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package e2e
1818

1919
import (
20-
. "github.com/onsi/gomega"
2120
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
2221

2322
batchv1 "k8s.io/api/batch/v1"
@@ -138,11 +137,6 @@ func createInstaScaleJobAppWrapper(test Test, namespace *corev1.Namespace, confi
138137
}
139138

140139
_, err := test.Client().MCAD().WorkloadV1beta1().AppWrappers(namespace.Name).Create(test.Ctx(), aw, metav1.CreateOptions{})
141-
test.Expect(err).NotTo(HaveOccurred())
142-
test.T().Logf("AppWrapper created successfully %s/%s", aw.Namespace, aw.Name)
143-
144-
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutGpuProvisioning).
145-
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive)))
146140

147141
return job, aw, err
148142
}

test/e2e/instascale_machinepool_test.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,29 @@ import (
2222
. "github.com/onsi/gomega"
2323
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
2424

25-
batchv1 "k8s.io/api/batch/v1"
26-
corev1 "k8s.io/api/core/v1"
27-
2825
. "github.com/project-codeflare/codeflare-operator/test/support"
2926
)
3027

3128
func TestInstascaleMachinePool(t *testing.T) {
32-
3329
test := With(t)
3430
test.T().Parallel()
3531

36-
if !IsOsd(test) {
32+
if !IsOsd() {
3733
test.T().Skip("Skipping test as not running on an OSD cluster")
3834
}
3935

4036
namespace := test.NewTestNamespace()
4137

4238
// Test configuration
43-
testConfigData := map[string][]byte{
39+
cm := CreateConfigMap(test, namespace.Name, map[string][]byte{
4440
// pip requirements
4541
"requirements.txt": ReadFile(test, "mnist_pip_requirements.txt"),
4642
// MNIST training script
4743
"mnist.py": ReadFile(test, "mnist.py"),
48-
}
49-
cm := CreateConfigMap(test, namespace.Name, testConfigData)
44+
})
5045

5146
//create OCM connection
5247
connection := CreateOCMConnection(test)
53-
5448
defer connection.Close()
5549

5650
// check existing cluster machine pool resources
@@ -59,25 +53,18 @@ func TestInstascaleMachinePool(t *testing.T) {
5953
ShouldNot(ContainElement(WithTransform(MachinePoolId, Equal("test-instascale-g4dn-xlarge"))))
6054

6155
// Setup batch job and AppWrapper
62-
job, aw, err := createInstaScaleJobAppWrapper(test, namespace, cm)
56+
_, aw, err := createInstaScaleJobAppWrapper(test, namespace, cm)
6357
test.Expect(err).NotTo(HaveOccurred())
58+
test.T().Logf("AppWrapper created successfully %s/%s", aw.Namespace, aw.Name)
59+
60+
// assert that AppWrapper goes to "Running" state
61+
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutGpuProvisioning).
62+
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive)))
6463

6564
// look for machine pool with aw name - expect to find it
6665
test.Eventually(MachinePools(test, connection), TestTimeoutLong).
6766
Should(ContainElement(WithTransform(MachinePoolId, Equal("test-instascale-g4dn-xlarge"))))
6867

69-
// Assert that the job has completed
70-
test.T().Logf("Waiting for Job %s/%s to complete", job.Namespace, job.Name)
71-
test.Eventually(Job(test, job.Namespace, job.Name), TestTimeoutLong).Should(
72-
Or(
73-
WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)),
74-
WithTransform(ConditionStatus(batchv1.JobFailed), Equal(corev1.ConditionTrue)),
75-
))
76-
77-
// Assert the job has completed successfully
78-
test.Expect(GetJob(test, job.Namespace, job.Name)).
79-
To(WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)))
80-
8168
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutShort).
8269
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateCompleted)))
8370

test/support/clusterpools.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/support/config_map.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

test/support/core.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ import (
2727
"k8s.io/apimachinery/pkg/runtime"
2828
)
2929

30+
func CreateConfigMap(t Test, namespace string, content map[string][]byte) *corev1.ConfigMap {
31+
configMap := &corev1.ConfigMap{
32+
TypeMeta: metav1.TypeMeta{
33+
APIVersion: corev1.SchemeGroupVersion.String(),
34+
Kind: "ConfigMap",
35+
},
36+
ObjectMeta: metav1.ObjectMeta{
37+
GenerateName: "config-",
38+
Namespace: namespace,
39+
},
40+
BinaryData: content,
41+
Immutable: Ptr(true),
42+
}
43+
44+
configMap, err := t.Client().Core().CoreV1().ConfigMaps(namespace).Create(t.Ctx(), configMap, metav1.CreateOptions{})
45+
t.Expect(err).NotTo(gomega.HaveOccurred())
46+
t.T().Logf("Created ConfigMap %s/%s successfully", configMap.Namespace, configMap.Name)
47+
48+
return configMap
49+
}
50+
3051
func Raw(t Test, obj runtime.Object) runtime.RawExtension {
3152
t.T().Helper()
3253
data, err := json.Marshal(obj)

test/support/codeflare.go renamed to test/support/environment.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ package support
1818

1919
import (
2020
"os"
21-
"strconv"
22-
23-
"github.com/onsi/gomega"
21+
"strings"
2422
)
2523

2624
const (
@@ -35,14 +33,11 @@ const (
3533
// The testing output directory, to write output files into.
3634
CodeFlareTestOutputDir = "CODEFLARE_TEST_OUTPUT_DIR"
3735

38-
// The name of a secret containing InstaScale OCM token.
39-
InstaScaleOcmSecretName = "INSTASCALE_OCM_SECRET_NAME"
40-
// The namespace where a secret containing InstaScale OCM token is stored.
41-
InstaScaleOcmSecretNamespace = "INSTASCALE_OCM_SECRET_NAMESPACE"
36+
// The namespace where a secret containing InstaScale OCM token is stored and the secret name.
37+
InstaScaleOcmSecret = "INSTASCALE_OCM_SECRET"
38+
4239
// Cluster ID for OSD cluster used in tests, used for testing InstaScale
4340
OsdClusterID = "CLUSTERID"
44-
// Determine if test is being run on an OSD cluster, used for testing InstaScale.
45-
IsOSD = "IS_OSD"
4641
)
4742

4843
func GetCodeFlareSDKVersion() string {
@@ -61,28 +56,21 @@ func GetPyTorchImage() string {
6156
return lookupEnvOrDefault(CodeFlareTestPyTorchImage, "pytorch/pytorch:1.11.0-cuda11.3-cudnn8-runtime")
6257
}
6358

64-
func GetInstaScaleOcmSecretName() string {
65-
return lookupEnvOrDefault(InstaScaleOcmSecretName, "instascale-ocm-secret")
66-
}
67-
68-
func GetInstaScaleOcmSecretNamespace() string {
69-
return lookupEnvOrDefault(InstaScaleOcmSecretNamespace, "default")
59+
func GetInstascaleOcmSecret() (string, string) {
60+
res := strings.SplitN(lookupEnvOrDefault(InstaScaleOcmSecret, "default/instascale-com-secret"), "/", 2)
61+
return res[0], res[1]
7062
}
7163

7264
func GetOsdClusterId() (string, bool) {
7365
return os.LookupEnv(OsdClusterID)
7466
}
7567

76-
func IsOsd(test Test) bool {
77-
test.T().Helper()
78-
env := lookupEnvOrDefault(IsOSD, "false")
79-
osd, err := strconv.ParseBool(env)
80-
if err != nil {
81-
test.T().Logf("error parsing IS_OSD environment variable, using default 'false' value, error: %v ", err)
82-
return false
68+
func IsOsd() bool {
69+
osdClusterId, found := GetOsdClusterId()
70+
if found && osdClusterId != "" {
71+
return true
8372
}
84-
test.Expect(err).NotTo(gomega.HaveOccurred())
85-
return osd
73+
return false
8674
}
8775

8876
func lookupEnvOrDefault(key, value string) string {

test/support/ocm.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626

2727
ocmsdk "github.com/openshift-online/ocm-sdk-go"
28+
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
2829
)
2930

3031
func CreateOCMConnection(test Test) *ocmsdk.Connection {
31-
instascaleOCMSecret, err := test.Client().Core().CoreV1().Secrets(GetInstaScaleOcmSecretNamespace()).Get(test.Ctx(), GetInstaScaleOcmSecretName(), metav1.GetOptions{})
32+
secretNamespace, secretName := GetInstascaleOcmSecret()
33+
instascaleOCMSecret, err := test.Client().Core().CoreV1().Secrets(secretNamespace).Get(test.Ctx(), secretName, metav1.GetOptions{})
3234
test.Expect(err).NotTo(gomega.HaveOccurred())
3335

3436
ocmToken := string(instascaleOCMSecret.Data["token"])
@@ -50,3 +52,23 @@ func buildOCMConnection(secret string) (*ocmsdk.Connection, error) {
5052

5153
return connection, nil
5254
}
55+
56+
func MachinePools(t Test, connection *ocmsdk.Connection) func(g gomega.Gomega) []*cmv1.MachinePool {
57+
osdClusterId, found := GetOsdClusterId()
58+
t.Expect(found).To(gomega.BeTrue(), "OSD cluster id not found, please configure environment properly")
59+
60+
return func(g gomega.Gomega) []*cmv1.MachinePool {
61+
machinePoolsListResponse, err := connection.ClustersMgmt().V1().Clusters().Cluster(osdClusterId).MachinePools().List().Send()
62+
g.Expect(err).NotTo(gomega.HaveOccurred())
63+
return machinePoolsListResponse.Items().Slice()
64+
}
65+
}
66+
67+
func GetMachinePools(t Test, connection *ocmsdk.Connection) []*cmv1.MachinePool {
68+
t.T().Helper()
69+
return MachinePools(t, connection)(t)
70+
}
71+
72+
func MachinePoolId(machinePool *cmv1.MachinePool) string {
73+
return machinePool.ID()
74+
}

0 commit comments

Comments
 (0)