Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kubernetes] Add support for k8s snap #3842

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading