From 2b774e16d71a97ccbdc5e0f5a542144c1a41fa4a Mon Sep 17 00:00:00 2001 From: diamonwiggins Date: Thu, 3 Mar 2022 06:12:42 +0000 Subject: [PATCH] adding serviceaccountname parameter to run collector --- .../troubleshoot/v1beta2/collector_shared.go | 19 ++++++++++--------- pkg/collect/run.go | 8 +++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/apis/troubleshoot/v1beta2/collector_shared.go b/pkg/apis/troubleshoot/v1beta2/collector_shared.go index 60b56b4f..b315abd3 100644 --- a/pkg/apis/troubleshoot/v1beta2/collector_shared.go +++ b/pkg/apis/troubleshoot/v1beta2/collector_shared.go @@ -65,15 +65,16 @@ type Data struct { } type Run struct { - CollectorMeta `json:",inline" yaml:",inline"` - Name string `json:"name,omitempty" yaml:"name,omitempty"` - Namespace string `json:"namespace" yaml:"namespace"` - Image string `json:"image" yaml:"image"` - Command []string `json:"command,omitempty" yaml:"command,omitempty"` - Args []string `json:"args,omitempty" yaml:"args,omitempty"` - Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"` - ImagePullPolicy string `json:"imagePullPolicy,omitempty" yaml:"imagePullPolicy,omitempty"` - ImagePullSecret *ImagePullSecrets `json:"imagePullSecret,omitempty" yaml:"imagePullSecret,omitempty"` + CollectorMeta `json:",inline" yaml:",inline"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Namespace string `json:"namespace" yaml:"namespace"` + Image string `json:"image" yaml:"image"` + Command []string `json:"command,omitempty" yaml:"command,omitempty"` + Args []string `json:"args,omitempty" yaml:"args,omitempty"` + Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"` + ImagePullPolicy string `json:"imagePullPolicy,omitempty" yaml:"imagePullPolicy,omitempty"` + ImagePullSecret *ImagePullSecrets `json:"imagePullSecret,omitempty" yaml:"imagePullSecret,omitempty"` + ServiceAccountName string `json:"serviceAccountName,omitempty" yaml:"serviceAccountName,omitempty"` } type ImagePullSecrets struct { diff --git a/pkg/collect/run.go b/pkg/collect/run.go index a53b50f4..6a42424a 100644 --- a/pkg/collect/run.go +++ b/pkg/collect/run.go @@ -135,6 +135,11 @@ func runPod(ctx context.Context, client *kubernetes.Clientset, runCollector *tro namespace = "default" } + serviceAccountName := "default" + if runCollector.ServiceAccountName != "" { + serviceAccountName = runCollector.ServiceAccountName + } + pod := corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: runCollector.CollectorName, @@ -146,7 +151,8 @@ func runPod(ctx context.Context, client *kubernetes.Clientset, runCollector *tro Kind: "Pod", }, Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyNever, + RestartPolicy: corev1.RestartPolicyNever, + ServiceAccountName: serviceAccountName, Containers: []corev1.Container{ { Image: runCollector.Image,