Skip to content
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

keepin it DRY with a helper function 4 owner ref #606

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions pkg/controllers/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ func desiredServiceAccount(cluster *rayv1.RayCluster) *corev1ac.ServiceAccountAp
`{"kind":"OAuthRedirectReference","apiVersion":"v1",` +
`"reference":{"kind":"Route","name":"` + dashboardNameFromCluster(cluster) + `"}}`,
}).
WithOwnerReferences(
metav1ac.OwnerReference().WithUID(cluster.UID).WithName(cluster.Name).WithKind(cluster.Kind).WithAPIVersion(cluster.APIVersion).WithController(true),
)
WithOwnerReferences(ownerRefForRayCluster(cluster))
}

func dashboardNameFromCluster(cluster *rayv1.RayCluster) string {
Expand All @@ -361,9 +359,7 @@ func desiredClusterRoute(cluster *rayv1.RayCluster) *routev1ac.RouteApplyConfigu
WithTermination(routev1.TLSTerminationReencrypt),
),
).
WithOwnerReferences(
metav1ac.OwnerReference().WithUID(cluster.UID).WithName(cluster.Name).WithKind(cluster.Kind).WithAPIVersion(cluster.APIVersion).WithController(true),
)
WithOwnerReferences(ownerRefForRayCluster(cluster))
}

func oauthServiceNameFromCluster(cluster *rayv1.RayCluster) string {
Expand All @@ -389,9 +385,7 @@ func desiredOAuthService(cluster *rayv1.RayCluster) *corev1ac.ServiceApplyConfig
).
WithSelector(map[string]string{"ray.io/cluster": cluster.Name, "ray.io/node-type": "head"}),
).
WithOwnerReferences(
metav1ac.OwnerReference().WithUID(cluster.UID).WithName(cluster.Name).WithKind(cluster.Kind).WithAPIVersion(cluster.APIVersion).WithController(true),
)
WithOwnerReferences(ownerRefForRayCluster(cluster))
}

func oauthSecretNameFromCluster(cluster *rayv1.RayCluster) string {
Expand All @@ -408,9 +402,7 @@ func desiredOAuthSecret(cluster *rayv1.RayCluster, cookieSalt string) *corev1ac.
return corev1ac.Secret(oauthSecretNameFromCluster(cluster), cluster.Namespace).
WithLabels(map[string]string{RayClusterNameLabel: cluster.Name}).
WithStringData(map[string]string{"cookie_secret": cookieSecret}).
WithOwnerReferences(
metav1ac.OwnerReference().WithUID(cluster.UID).WithName(cluster.Name).WithKind(cluster.Kind).WithAPIVersion(cluster.APIVersion).WithController(true),
)
WithOwnerReferences(ownerRefForRayCluster(cluster))
}

func caSecretNameFromCluster(cluster *rayv1.RayCluster) string {
Expand All @@ -424,12 +416,7 @@ func desiredCASecret(cluster *rayv1.RayCluster, key, cert []byte) *corev1ac.Secr
CAPrivateKeyKey: key,
CACertKey: cert,
}).
WithOwnerReferences(metav1ac.OwnerReference().
WithUID(cluster.UID).
WithName(cluster.Name).
WithKind(cluster.Kind).
WithAPIVersion(cluster.APIVersion).
WithController(true))
WithOwnerReferences(ownerRefForRayCluster(cluster))
}

func generateCACertificate() ([]byte, []byte, error) {
Expand Down Expand Up @@ -487,9 +474,7 @@ func desiredWorkersNetworkPolicy(cluster *rayv1.RayCluster) *networkingv1ac.Netw
),
),
).
WithOwnerReferences(
metav1ac.OwnerReference().WithUID(cluster.UID).WithName(cluster.Name).WithKind(cluster.Kind).WithAPIVersion(cluster.APIVersion).WithController(true),
)
WithOwnerReferences(ownerRefForRayCluster(cluster))
}

func desiredHeadNetworkPolicy(cluster *rayv1.RayCluster, cfg *config.KubeRayConfiguration, kubeRayNamespaces []string) *networkingv1ac.NetworkPolicyApplyConfiguration {
Expand Down Expand Up @@ -545,9 +530,7 @@ func desiredHeadNetworkPolicy(cluster *rayv1.RayCluster, cfg *config.KubeRayConf
),
),
).
WithOwnerReferences(
metav1ac.OwnerReference().WithUID(cluster.UID).WithName(cluster.Name).WithKind(cluster.Kind).WithAPIVersion(cluster.APIVersion).WithController(true),
)
WithOwnerReferences(ownerRefForRayCluster(cluster))
}

func (r *RayClusterReconciler) deleteHeadPodIfMissingImagePullSecrets(ctx context.Context, cluster *rayv1.RayCluster) error {
Expand Down
27 changes: 12 additions & 15 deletions pkg/controllers/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ func desiredRayClientRoute(cluster *rayv1.RayCluster) *routeapply.RouteApplyConf
WithPort(routeapply.RoutePort().WithTargetPort(intstr.FromString("client"))).
WithTLS(routeapply.TLSConfig().WithTermination("passthrough")),
).
WithOwnerReferences(
v1.OwnerReference().WithUID(cluster.UID).WithName(cluster.Name).WithKind(cluster.Kind).WithAPIVersion(cluster.APIVersion).WithController(true),
)
WithOwnerReferences(ownerRefForRayCluster(cluster))
}

func desiredRayClientIngress(cluster *rayv1.RayCluster, ingressHost string) *networkingv1ac.IngressApplyConfiguration {
Expand All @@ -55,12 +53,7 @@ func desiredRayClientIngress(cluster *rayv1.RayCluster, ingressHost string) *net
"nginx.ingress.kubernetes.io/ssl-redirect": "true",
"nginx.ingress.kubernetes.io/ssl-passthrough": "true",
}).
WithOwnerReferences(v1.OwnerReference().
WithAPIVersion(cluster.APIVersion).
WithKind(cluster.Kind).
WithName(cluster.Name).
WithUID(cluster.UID).
WithController(true)).
WithOwnerReferences(ownerRefForRayCluster(cluster)).
WithSpec(networkingv1ac.IngressSpec().
WithIngressClassName("nginx").
WithRules(networkingv1ac.IngressRule().
Expand All @@ -86,12 +79,7 @@ func desiredRayClientIngress(cluster *rayv1.RayCluster, ingressHost string) *net
func desiredClusterIngress(cluster *rayv1.RayCluster, ingressHost string) *networkingv1ac.IngressApplyConfiguration {
return networkingv1ac.Ingress(dashboardNameFromCluster(cluster), cluster.Namespace).
WithLabels(map[string]string{RayClusterNameLabel: cluster.Name}).
WithOwnerReferences(v1.OwnerReference().
WithAPIVersion(cluster.APIVersion).
WithKind(cluster.Kind).
WithName(cluster.Name).
WithUID(cluster.UID).
WithController(true)).
WithOwnerReferences(ownerRefForRayCluster(cluster)).
WithSpec(networkingv1ac.IngressSpec().
WithRules(networkingv1ac.IngressRule().
WithHost(ingressHost). // Full Hostname
Expand Down Expand Up @@ -212,3 +200,12 @@ func (l logSink) WithName(name string) logr.LogSink {
func FilteredLogger(logger logr.Logger) logr.Logger {
return logger.WithSink(logSink{logger.GetSink()})
}

func ownerRefForRayCluster(cluster *rayv1.RayCluster) *v1.OwnerReferenceApplyConfiguration {
return v1.OwnerReference().
WithAPIVersion(cluster.APIVersion).
WithKind(cluster.Kind).
WithName(cluster.Name).
WithUID(cluster.UID).
WithController(true)
}