Skip to content

Commit fa02c39

Browse files
committed
add hash to end of resource names to avoid name clash
Signed-off-by: Kevin <kpostlet@redhat.com>
1 parent ca81c46 commit fa02c39

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

pkg/controllers/raycluster_controller.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ const (
8686
)
8787

8888
var (
89-
deletePolicy = metav1.DeletePropagationForeground
90-
deleteOptions = client.DeleteOptions{PropagationPolicy: &deletePolicy}
89+
deletePolicy = metav1.DeletePropagationForeground
90+
deleteOptions = client.DeleteOptions{PropagationPolicy: &deletePolicy}
91+
defaultHashLength = 8
9192
)
9293

9394
// +kubebuilder:rbac:groups=ray.io,resources=rayclusters,verbs=get;list;watch;create;update;patch;delete
@@ -304,7 +305,7 @@ func isMTLSEnabled(cfg *config.KubeRayConfiguration) bool {
304305
}
305306

306307
func crbNameFromCluster(cluster *rayv1.RayCluster) string {
307-
return cluster.Name + "-" + cluster.Namespace + "-auth" // NOTE: potential naming conflicts ie {name: foo, ns: bar-baz} and {name: foo-bar, ns: baz}
308+
return cluster.Name + "-" + cluster.Namespace + "-auth-" + ControllerSpecificHash(cluster.Name, defaultHashLength) // NOTE: potential naming conflicts ie {name: foo, ns: bar-baz} and {name: foo-bar, ns: baz}
308309
}
309310

310311
func desiredOAuthClusterRoleBinding(cluster *rayv1.RayCluster) *rbacv1ac.ClusterRoleBindingApplyConfiguration {
@@ -326,7 +327,7 @@ func desiredOAuthClusterRoleBinding(cluster *rayv1.RayCluster) *rbacv1ac.Cluster
326327
}
327328

328329
func oauthServiceAccountNameFromCluster(cluster *rayv1.RayCluster) string {
329-
return cluster.Name + "-oauth-proxy"
330+
return cluster.Name + "-oauth-proxy-" + ControllerSpecificHash(cluster.Name, defaultHashLength)
330331
}
331332

332333
func desiredServiceAccount(cluster *rayv1.RayCluster) *corev1ac.ServiceAccountApplyConfiguration {
@@ -343,11 +344,11 @@ func desiredServiceAccount(cluster *rayv1.RayCluster) *corev1ac.ServiceAccountAp
343344
}
344345

345346
func dashboardNameFromCluster(cluster *rayv1.RayCluster) string {
346-
return "ray-dashboard-" + cluster.Name
347+
return "ray-dashboard-" + cluster.Name + "-" + ControllerSpecificHash(cluster.Name, defaultHashLength)
347348
}
348349

349350
func rayClientNameFromCluster(cluster *rayv1.RayCluster) string {
350-
return "rayclient-" + cluster.Name
351+
return "rayclient-" + cluster.Name + "-" + ControllerSpecificHash(cluster.Name, defaultHashLength)
351352
}
352353

353354
func desiredClusterRoute(cluster *rayv1.RayCluster) *routev1ac.RouteApplyConfiguration {
@@ -367,11 +368,11 @@ func desiredClusterRoute(cluster *rayv1.RayCluster) *routev1ac.RouteApplyConfigu
367368
}
368369

369370
func oauthServiceNameFromCluster(cluster *rayv1.RayCluster) string {
370-
return cluster.Name + "-oauth"
371+
return cluster.Name + "-oauth-" + ControllerSpecificHash(cluster.Name, defaultHashLength)
371372
}
372373

373374
func oauthServiceTLSSecretName(cluster *rayv1.RayCluster) string {
374-
return cluster.Name + "-proxy-tls-secret"
375+
return cluster.Name + "-proxy-tls-secret-" + ControllerSpecificHash(cluster.Name, defaultHashLength)
375376
}
376377

377378
func desiredOAuthService(cluster *rayv1.RayCluster) *corev1ac.ServiceApplyConfiguration {
@@ -395,7 +396,7 @@ func desiredOAuthService(cluster *rayv1.RayCluster) *corev1ac.ServiceApplyConfig
395396
}
396397

397398
func oauthSecretNameFromCluster(cluster *rayv1.RayCluster) string {
398-
return cluster.Name + "-oauth-config"
399+
return cluster.Name + "-oauth-config-" + ControllerSpecificHash(cluster.Name, defaultHashLength)
399400
}
400401

401402
// desiredOAuthSecret defines the desired OAuth secret object
@@ -414,7 +415,7 @@ func desiredOAuthSecret(cluster *rayv1.RayCluster, cookieSalt string) *corev1ac.
414415
}
415416

416417
func caSecretNameFromCluster(cluster *rayv1.RayCluster) string {
417-
return "ca-secret-" + cluster.Name
418+
return "ca-secret-" + cluster.Name + "-" + ControllerSpecificHash(cluster.Name, defaultHashLength)
418419
}
419420

420421
func desiredCASecret(cluster *rayv1.RayCluster, key, cert []byte) *corev1ac.SecretApplyConfiguration {
@@ -476,7 +477,9 @@ func generateCACertificate() ([]byte, []byte, error) {
476477
}
477478

478479
func desiredWorkersNetworkPolicy(cluster *rayv1.RayCluster) *networkingv1ac.NetworkPolicyApplyConfiguration {
479-
return networkingv1ac.NetworkPolicy(cluster.Name+"-workers", cluster.Namespace).
480+
return networkingv1ac.NetworkPolicy(
481+
cluster.Name+"-workers-"+ControllerSpecificHash(cluster.Name, defaultHashLength), cluster.Namespace,
482+
).
480483
WithLabels(map[string]string{RayClusterNameLabel: cluster.Name}).
481484
WithSpec(networkingv1ac.NetworkPolicySpec().
482485
WithPodSelector(metav1ac.LabelSelector().WithMatchLabels(map[string]string{"ray.io/cluster": cluster.Name, "ray.io/node-type": "worker"})).
@@ -499,7 +502,7 @@ func desiredHeadNetworkPolicy(cluster *rayv1.RayCluster, cfg *config.KubeRayConf
499502
if ptr.Deref(cfg.MTLSEnabled, true) {
500503
allSecuredPorts = append(allSecuredPorts, networkingv1ac.NetworkPolicyPort().WithProtocol(corev1.ProtocolTCP).WithPort(intstr.FromInt(10001)))
501504
}
502-
return networkingv1ac.NetworkPolicy(cluster.Name+"-head", cluster.Namespace).
505+
return networkingv1ac.NetworkPolicy(cluster.Name+"-head-"+ControllerSpecificHash(cluster.Name, defaultHashLength), cluster.Namespace).
503506
WithLabels(map[string]string{RayClusterNameLabel: cluster.Name}).
504507
WithSpec(networkingv1ac.NetworkPolicySpec().
505508
WithPodSelector(metav1ac.LabelSelector().WithMatchLabels(map[string]string{"ray.io/cluster": cluster.Name, "ray.io/node-type": "head"})).

pkg/controllers/support.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controllers
22

33
import (
4+
"crypto/sha256"
5+
"fmt"
46
"os"
57

68
"github.com/go-logr/logr"
@@ -212,3 +214,15 @@ func (l logSink) WithName(name string) logr.LogSink {
212214
func FilteredLogger(logger logr.Logger) logr.Logger {
213215
return logger.WithSink(logSink{logger.GetSink()})
214216
}
217+
218+
var (
219+
hashConstant = "codeflare-operator"
220+
)
221+
222+
func ControllerSpecificHash(s string, l int) string {
223+
toReturn := fmt.Sprintf("%x", sha256.Sum256([]byte(hashConstant+s)))
224+
if l > 0 {
225+
return toReturn[:l]
226+
}
227+
return toReturn
228+
}

0 commit comments

Comments
 (0)