mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
* add support bundle metadata collector * add e2e test for the new collector * make fmt * properly include v1beta3 * remove the ability to specify an arbitrary secret
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package collect
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/pkg/errors"
|
|
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/rest"
|
|
)
|
|
|
|
type CollectSupportBundleMetadata struct {
|
|
Collector *troubleshootv1beta2.SupportBundleMetadata
|
|
BundlePath string
|
|
Namespace string
|
|
ClientConfig *rest.Config
|
|
Client kubernetes.Interface
|
|
Context context.Context
|
|
RBACErrors
|
|
}
|
|
|
|
func (c *CollectSupportBundleMetadata) Title() string {
|
|
return getCollectorName(c)
|
|
}
|
|
|
|
func (c *CollectSupportBundleMetadata) IsExcluded() (bool, error) {
|
|
return isExcluded(c.Collector.Exclude)
|
|
}
|
|
|
|
func (c *CollectSupportBundleMetadata) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
|
|
output := NewResult()
|
|
|
|
const secretName = "replicated-support-metadata"
|
|
secret, err := c.Client.CoreV1().Secrets(c.Collector.Namespace).Get(c.Context, secretName, metav1.GetOptions{})
|
|
if err != nil {
|
|
return output, errors.Wrapf(err, "failed to get secret %s/%s", c.Collector.Namespace, secretName)
|
|
}
|
|
|
|
metadata := make(map[string]string)
|
|
for k, v := range secret.Data {
|
|
metadata[k] = string(v)
|
|
}
|
|
|
|
b, err := json.MarshalIndent(metadata, "", " ")
|
|
if err != nil {
|
|
return output, errors.Wrap(err, "failed to marshal metadata")
|
|
}
|
|
|
|
output.SaveResult(c.BundlePath, "metadata/cluster.json", bytes.NewBuffer(b))
|
|
return output, nil
|
|
}
|