Repository: canonical/microk8s

Issue:
Error: open servers store: open /var/snap/microk8s/3699/var/kubernetes/backend/cluster.yaml: permission denied
#### Summary
Periodically, on checking a newly configured and restarted Microk8s, an permission denied error is printed.  Microk8s appears to be fully functional, so I do not know the impact of this error.

#### What Should Happen Instead?
No error message displayed.

#### Reproduction Steps
This is not 100% reproducible.  In OSM, we have an installer which configures Microk8s as follows.  The IP address 172.21.248.101 in this case is the only IP on the VM where Microk8s is being installed.

```
+ sudo snap install microk8s --classic --channel=1.23/stable
snap "microk8s" is already installed, see 'snap help refresh'
++ whoami
+ sudo usermod -a -G microk8s ubuntu
+ sudo cat /var/snap/microk8s/current/args/kube-apiserver
+ grep advertise-address
+ echo '--advertise-address 172.21.248.101'
+ sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
--advertise-address 172.21.248.101
+ sg microk8s -c microk8s.stop
Stopped.
+ sg microk8s -c microk8s.start
Started.
+ sg microk8s -c 'microk8s status --wait-ready'
Error: open servers store: open /var/snap/microk8s/3699/var/kubernetes/backend/cluster.yaml: permission denied
Usage:
  dqlite -s <servers> <database> [command] [flags]

Flags:
  -c, --cert string       public TLS cert
  -f, --format string     output format (tabular, json) (default "tabular")
  -h, --help              help for dqlite
  -k, --key string        private TLS key
  -s, --servers strings   comma-separated list of db servers, or file://<store>

Error: open servers store: open /var/snap/microk8s/3699/var/kubernetes/backend/cluster.yaml: permission denied
Usage:
  dqlite -s <servers> <database> [command] [flags]

Flags:
  -c, --cert string       public TLS cert
  -f, --format string     output format (tabular, json) (default "tabular")
  -h, --help              help for dqlite
  -k, --key string        private TLS key
  -s, --servers strings   comma-separated list of db servers, or file://<store>

microk8s is running
high-availability: no
  datastore master nodes: 127.0.0.1:19001
  datastore standby nodes: none
addons:
  enabled:
    ha-cluster           # Configure high availability on the current node
  disabled:
    ambassador           # Ambassador API Gateway and Ingress
    cilium               # SDN, fast with full network policy
    dashboard            # The Kubernetes dashboard
    dashboard-ingress    # Ingress definition for Kubernetes dashboard
    dns                  # CoreDNS
    fluentd              # Elasticsearch-Fluentd-Kibana logging and monitoring
    gpu                  # Automatic enablement of Nvidia CUDA
    helm                 # Helm 2 - the package manager for Kubernetes
    helm3                # Helm 3 - Kubernetes package manager
    host-access          # Allow Pods connecting to Host services smoothly
    inaccel              # Simplifying FPGA management in Kubernetes
    ingress              # Ingress controller for external access
    istio                # Core Istio service mesh services
    jaeger               # Kubernetes Jaeger operator with its simple config
    kata                 # Kata Containers is a secure runtime with lightweight VMS
    keda                 # Kubernetes-based Event Driven Autoscaling
    knative              # The Knative framework on Kubernetes.
    kubeflow             # Kubeflow for easy ML deployments
    linkerd              # Linkerd is a service mesh for Kubernetes and other frameworks
    metallb              # Loadbalancer for your Kubernetes cluster
    metrics-server       # K8s Metrics Server for API access to service metrics
    multus               # Multus CNI enables attaching multiple network interfaces to pods
    openebs              # OpenEBS is the open-source storage solution for Kubernetes
    openfaas             # OpenFaaS serverless framework
    portainer            # Portainer UI for your Kubernetes cluster
    prometheus           # Prometheus operator for monitoring and logging
    rbac                 # Role-Based Access Control for authorisation
    registry             # Private image registry exposed on localhost:32000
    storage              # Storage class; allocates storage from host directory
    traefik              # traefik Ingress controller for external access
```



Discussion:

Resolving patch:
diff --git a/scripts/wrappers/common/utils.py b/scripts/wrappers/common/utils.py
--- a/scripts/wrappers/common/utils.py
+++ b/scripts/wrappers/common/utils.py
@@ -87,6 +87,7 @@ def get_dqlite_info():
                         snappath=snap_path, dbdir=cluster_dir
                     ).split(),
                     timeout=4,
+                    stderr=subprocess.DEVNULL,
                 )
                 if data["Address"] in out.decode():
                     break


Test patch: