Files
troubleshoot/pkg/collect/support_bundle_metadata.go
Andrew Lavery 94db56d668 add a dedicated support bundle metadata collector (#1992)
* 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
2026-03-12 12:38:45 -04:00

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
}