kubeplus icon indicating copy to clipboard operation
kubeplus copied to clipboard

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

Open devdattakulkarni opened this issue 1 year ago • 2 comments
trafficstars

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 avatar Apr 16 '24 10:04 devdattakulkarni

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.

devdattakulkarni avatar Apr 16 '24 10:04 devdattakulkarni

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

devdattakulkarni avatar May 09 '24 21:05 devdattakulkarni

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

omgoswami avatar Jul 06 '24 00:07 omgoswami

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

devdattakulkarni avatar Jul 08 '24 11:07 devdattakulkarni

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.

omgoswami avatar Jul 09 '24 17:07 omgoswami

Thanks @omgoswami for the update.

devdattakulkarni avatar Jul 09 '24 18:07 devdattakulkarni