From e9f060ef0fae48f238b1d3999879718aab2e7ca0 Mon Sep 17 00:00:00 2001 From: clementlachaussee Date: Thu, 16 Nov 2023 10:39:49 +0100 Subject: [PATCH 1/8] feat: add imagePullSecrets and imagePullPolicy in shell_pod for internal registry use cases --- internal/config/shell_pod.go | 17 +++++++++++------ internal/view/exec.go | 4 ++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/config/shell_pod.go b/internal/config/shell_pod.go index a9c429b832..d6c694f88a 100644 --- a/internal/config/shell_pod.go +++ b/internal/config/shell_pod.go @@ -12,12 +12,14 @@ type Limits map[v1.ResourceName]string // ShellPod represents k9s shell configuration. type ShellPod struct { - Image string `json:"image"` - Command []string `json:"command,omitempty"` - Args []string `json:"args,omitempty"` - Namespace string `json:"namespace"` - Limits Limits `json:"resources,omitempty"` - Labels map[string]string `json:"labels,omitempty"` + Image string `json:"image"` + ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty" yaml:"imagePullSecrets,omitempty"` + ImagePullPolicy string `json:"imagePullPolicy,omitempty" yaml:"imagePullPolicy,omitempty"` + Command []string `json:"command,omitempty"` + Args []string `json:"args,omitempty"` + Namespace string `json:"namespace"` + Limits Limits `json:"resources,omitempty"` + Labels map[string]string `json:"labels,omitempty"` } // NewShellPod returns a new instance. @@ -37,6 +39,9 @@ func (s *ShellPod) Validate(client.Connection, KubeSettings) { if len(s.Limits) == 0 { s.Limits = defaultLimits() } + if len(s.ImagePullSecrets) == 0 { + s.ImagePullSecrets = []v1.LocalObjectReference{} + } } func defaultLimits() Limits { diff --git a/internal/view/exec.go b/internal/view/exec.go index e80dca0a05..2f1e52f4d5 100644 --- a/internal/view/exec.go +++ b/internal/view/exec.go @@ -378,6 +378,9 @@ func k9sShellPod(node string, cfg *config.ShellPod) *v1.Pod { if len(cfg.Args) > 0 { c.Args = cfg.Args } + if len(cfg.ImagePullPolicy) > 0 { + c.ImagePullPolicy = v1.PullPolicy(cfg.ImagePullPolicy) + } return &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -390,6 +393,7 @@ func k9sShellPod(node string, cfg *config.ShellPod) *v1.Pod { RestartPolicy: v1.RestartPolicyNever, HostPID: true, HostNetwork: true, + ImagePullSecrets: cfg.ImagePullSecrets, TerminationGracePeriodSeconds: &grace, Volumes: []v1.Volume{ { From 61ee4a6dc905162e1a01c2888feb7463054e1600 Mon Sep 17 00:00:00 2001 From: clementlachaussee Date: Thu, 16 Nov 2023 10:48:52 +0100 Subject: [PATCH 2/8] docs: add imagePullPolicy and imagePullSecrets configuration example --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index b3c0ad1394..efd5201acd 100644 --- a/README.md +++ b/README.md @@ -385,6 +385,11 @@ K9s uses aliases to navigate most K8s resources. image: killerAdmin # The namespace to launch to shell pod into. namespace: fred + # imagePullPolicy defaults to Always + imagePullPolicy: Always + # imagePullSecrets defaults to no secrets + # imagePullSecrets: + # - name: my-regcred # The resource limit to set on the shell pod. limits: cpu: 100m @@ -429,6 +434,12 @@ k9s: shellPod: image: cool_kid_admin:42 namespace: blee + # imagePullPolicy defaults to Always + imagePullPolicy: Always + # imagePullSecrets defaults to no secrets + # imagePullSecrets: + # - name: my-regcred + # The resource limit to limits: cpu: 100m memory: 100Mi From 843acb5c827188d6ff518ba0a8fd838d787261cf Mon Sep 17 00:00:00 2001 From: clementlachaussee Date: Thu, 16 Nov 2023 10:51:15 +0100 Subject: [PATCH 3/8] docs: remove comments --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index efd5201acd..f6a98227c8 100644 --- a/README.md +++ b/README.md @@ -388,8 +388,8 @@ K9s uses aliases to navigate most K8s resources. # imagePullPolicy defaults to Always imagePullPolicy: Always # imagePullSecrets defaults to no secrets - # imagePullSecrets: - # - name: my-regcred + imagePullSecrets: + - name: my-regcred # The resource limit to set on the shell pod. limits: cpu: 100m @@ -436,9 +436,9 @@ k9s: namespace: blee # imagePullPolicy defaults to Always imagePullPolicy: Always - # imagePullSecrets defaults to no secrets - # imagePullSecrets: - # - name: my-regcred + # imagePullSecrets defaults to no secret, remove the option if you don't need it. + imagePullSecrets: + - name: my-regcred # The resource limit to limits: cpu: 100m From 4ee6c9d005c7c01fee7d3e8efef5bdc08414d47a Mon Sep 17 00:00:00 2001 From: clementlachaussee Date: Thu, 16 Nov 2023 11:16:25 +0100 Subject: [PATCH 4/8] docs: use same wording --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6a98227c8..cad77b7688 100644 --- a/README.md +++ b/README.md @@ -387,7 +387,7 @@ K9s uses aliases to navigate most K8s resources. namespace: fred # imagePullPolicy defaults to Always imagePullPolicy: Always - # imagePullSecrets defaults to no secrets + # imagePullSecrets defaults to no secret, remove the option if you don't need it. imagePullSecrets: - name: my-regcred # The resource limit to set on the shell pod. From a5b19d50eef91b43cc2eff59404a5606933d6ed3 Mon Sep 17 00:00:00 2001 From: clementlachaussee Date: Thu, 16 Nov 2023 11:35:04 +0100 Subject: [PATCH 5/8] docs: remove useless phrase --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cad77b7688..125af642b5 100644 --- a/README.md +++ b/README.md @@ -387,7 +387,7 @@ K9s uses aliases to navigate most K8s resources. namespace: fred # imagePullPolicy defaults to Always imagePullPolicy: Always - # imagePullSecrets defaults to no secret, remove the option if you don't need it. + # imagePullSecrets defaults to no secret imagePullSecrets: - name: my-regcred # The resource limit to set on the shell pod. @@ -436,7 +436,7 @@ k9s: namespace: blee # imagePullPolicy defaults to Always imagePullPolicy: Always - # imagePullSecrets defaults to no secret, remove the option if you don't need it. + # imagePullSecrets defaults to no secret imagePullSecrets: - name: my-regcred # The resource limit to From 58d3c3e903dad34fca71f50ad7af8848a59c7e6f Mon Sep 17 00:00:00 2001 From: clementlachaussee Date: Thu, 16 Nov 2023 14:12:07 +0100 Subject: [PATCH 6/8] fix: truncated comment --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 125af642b5..3e78f7b8ab 100644 --- a/README.md +++ b/README.md @@ -439,7 +439,7 @@ k9s: # imagePullSecrets defaults to no secret imagePullSecrets: - name: my-regcred - # The resource limit to + # The resource limit to set on the shell pod. limits: cpu: 100m memory: 100Mi From 98a14586a907bd6815f44e0111e2ba171f2a6be6 Mon Sep 17 00:00:00 2001 From: clementlachaussee Date: Tue, 21 Nov 2023 17:03:09 +0100 Subject: [PATCH 7/8] fix: use correct type, remove useless if --- internal/config/shell_pod.go | 5 +---- internal/view/exec.go | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/internal/config/shell_pod.go b/internal/config/shell_pod.go index d6c694f88a..3ad705febc 100644 --- a/internal/config/shell_pod.go +++ b/internal/config/shell_pod.go @@ -14,7 +14,7 @@ type Limits map[v1.ResourceName]string type ShellPod struct { Image string `json:"image"` ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty" yaml:"imagePullSecrets,omitempty"` - ImagePullPolicy string `json:"imagePullPolicy,omitempty" yaml:"imagePullPolicy,omitempty"` + ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty" yaml:"imagePullPolicy,omitempty"` Command []string `json:"command,omitempty"` Args []string `json:"args,omitempty"` Namespace string `json:"namespace"` @@ -39,9 +39,6 @@ func (s *ShellPod) Validate(client.Connection, KubeSettings) { if len(s.Limits) == 0 { s.Limits = defaultLimits() } - if len(s.ImagePullSecrets) == 0 { - s.ImagePullSecrets = []v1.LocalObjectReference{} - } } func defaultLimits() Limits { diff --git a/internal/view/exec.go b/internal/view/exec.go index 2f1e52f4d5..8d6fe30c2a 100644 --- a/internal/view/exec.go +++ b/internal/view/exec.go @@ -378,9 +378,6 @@ func k9sShellPod(node string, cfg *config.ShellPod) *v1.Pod { if len(cfg.Args) > 0 { c.Args = cfg.Args } - if len(cfg.ImagePullPolicy) > 0 { - c.ImagePullPolicy = v1.PullPolicy(cfg.ImagePullPolicy) - } return &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ From ac83ec5417c634fea4b6712b7521c1ab6c0a7644 Mon Sep 17 00:00:00 2001 From: clementlachaussee Date: Tue, 21 Nov 2023 17:09:39 +0100 Subject: [PATCH 8/8] add: ImagePullPolicy on container variable --- internal/view/exec.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/view/exec.go b/internal/view/exec.go index 8d6fe30c2a..7c64b5bb95 100644 --- a/internal/view/exec.go +++ b/internal/view/exec.go @@ -357,8 +357,9 @@ func k9sShellPod(node string, cfg *config.ShellPod) *v1.Pod { log.Debug().Msgf("Shell Config %#v", cfg) c := v1.Container{ - Name: k9sShell, - Image: cfg.Image, + Name: k9sShell, + Image: cfg.Image, + ImagePullPolicy: cfg.ImagePullPolicy, VolumeMounts: []v1.VolumeMount{ { Name: "root-vol",