-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor] Extract KubectlApplyYaml and yaml deserialization to support package #2498
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package sampleyaml | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
|
@@ -35,10 +36,11 @@ func TestRayJob(t *testing.T) { | |
test := With(t) | ||
g := NewWithT(t) | ||
|
||
yamlFilePath := path.Join(GetSampleYAMLDir(test), tt.name) | ||
namespace := test.NewTestNamespace() | ||
test.StreamKubeRayOperatorLogs() | ||
rayJobFromYaml := DeserializeRayJobSampleYAML(test, tt.name) | ||
KubectlApplyYAML(test, tt.name, namespace.Name) | ||
rayJobFromYaml := DeserializeRayJobYAML(test, yamlFilePath) | ||
KubectlApplyYAML(test, yamlFilePath, namespace.Name) | ||
|
||
rayJob, err := GetRayJob(test, namespace.Name, rayJobFromYaml.Name) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
|
@@ -65,9 +67,7 @@ func TestRayJob(t *testing.T) { | |
desiredWorkerReplicas += *workerGroupSpec.Replicas | ||
} | ||
} | ||
|
||
g.Eventually(WorkerPods(test, rayCluster), TestTimeoutShort).Should(HaveLen(int(desiredWorkerReplicas))) | ||
g.Expect(rayCluster.Status.DesiredWorkerReplicas).To(Equal(desiredWorkerReplicas)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need to check this because we've already checked the number of worker pods above. Also because this is a one-line fix so I do it directly in this refactoring PR. Do you think it's better to create a separate PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, this differs from the above logic. The above logic checks the number of worker Pods by querying the K8s API server, which is the source of truth. The deleted line checks whether the RayCluster status reflects the actual cluster status. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I've restored this check, but updating it to g.Expect(GetRayCluster(test, namespace.Name, rayCluster.Name)).To(WithTransform(RayClusterDesiredWorkerReplicas, Equal(desiredWorkerReplicas))) because I found that we forgot to get the RayCluster again to update its status. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a transform just to return a field seems overkill :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And |
||
|
||
// Check if the head pod is ready | ||
g.Eventually(HeadPod(test, rayCluster), TestTimeoutShort).Should(WithTransform(IsPodRunningAndReady, BeTrue())) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package support | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" | ||
rayscheme "github.com/ray-project/kuberay/ray-operator/pkg/client/clientset/versioned/scheme" | ||
) | ||
|
||
func deserializeYAML(filename string, into runtime.Object) error { | ||
yamlFileContent, err := os.ReadFile(filename) | ||
if err != nil { | ||
return err | ||
} | ||
decoder := rayscheme.Codecs.UniversalDecoder() | ||
if _, _, err = decoder.Decode(yamlFileContent, nil, into); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func DeserializeRayClusterYAML(t Test, filename string) *rayv1.RayCluster { | ||
t.T().Helper() | ||
rayCluster := &rayv1.RayCluster{} | ||
err := deserializeYAML(filename, rayCluster) | ||
assert.NoError(t.T(), err) | ||
return rayCluster | ||
} | ||
|
||
func DeserializeRayJobYAML(t Test, filename string) *rayv1.RayJob { | ||
t.T().Helper() | ||
rayJob := &rayv1.RayJob{} | ||
err := deserializeYAML(filename, rayJob) | ||
assert.NoError(t.T(), err) | ||
return rayJob | ||
} | ||
|
||
func DeserializeRayServiceYAML(t Test, filename string) *rayv1.RayService { | ||
t.T().Helper() | ||
rayService := &rayv1.RayService{} | ||
err := deserializeYAML(filename, rayService) | ||
assert.NoError(t.T(), err) | ||
return rayService | ||
} | ||
|
||
func KubectlApplyYAML(t Test, filename string, namespace string) { | ||
t.T().Helper() | ||
kubectlCmd := exec.CommandContext(t.Ctx(), "kubectl", "apply", "-f", filename, "-n", namespace) | ||
err := kubectlCmd.Run() | ||
assert.NoError(t.T(), err) | ||
t.T().Logf("Successfully applied %s", filename) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove this?