Skip to content

Commit

Permalink
Merge pull request #99 from Madhu-1/fix-88
Browse files Browse the repository at this point in the history
generate service name as per kubernetes
  • Loading branch information
nb-ohad authored Aug 7, 2024
2 parents d0835c9 + a06beb7 commit deb792a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/controller/driver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ func (r *driverReconcile) reconcileNodePluginDeamonSet() error {
func (r *driverReconcile) reconcileLivenessService() error {
service := &corev1.Service{}
service.Namespace = r.driver.Namespace
service.Name = r.generateName("liveness")
service.Name = r.generateServiceName("liveness")

log := r.log.WithValues("service", service.Name)
log.Info("Reconciling liveness service")
Expand Down Expand Up @@ -1138,6 +1138,17 @@ func (r *driverReconcile) generateName(suffix string) string {
return fmt.Sprintf("%s-%s", r.driver.Name, suffix)
}

// generateServiceName generates a service name by replacing all special characters with a hyphen
// as required by Kubernetes for service name, This assumes that the name
// from the generateName is RFC 1123 compliant.
func (r *driverReconcile) generateServiceName(suffix string) string {
name := r.generateName(suffix)
// Define a regex pattern to match all special characters except hyphen
re := regexp.MustCompile(`[^a-z0-9-]`)
// Replace all special characters with a hyphen
return re.ReplaceAllString(name, "-")
}

func getControllerPluginPodAffinity(
pluginSpec *csiv1a1.ControllerPluginSpec,
selector *metav1.LabelSelector,
Expand Down

0 comments on commit deb792a

Please sign in to comment.