From ab9ac27982d6edaa765a0463010c9f49ef6e2858 Mon Sep 17 00:00:00 2001 From: jessebot Date: Fri, 12 Jan 2024 10:48:17 +0100 Subject: [PATCH] specify an id for the kubelet widget so that we can generate rows for it --- smol_k8s_lab/tui/css/kind.tcss | 4 ++-- smol_k8s_lab/tui/distro_screen.py | 19 ++++++++++++++----- .../tui/distro_widgets/kubelet_config.py | 10 ++++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/smol_k8s_lab/tui/css/kind.tcss b/smol_k8s_lab/tui/css/kind.tcss index baf02f584..9dc00d02a 100644 --- a/smol_k8s_lab/tui/css/kind.tcss +++ b/smol_k8s_lab/tui/css/kind.tcss @@ -57,13 +57,13 @@ KubeletConfig { } /* kubelet config container */ -#kubelet-config-container { +.kubelet-config-container { padding: 1; grid-rows: 0.25fr 1fr; align: center middle; } -#kubelet-config-scroll { +.kubelet-config-scroll { align: center middle; scrollbar-background: $dark_gray; scrollbar-background-active: $dark_gray; diff --git a/smol_k8s_lab/tui/distro_screen.py b/smol_k8s_lab/tui/distro_screen.py index ba928b6f3..45c08ba11 100755 --- a/smol_k8s_lab/tui/distro_screen.py +++ b/smol_k8s_lab/tui/distro_screen.py @@ -180,21 +180,30 @@ def update_k8s_distro(self, event: Select.Changed) -> None: def action_launch_new_option_modal(self) -> None: def add_new_row(option: str): if option and self.current_distro != 'kind': - k3s_widget = self.get_widget_by_id(f"{self.current_distro}-widget") + if self.query_one(TabbedContent).active == "k3s-yaml-tab": + k3s_widget = self.get_widget_by_id(f"{self.current_distro}-widget") + else: + k3s_widget = self.get_widget_by_id( + f"kubelet-config-{self.current_distro}" + ) k3s_widget.generate_row(option) + elif option and self.current_distro == 'kind': if self.query_one(TabbedContent).active == "kind-networking-tab": kind_widget = self.query_one(KindNetworkingConfig) - kind_widget.generate_row(option) else: - kind_widget = self.query_one(KubeletConfig) - kind_widget.generate_row(option) + kind_widget = self.get_widget_by_id( + f"kubelet-config-{self.current_distro}" + ) + kind_widget.generate_row(option) else: return if self.current_distro != 'kind': if self.query_one(TabbedContent).active == "k3s-kubelet-tab": - existing_keys = self.cfg[self.current_distro]['k3s_yaml'].get("kubelet-arg", []) + existing_keys = self.cfg[self.current_distro]['k3s_yaml'].get( + "kubelet-arg", [] + ) trigger = "k3s kubelet" else: existing_keys = self.cfg[self.current_distro]['k3s_yaml'].keys() diff --git a/smol_k8s_lab/tui/distro_widgets/kubelet_config.py b/smol_k8s_lab/tui/distro_widgets/kubelet_config.py index d985d210b..38480f27e 100644 --- a/smol_k8s_lab/tui/distro_widgets/kubelet_config.py +++ b/smol_k8s_lab/tui/distro_widgets/kubelet_config.py @@ -29,12 +29,14 @@ class KubeletConfig(Widget): def __init__(self, distro: str, kubelet_extra_args: list = []) -> None: self.distro = distro self.kubelet_extra_args = kubelet_extra_args - super().__init__() + super().__init__(id=f"kubelet-config-{distro}") def compose(self) -> ComposeResult: - with Grid(id="kubelet-config-container"): + with Grid(id=f"kubelet-config-container-{self.distro}", + classes="kubelet-config-container"): yield Label(kubelet_help, classes="help-text") - yield VerticalScroll(id="kubelet-config-scroll") + yield VerticalScroll(id=f"kubelet-config-scroll-{self.distro}", + classes="kubelet-config-scroll") def on_mount(self) -> None: if self.kubelet_extra_args: @@ -146,7 +148,7 @@ def generate_row(self, param: str = "", value: str = "") -> Grid: del_button = Button("🚮", id=f"kind-kubelet-delete-{param}-button") del_button.tooltip = "Delete this kubelet parameter" - self.get_widget_by_id("kubelet-config-scroll").mount( + self.get_widget_by_id(f"kubelet-config-scroll-{self.distro}").mount( Grid(label, param_value_input, del_button, classes="label-input-delete-row") )