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 authored and TurboTurtle committed Nov 23, 2024
1 parent aae6867 commit 0c70fa9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 39 additions & 1 deletion sos/report/plugins/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def check_is_master(self):
def setup(self):
self.add_copy_spec(self.config_files)

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

self.add_env_var([
'KUBECONFIG',
'KUBERNETES_HTTP_PROXY',
Expand Down Expand Up @@ -294,7 +296,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 +320,46 @@ 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([
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_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 0c70fa9

Please sign in to comment.