tyk-operator
tyk-operator copied to clipboard
Allow for Ingress APIs to have categories
trafficstars
When an api in the apidefinition has a name with tags like "myapi #demo #infra" it will result in categories in the Dashboard. When using the ingress and apidefenition
apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
name: myapideftemplate
labels:
name: myapi
template: "true"
spec:
name: "myapi #demo #infra"
......
The name is ignored and and constructed via the function: https://github.com/TykTechnologies/tyk-operator/blob/39ff14bed1ed8b81f438821d9af443eb18985ec8/controllers/ingress_controller.go#L279
func (r *IngressReconciler) buildAPIName(nameSpace, name, hash string) string {
return fmt.Sprintf("%s-%s-%s", nameSpace, name, hash)
}
This will not allow for having categories on you ingress api's. I would like to propose to change the code to:
name := r.buildAPIName(ns, desired.Name, template.Spec.Name, hash)
func buildAPIName(nameSpace, ingress_name, template_name, hash string) string {
r, _ := regexp.Compile("#\\w+")
categories := r.FindAllString(template_name, -1)
return fmt.Sprintf("%s-%s-%s %s", nameSpace, ingress_name, hash, strings.Join(categories, " "))
}