From 48beb303becc4481d0a6a27cf2994185d2ff486c Mon Sep 17 00:00:00 2001 From: Diamon Wiggins <38189728+diamonwiggins@users.noreply.github.com> Date: Tue, 11 Oct 2022 14:54:54 -0400 Subject: [PATCH] export context field from collector structs (#771) --- pkg/collect/ceph.go | 4 ++-- pkg/collect/collectd.go | 4 ++-- pkg/collect/configmap.go | 6 +++--- pkg/collect/copy.go | 2 +- pkg/collect/copy_from_host.go | 6 +++--- pkg/collect/data.go | 2 +- pkg/collect/exec.go | 2 +- pkg/collect/logs.go | 2 +- pkg/collect/longhorn.go | 4 ++-- pkg/collect/mysql.go | 2 +- pkg/collect/postgres.go | 2 +- pkg/collect/redis.go | 2 +- pkg/collect/registry.go | 2 +- pkg/collect/run.go | 4 ++-- pkg/collect/run_pod.go | 2 +- pkg/collect/secret.go | 6 +++--- pkg/collect/sysctl.go | 10 +++++----- 17 files changed, 31 insertions(+), 31 deletions(-) diff --git a/pkg/collect/ceph.go b/pkg/collect/ceph.go index 18027bda..63ec31b2 100644 --- a/pkg/collect/ceph.go +++ b/pkg/collect/ceph.go @@ -112,7 +112,7 @@ type CollectCeph struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } @@ -164,7 +164,7 @@ func cephCommandExec(ctx context.Context, progressChan chan<- interface{}, c *Co } rbacErrors := c.GetRBACErrors() - execCollector := &CollectExec{execSpec, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.ctx, rbacErrors} + execCollector := &CollectExec{execSpec, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.Context, rbacErrors} results, err := execCollector.Collect(progressChan) if err != nil { diff --git a/pkg/collect/collectd.go b/pkg/collect/collectd.go index 35f61bb9..022fdd82 100644 --- a/pkg/collect/collectd.go +++ b/pkg/collect/collectd.go @@ -14,7 +14,7 @@ type CollectCollectd struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } @@ -39,7 +39,7 @@ func (c *CollectCollectd) Collect(progressChan chan<- interface{}) (CollectorRes } rbacErrors := c.GetRBACErrors() - copyFromHostCollector := &CollectCopyFromHost{copyFromHost, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.ctx, rbacErrors} + copyFromHostCollector := &CollectCopyFromHost{copyFromHost, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.Context, rbacErrors} return copyFromHostCollector.Collect(progressChan) } diff --git a/pkg/collect/configmap.go b/pkg/collect/configmap.go index 3e052616..23766c26 100644 --- a/pkg/collect/configmap.go +++ b/pkg/collect/configmap.go @@ -33,7 +33,7 @@ type CollectConfigMap struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } @@ -50,7 +50,7 @@ func (c *CollectConfigMap) Collect(progressChan chan<- interface{}) (CollectorRe configMaps := []corev1.ConfigMap{} if c.Collector.Name != "" { - configMap, err := c.Client.CoreV1().ConfigMaps(c.Collector.Namespace).Get(c.ctx, c.Collector.Name, metav1.GetOptions{}) + configMap, err := c.Client.CoreV1().ConfigMaps(c.Collector.Namespace).Get(c.Context, c.Collector.Name, metav1.GetOptions{}) if err != nil { if kuberneteserrors.IsNotFound(err) { filePath, encoded, err := configMapToOutput(c.Collector, nil, c.Collector.Name) @@ -64,7 +64,7 @@ func (c *CollectConfigMap) Collect(progressChan chan<- interface{}) (CollectorRe } configMaps = append(configMaps, *configMap) } else if len(c.Collector.Selector) > 0 { - cms, err := listConfigMapsForSelector(c.ctx, c.Client, c.Collector.Namespace, c.Collector.Selector) + cms, err := listConfigMapsForSelector(c.Context, c.Client, c.Collector.Namespace, c.Collector.Selector) if err != nil { output.SaveResult(c.BundlePath, GetConfigMapErrorsFileName(c.Collector), marshalErrors([]string{err.Error()})) return output, nil diff --git a/pkg/collect/copy.go b/pkg/collect/copy.go index db270a47..1f508993 100644 --- a/pkg/collect/copy.go +++ b/pkg/collect/copy.go @@ -26,7 +26,7 @@ type CollectCopy struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } diff --git a/pkg/collect/copy_from_host.go b/pkg/collect/copy_from_host.go index 3139215a..54301366 100644 --- a/pkg/collect/copy_from_host.go +++ b/pkg/collect/copy_from_host.go @@ -32,7 +32,7 @@ type CollectCopyFromHost struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } @@ -69,13 +69,13 @@ func (c *CollectCopyFromHost) Collect(progressChan chan<- interface{}) (Collecto namespace, _, _ = kubeconfig.Namespace() } - _, cleanup, err := copyFromHostCreateDaemonSet(c.ctx, c.Client, c.Collector, hostDir, namespace, "troubleshoot-copyfromhost-", labels) + _, cleanup, err := copyFromHostCreateDaemonSet(c.Context, c.Client, c.Collector, hostDir, namespace, "troubleshoot-copyfromhost-", labels) defer cleanup() if err != nil { return nil, errors.Wrap(err, "create daemonset") } - childCtx, cancel := context.WithCancel(c.ctx) + childCtx, cancel := context.WithCancel(c.Context) defer cancel() timeoutCtx := context.Background() diff --git a/pkg/collect/data.go b/pkg/collect/data.go index 5dc9e596..437f4240 100644 --- a/pkg/collect/data.go +++ b/pkg/collect/data.go @@ -16,7 +16,7 @@ type CollectData struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } diff --git a/pkg/collect/exec.go b/pkg/collect/exec.go index e3fcfef7..82dabd84 100644 --- a/pkg/collect/exec.go +++ b/pkg/collect/exec.go @@ -22,7 +22,7 @@ type CollectExec struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } diff --git a/pkg/collect/logs.go b/pkg/collect/logs.go index 03c50d40..777156c6 100644 --- a/pkg/collect/logs.go +++ b/pkg/collect/logs.go @@ -22,7 +22,7 @@ type CollectLogs struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context SinceTime *time.Time RBACErrors } diff --git a/pkg/collect/longhorn.go b/pkg/collect/longhorn.go index 8a025bc1..7fd39283 100644 --- a/pkg/collect/longhorn.go +++ b/pkg/collect/longhorn.go @@ -35,7 +35,7 @@ type CollectLonghorn struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } @@ -221,7 +221,7 @@ func (c *CollectLonghorn) Collect(progressChan chan<- interface{}) (CollectorRes } rbacErrors := c.GetRBACErrors() - logsCollector := &CollectLogs{logsCollectorSpec, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.ctx, nil, rbacErrors} + logsCollector := &CollectLogs{logsCollectorSpec, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.Context, nil, rbacErrors} logs, err := logsCollector.Collect(progressChan) if err != nil { diff --git a/pkg/collect/mysql.go b/pkg/collect/mysql.go index 719372b3..76323da3 100644 --- a/pkg/collect/mysql.go +++ b/pkg/collect/mysql.go @@ -20,7 +20,7 @@ type CollectMysql struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } diff --git a/pkg/collect/postgres.go b/pkg/collect/postgres.go index 3c7ca244..71960dba 100644 --- a/pkg/collect/postgres.go +++ b/pkg/collect/postgres.go @@ -21,7 +21,7 @@ type CollectPostgres struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } diff --git a/pkg/collect/redis.go b/pkg/collect/redis.go index 7824b63b..81110cd9 100644 --- a/pkg/collect/redis.go +++ b/pkg/collect/redis.go @@ -20,7 +20,7 @@ type CollectRedis struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } diff --git a/pkg/collect/registry.go b/pkg/collect/registry.go index d486186e..35a4b18b 100644 --- a/pkg/collect/registry.go +++ b/pkg/collect/registry.go @@ -43,7 +43,7 @@ type CollectRegistry struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } diff --git a/pkg/collect/run.go b/pkg/collect/run.go index 119906bb..5685659d 100644 --- a/pkg/collect/run.go +++ b/pkg/collect/run.go @@ -15,7 +15,7 @@ type CollectRun struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } @@ -67,7 +67,7 @@ func (c *CollectRun) Collect(progressChan chan<- interface{}) (CollectorResult, } rbacErrors := c.GetRBACErrors() - runPodCollector := &CollectRunPod{runPodSpec, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.ctx, rbacErrors} + runPodCollector := &CollectRunPod{runPodSpec, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.Context, rbacErrors} return runPodCollector.Collect(progressChan) } diff --git a/pkg/collect/run_pod.go b/pkg/collect/run_pod.go index bafa0857..b58033ab 100644 --- a/pkg/collect/run_pod.go +++ b/pkg/collect/run_pod.go @@ -28,7 +28,7 @@ type CollectRunPod struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } diff --git a/pkg/collect/secret.go b/pkg/collect/secret.go index cb650b71..682207f6 100644 --- a/pkg/collect/secret.go +++ b/pkg/collect/secret.go @@ -32,7 +32,7 @@ type CollectSecret struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } @@ -49,7 +49,7 @@ func (c *CollectSecret) Collect(progressChan chan<- interface{}) (CollectorResul secrets := []corev1.Secret{} if c.Collector.Name != "" { - secret, err := c.Client.CoreV1().Secrets(c.Collector.Namespace).Get(c.ctx, c.Collector.Name, metav1.GetOptions{}) + secret, err := c.Client.CoreV1().Secrets(c.Collector.Namespace).Get(c.Context, c.Collector.Name, metav1.GetOptions{}) if err != nil { if kuberneteserrors.IsNotFound(err) { filePath, encoded, err := secretToOutput(c.Collector, nil, c.Collector.Name) @@ -63,7 +63,7 @@ func (c *CollectSecret) Collect(progressChan chan<- interface{}) (CollectorResul } secrets = append(secrets, *secret) } else if len(c.Collector.Selector) > 0 { - ss, err := listSecretsForSelector(c.ctx, c.Client, c.Collector.Namespace, c.Collector.Selector) + ss, err := listSecretsForSelector(c.Context, c.Client, c.Collector.Namespace, c.Collector.Selector) if err != nil { output.SaveResult(c.BundlePath, GetSecretErrorsFileName(c.Collector), marshalErrors([]string{err.Error()})) return output, nil diff --git a/pkg/collect/sysctl.go b/pkg/collect/sysctl.go index 9a5d3257..71bab874 100644 --- a/pkg/collect/sysctl.go +++ b/pkg/collect/sysctl.go @@ -22,7 +22,7 @@ type CollectSysctl struct { Namespace string ClientConfig *rest.Config Client kubernetes.Interface - ctx context.Context + Context context.Context RBACErrors } @@ -43,9 +43,9 @@ func (c *CollectSysctl) Collect(progressChan chan<- interface{}) (CollectorResul if timeout == 0 { timeout = time.Minute } - childCtx, cancel := context.WithTimeout(c.ctx, timeout) + childCtx, cancel := context.WithTimeout(c.Context, timeout) defer cancel() - c.ctx = childCtx + c.Context = childCtx } if c.Collector.Namespace == "" { @@ -74,7 +74,7 @@ find /proc/sys/net/bridge -type f | while read f; do v=$(cat $f 2>/dev/null); ec runPodOptions.ImagePullSecretName = c.Collector.ImagePullSecret.Name if c.Collector.ImagePullSecret.Data != nil { - secretName, err := createSecret(c.ctx, c.Client, c.Collector.Namespace, c.Collector.ImagePullSecret) + secretName, err := createSecret(c.Context, c.Client, c.Collector.Namespace, c.Collector.ImagePullSecret) if err != nil { return nil, errors.Wrap(err, "create image pull secret") } @@ -89,7 +89,7 @@ find /proc/sys/net/bridge -type f | while read f; do v=$(cat $f 2>/dev/null); ec } } - results, err := RunPodsReadyNodes(c.ctx, c.Client.CoreV1(), runPodOptions) + results, err := RunPodsReadyNodes(c.Context, c.Client.CoreV1(), runPodOptions) if err != nil { return nil, err }