From 4ba15ae31d0be5a10ff02a722cce52db6ed34be6 Mon Sep 17 00:00:00 2001 From: ChristianZaccaria Date: Mon, 27 May 2024 10:40:00 +0100 Subject: [PATCH] Use ResourceName generic function for raycluster_webhook tests --- go.mod | 2 +- go.sum | 4 +- pkg/controllers/raycluster_webhook_test.go | 68 ++++++++-------------- 3 files changed, 27 insertions(+), 47 deletions(-) diff --git a/go.mod b/go.mod index 637bcf5e..2fd0a7aa 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 59ec28e4..8901492a 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/controllers/raycluster_webhook_test.go b/pkg/controllers/raycluster_webhook_test.go index 3586bc06..44927309 100644 --- a/pkg/controllers/raycluster_webhook_test.go +++ b/pkg/controllers/raycluster_webhook_test.go @@ -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", ) @@ -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", ) @@ -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", ) @@ -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", ) @@ -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", ) @@ -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", ) @@ -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", ) @@ -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", ) @@ -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", ) @@ -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 -}