cloud-ark / kubeplus

Kubernetes Operator for multi-instance multi-tenancy
https://cloudark.io/
Apache License 2.0
662 stars 82 forks source link

Follow Kubernetes naming convention for Service (CRD) name and service instance names #1218

Closed devdattakulkarni closed 4 months ago

devdattakulkarni commented 7 months ago

When creating service instances through consumer UI, we should enforce that the service instance name adheres to the following convention: alphanumeric or hyphen with the initial letter not being a hyphen. These are the constraints that are defined by Kubernetes for defining namespaces. The reason we want to set these constraints for defining the service instance names as well is that KubePlus will create a namespace with the service name and then deploy the service Helm chart in that namespace. So we want to make sure that the service name adheres to the naming policies for Kubernetes Namespaces.

devdattakulkarni commented 7 months ago

The modifications will be in mutating-webhook: https://github.com/cloud-ark/kubeplus/blob/master/mutating-webhook/webhook.go Specifically, check the "trackCustomAPIs" function.

Pre-requisites:

devdattakulkarni commented 6 months ago

https://kubernetes.io/docs/concepts/overview/working-with-objects/names/

We should implement the following checks:

omgoswami commented 4 months ago

Are these checks supposed to be implemented on the platformWorkflowName variable in the trackCustomAPIs function (line 982)?

devdattakulkarni commented 4 months ago

@omgoswami Yes ^^ that is the correct place to add these checks.

omgoswami commented 4 months ago

Seems that Kubernetes already checks this for us, and no additional code needs to be written to enforce validity of service instance names. K8s refers to such an instance as a "lowercase RFC 1123 subdomain", and will not allow users to create instances with names that contain uppercase/nonalphanumeric characters, start with a hyphen, etc.

devdattakulkarni commented 4 months ago

Thanks @omgoswami for the update.