Is in the kubernetes API a function to fetch all services by annotations

5/13/2019

I'm setting up a kubernet cluster to roll out our container applications. The applications actually need all labels, but the labels are longer than 63 characters and I get an error. This makes me dependent on annotations.

An annotation for a service looks like this: com.example.development.london/component.proxy-config.secure-routes.backend.proxy-path. The / only serves to bypass an RFC domain error.

In a Golang application all services of a namespace are requested. Actually based on the labels. For this I have used the following code so far.

func (kc *KubernetesCollector) generateRoutes(errorChannel chan<- error) {
    log.Println("INFO: Try to generate routes")
    services, err := kc.iface.Services(kc.namespace).List(metav1.ListOptions{
        LabelSelector: fmt.Sprintf("%s==true", ConvertLabelToKubernetesAnnotation(ProxyConfDiscoverableLabel)),
    })
...

func ConvertLabelToKubernetesAnnotation(label string) string {
    return strings.Replace(label, "com.example.development.london.", "com.example.development.london/", -1)
}

But there is no possibility to return the services using annotations. Does anyone know another way how I can get all services that apply to an annotation with Go?

-- Volker Raschek
go
kubernetes

2 Answers

5/13/2019

There is no FieldSelector for annotations. What you can do is get all services into your list and then filter them based on annotations found in each.

-- antweiss
Source: StackOverflow

5/13/2019

As specified in the Kubernetes documentation, annotations are meant for non-identifying information, so naturally you shouldn't use them for finding objects.

If that's an option, you can attach a prefix (max length of 253 characters) to your label in this manner: <label prefix>/<label name>. Additional information can be found from the link provided above.

-- Alassane Ndiaye
Source: StackOverflow