Skip to content

Commit

Permalink
Use ResourceName generic function for raycluster_webhook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianZaccaria committed May 28, 2024
1 parent 3b89d26 commit 954fa07
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 47 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/openshift/api v0.0.0-20230823114715-5fdd7511b790
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c
github.com/project-codeflare/appwrapper v0.12.0
github.com/project-codeflare/codeflare-common v0.0.0-20240422163521-380101642c8f
github.com/project-codeflare/codeflare-common v0.0.0-20240528061920-68eadc29b5b0
github.com/ray-project/kuberay/ray-operator v1.1.0
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/project-codeflare/appwrapper v0.12.0 h1:QMxryBPK6ir3VK6Qx4NWOA05/s4xU6uDHI/nXmLznvw=
github.com/project-codeflare/appwrapper v0.12.0/go.mod h1:sH9j/rXX6WIlZzFXUOuqK5pagASPZNhuCtdFK+3BDkw=
github.com/project-codeflare/codeflare-common v0.0.0-20240422163521-380101642c8f h1:9Uron4ej4Tt5ULX5CMzjmPqIZu3q/m07d4jhbNSwdPY=
github.com/project-codeflare/codeflare-common v0.0.0-20240422163521-380101642c8f/go.mod h1:tlPi2e1HZQuf7AAFc7keWdVUNcxV+Gfh6Ss4KAQs1O0=
github.com/project-codeflare/codeflare-common v0.0.0-20240528061920-68eadc29b5b0 h1:3Vz7D9/TwzrBNujHQZGb4L6UKu3siAWwVP4Bj3ByUrU=
github.com/project-codeflare/codeflare-common v0.0.0-20240528061920-68eadc29b5b0/go.mod h1:tlPi2e1HZQuf7AAFc7keWdVUNcxV+Gfh6Ss4KAQs1O0=
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
68 changes: 24 additions & 44 deletions pkg/controllers/raycluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(1),
ContainElement(WithTransform(ContainerName, Equal(oauthProxyContainerName))),
ContainElement(WithTransform(support.ResourceName, Equal(oauthProxyContainerName))),
),
"Expected the OAuth proxy container to be present in the head group",
)
Expand All @@ -114,9 +114,9 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(3),
ContainElement(WithTransform(VolumeName, Equal(oauthProxyVolumeName))),
ContainElement(WithTransform(VolumeName, Equal("ca-vol"))),
ContainElement(WithTransform(VolumeName, Equal("server-cert"))),
ContainElement(WithTransform(support.ResourceName, Equal(oauthProxyVolumeName))),
ContainElement(WithTransform(support.ResourceName, Equal("ca-vol"))),
ContainElement(WithTransform(support.ResourceName, Equal("server-cert"))),
),
"Expected the OAuth proxy TLS secret and CA volumes to be present in the head group",
)
Expand All @@ -133,12 +133,12 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(6),
ContainElement(WithTransform(EnvVarName, Equal("COOKIE_SECRET"))),
ContainElement(WithTransform(EnvVarName, Equal("MY_POD_IP"))),
ContainElement(WithTransform(EnvVarName, Equal("RAY_USE_TLS"))),
ContainElement(WithTransform(EnvVarName, Equal("RAY_TLS_SERVER_CERT"))),
ContainElement(WithTransform(EnvVarName, Equal("RAY_TLS_SERVER_KEY"))),
ContainElement(WithTransform(EnvVarName, Equal("RAY_TLS_CA_CERT"))),
ContainElement(WithTransform(support.ResourceName, Equal("COOKIE_SECRET"))),
ContainElement(WithTransform(support.ResourceName, Equal("MY_POD_IP"))),
ContainElement(WithTransform(support.ResourceName, Equal("RAY_USE_TLS"))),
ContainElement(WithTransform(support.ResourceName, Equal("RAY_TLS_SERVER_CERT"))),
ContainElement(WithTransform(support.ResourceName, Equal("RAY_TLS_SERVER_KEY"))),
ContainElement(WithTransform(support.ResourceName, Equal("RAY_TLS_CA_CERT"))),
),
"Expected the required environment variables to be present in the head group",
)
Expand All @@ -149,7 +149,7 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(1),
ContainElement(WithTransform(ContainerName, Equal(initContainerName))),
ContainElement(WithTransform(support.ResourceName, Equal(initContainerName))),
),
"Expected the create-cert init container to be present in the head group",
)
Expand All @@ -160,9 +160,9 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(3),
ContainElement(WithTransform(VolumeMountName, Equal(oauthProxyVolumeName))),
ContainElement(WithTransform(VolumeMountName, Equal("ca-vol"))),
ContainElement(WithTransform(VolumeMountName, Equal("server-cert"))),
ContainElement(WithTransform(support.ResourceName, Equal(oauthProxyVolumeName))),
ContainElement(WithTransform(support.ResourceName, Equal("ca-vol"))),
ContainElement(WithTransform(support.ResourceName, Equal("server-cert"))),
),
"Expected the OAuth proxy TLS secret and CA volume mounts to be present in the head group",
)
Expand All @@ -174,11 +174,11 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(5),
ContainElement(WithTransform(EnvVarName, Equal("MY_POD_IP"))),
ContainElement(WithTransform(EnvVarName, Equal("RAY_USE_TLS"))),
ContainElement(WithTransform(EnvVarName, Equal("RAY_TLS_SERVER_CERT"))),
ContainElement(WithTransform(EnvVarName, Equal("RAY_TLS_SERVER_KEY"))),
ContainElement(WithTransform(EnvVarName, Equal("RAY_TLS_CA_CERT"))),
ContainElement(WithTransform(support.ResourceName, Equal("MY_POD_IP"))),
ContainElement(WithTransform(support.ResourceName, Equal("RAY_USE_TLS"))),
ContainElement(WithTransform(support.ResourceName, Equal("RAY_TLS_SERVER_CERT"))),
ContainElement(WithTransform(support.ResourceName, Equal("RAY_TLS_SERVER_KEY"))),
ContainElement(WithTransform(support.ResourceName, Equal("RAY_TLS_CA_CERT"))),
),
"Expected the required environment variables to be present in each worker group",
)
Expand All @@ -191,8 +191,8 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(2),
ContainElement(WithTransform(VolumeName, Equal("ca-vol"))),
ContainElement(WithTransform(VolumeName, Equal("server-cert"))),
ContainElement(WithTransform(support.ResourceName, Equal("ca-vol"))),
ContainElement(WithTransform(support.ResourceName, Equal("server-cert"))),
),
"Expected the required CA volumes to be present in each worker group",
)
Expand All @@ -205,8 +205,8 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(2),
ContainElement(WithTransform(VolumeMountName, Equal("ca-vol"))),
ContainElement(WithTransform(VolumeMountName, Equal("server-cert"))),
ContainElement(WithTransform(support.ResourceName, Equal("ca-vol"))),
ContainElement(WithTransform(support.ResourceName, Equal("server-cert"))),
),
"Expected the required certificate volume mounts to be present in each worker group",
)
Expand All @@ -219,7 +219,7 @@ func TestRayClusterWebhookDefault(t *testing.T) {
To(
And(
HaveLen(1),
ContainElement(WithTransform(ContainerName, Equal(initContainerName))),
ContainElement(WithTransform(support.ResourceName, Equal(initContainerName))),
),
"Expected the required init container to be present in each worker group",
)
Expand Down Expand Up @@ -645,23 +645,3 @@ func TestValidateUpdate(t *testing.T) {
test.Expect(err).Should(HaveOccurred(), "Expected errors on call to ValidateUpdate function due to manipulated env vars in the worker group")
})
}

func ContainerName(container corev1.Container) string {
return container.Name
}

func VolumeName(volume corev1.Volume) string {
return volume.Name
}

func ServiceAccountName(serviceAccount corev1.ServiceAccount) string {
return serviceAccount.Name
}

func VolumeMountName(volumeMount corev1.VolumeMount) string {
return volumeMount.Name
}

func EnvVarName(envVar corev1.EnvVar) string {
return envVar.Name
}

0 comments on commit 954fa07

Please sign in to comment.