Skip to content

Commit

Permalink
[kubernetes] Add support for k8s snap
Browse files Browse the repository at this point in the history
Also, fix command for microk8s, and use variable

Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
arif-ali committed Nov 19, 2024
1 parent 2aa4fcf commit eaa59de
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
41 changes: 40 additions & 1 deletion sos/report/plugins/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ def setup(self):

class UbuntuKubernetes(Kubernetes, UbuntuPlugin, DebianPlugin):

packages = KUBE_PACKAGES
packages = KUBE_PACKAGES + (
'k8s',
)

files = KUBECONFIGS + (
'/root/cdk/cdk_addons_kubectl_config',
Expand All @@ -316,12 +318,49 @@ def setup(self):

if self.is_installed('microk8s'):
self.kube_cmd = 'microk8s kubectl'
elif self.is_installed('k8s'):
self.kube_cmd = 'k8s kubectl'
self._canonical_kubernetes()

self.config_files.extend([
'/root/cdk/kubelet/config.yaml',
'/root/cdk/audit/audit-policy.yaml',
])
super().setup()

def _canonical_kubernetes(self):
self.add_journal(units="snap.k8s.*")

k8s_cmd = "k8s"
k8s_common = "/var/snap/k8s/common"

k8s_subcmds = [
'status',
'get',
]

self.add_copy_spec([
"/etc/kubernetes/"
f"{k8s_common}/args",
f"{k8s_common}/var/lib/k8s-dqlite/info.yaml",
f"{k8s_common}/var/lib/k8s-dqlite/cluster.yaml",
f"{k8s_common}/var/lib/k8sd/state/truststore/k8s.yaml",
f"{k8s_common}/var/lib/k8sd/state/database/info.yaml",
f"{k8s_common}/var/lib/k8sd/state/database/cluster.yaml",
f"{k8s_common}/var/lib/k8sd/state/daemon.yaml",
])

self.add_forbidden_path("/etc/kubernetes/pki")

self.add_cmd_output([
f"{k8s_cmd} {subcmd}" for subcmd in k8s_subcmds
])

def postproc(self):
super().postproc()

self.do_file_private_sub(
"/var/snap/k8s/common/var/lib/k8sd/state/truststore/k8s.yaml")


# vim: et ts=5 sw=4
4 changes: 2 additions & 2 deletions sos/report/plugins/microk8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def setup(self):
)

self.add_cmd_output([
f"microk8s {subcmd}" for subcmd in microk8s_subcmds
f"{self.microk8s_cmd} {subcmd}" for subcmd in microk8s_subcmds
])

def postproc(self):
rsub = r'(certificate-authority-data:|token:)\s.*'
self.do_cmd_output_sub("microk8s", rsub, r'\1 "**********"')
self.do_cmd_output_sub(self.microk8s_cmd, rsub, r'\1 "**********"')

protect_keys = [
"certificate-authority-data",
Expand Down

0 comments on commit eaa59de

Please sign in to comment.