export context field from collector structs (#771)

This commit is contained in:
Diamon Wiggins
2022-10-11 14:54:54 -04:00
committed by GitHub
parent e30d279cad
commit 48beb303be
17 changed files with 31 additions and 31 deletions

View File

@@ -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 {

View File

@@ -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)
}

View File

@@ -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

View File

@@ -26,7 +26,7 @@ type CollectCopy struct {
Namespace string
ClientConfig *rest.Config
Client kubernetes.Interface
ctx context.Context
Context context.Context
RBACErrors
}

View File

@@ -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()

View File

@@ -16,7 +16,7 @@ type CollectData struct {
Namespace string
ClientConfig *rest.Config
Client kubernetes.Interface
ctx context.Context
Context context.Context
RBACErrors
}

View File

@@ -22,7 +22,7 @@ type CollectExec struct {
Namespace string
ClientConfig *rest.Config
Client kubernetes.Interface
ctx context.Context
Context context.Context
RBACErrors
}

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -20,7 +20,7 @@ type CollectMysql struct {
Namespace string
ClientConfig *rest.Config
Client kubernetes.Interface
ctx context.Context
Context context.Context
RBACErrors
}

View File

@@ -21,7 +21,7 @@ type CollectPostgres struct {
Namespace string
ClientConfig *rest.Config
Client kubernetes.Interface
ctx context.Context
Context context.Context
RBACErrors
}

View File

@@ -20,7 +20,7 @@ type CollectRedis struct {
Namespace string
ClientConfig *rest.Config
Client kubernetes.Interface
ctx context.Context
Context context.Context
RBACErrors
}

View File

@@ -43,7 +43,7 @@ type CollectRegistry struct {
Namespace string
ClientConfig *rest.Config
Client kubernetes.Interface
ctx context.Context
Context context.Context
RBACErrors
}

View File

@@ -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)
}

View File

@@ -28,7 +28,7 @@ type CollectRunPod struct {
Namespace string
ClientConfig *rest.Config
Client kubernetes.Interface
ctx context.Context
Context context.Context
RBACErrors
}

View File

@@ -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

View File

@@ -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
}