kubeplus
kubeplus copied to clipboard
Follow Kubernetes naming convention for Service (CRD) name and service instance names
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.
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:
- Understanding of KubePlus architecture
- Understanding of Golang
- Understanding of Kubernetes naming convention.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
We should implement the following checks:
- contain at most 63 characters
- contain only lowercase alphanumeric characters or '-'
- start with an alphanumeric character
- end with an alphanumeric character
Are these checks supposed to be implemented on the platformWorkflowName variable in the trackCustomAPIs function (line 982)?
@omgoswami Yes ^^ that is the correct place to add these checks.
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.
Thanks @omgoswami for the update.