Cluster name has a stray "\n" character, messing up dashboard queries

Bug #2058269 reported by Leon
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Kubernetes Control Plane Charm
Fix Released
High
Kevin W Monroe

Bug Description

It seems that the generated cluster name may contain and end-of-line character:
https://github.com/charmed-kubernetes/charm-kubernetes-control-plane/blob/da2725c67c44bcc855de166fc3251c28879498dd/src/charm.py#L418C9-L418C28

Not sure how it could happen, but on grafana we can clearly see this:

          "labels": {
            "__name__": "kube_pod_container_resource_requests",
            "cluster": "kubernetes-1er8ci1qdkk64gndu4n0b8trf7azivp8\n",
            "container": "calico-node",
            "exported_node": "m2",
            "instance": "localhost:6443",
            "job": "kube-state-metrics",

Also see screenshot.

This can be confirmed by querying prometheus directly:

$ curl 10.1.199.215:9090/api/v1/label/cluster/values
{"status":"success","data":["etcd-0","kubernetes-1er8ci1qdkk64gndu4n0b8trf7azivp8\n"]}

Reproducer is available here: https://pastebin.canonical.com/p/dqyx5TwFkx/

Revision history for this message
Leon (sed-i) wrote :
Changed in charm-kubernetes-master:
milestone: none → 1.29+ck1
Changed in charm-kubernetes-master:
status: New → In Progress
importance: Undecided → High
assignee: nobody → Kevin W Monroe (kwmonroe)
Changed in charm-kubernetes-master:
milestone: 1.29+ck1 → 1.29+ck2
Revision history for this message
Adam Dyess (addyess) wrote :

I see no way of actually generating a LF or CR.

the method to create the clustername is

```
def token_generator(length=32):
    """Generate a random token for use in account tokens.

    param: length - the length of the token to generate
    """
    alpha = string.ascii_letters + string.digits
    token = "".join(random.SystemRandom().choice(alpha) for _ in range(length))
    return token
```

which limits the cluster name to be alphanumerics. After this call a further winnowing is done to push to lowercase.

Its more likely this comes from the upgrade where the cluster was stored in leader_set.

we should strip the output from leader_get here

https://github.com/charmed-kubernetes/charm-kubernetes-control-plane/blob/da2725c67c44bcc855de166fc3251c28879498dd/src/charm.py#L409-L410

Revision history for this message
Adam Dyess (addyess) wrote :
tags: added: backport-needed
Revision history for this message
Adam Dyess (addyess) wrote :
Changed in charm-kubernetes-master:
status: In Progress → Fix Committed
Changed in charm-kubernetes-master:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.