Skip to content

Commit

Permalink
feat: add velero collector (#806)
Browse files Browse the repository at this point in the history
  * test velero spec

  * need to get an older velero library to support restic
  • Loading branch information
adamancini authored and arcolife committed Oct 11, 2023
1 parent 15a4802 commit 8988c4d
Show file tree
Hide file tree
Showing 14 changed files with 643 additions and 34 deletions.
13 changes: 13 additions & 0 deletions config/crds/troubleshoot.sh_collectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8823,6 +8823,19 @@ spec:
- image
- namespace
type: object
velero:
properties:
collectorName:
type: string
exclude:
type: BoolString
namespace:
type: string
timeout:
type: string
required:
- namespace
type: object
type: object
type: array
type: object
Expand Down
13 changes: 13 additions & 0 deletions config/crds/troubleshoot.sh_preflights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10320,6 +10320,19 @@ spec:
- image
- namespace
type: object
velero:
properties:
collectorName:
type: string
exclude:
type: BoolString
namespace:
type: string
timeout:
type: string
required:
- namespace
type: object
type: object
type: array
remoteCollectors:
Expand Down
13 changes: 13 additions & 0 deletions config/crds/troubleshoot.sh_supportbundles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10351,6 +10351,19 @@ spec:
- image
- namespace
type: object
velero:
properties:
collectorName:
type: string
exclude:
type: BoolString
namespace:
type: string
timeout:
type: string
required:
- namespace
type: object
type: object
type: array
hostAnalyzers:
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ require (
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/tj/go-spin v1.1.0
github.com/vmware-tanzu/velero v1.11.1
go.opentelemetry.io/otel v1.18.0
go.opentelemetry.io/otel/sdk v1.18.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
golang.org/x/sync v0.3.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.28.2
Expand Down
11 changes: 5 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/14rcole/gopopulate v0.0.0-20180821133914-b175b219e774 h1:SCbEWT58NSt7d2mcFdvxC9uyrdcTfvBbPLThhkDmXzg=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 h1:EKPd1INOIyr5hWOWhvpmQpY6tKjeG0hT1s3AMC/9fic=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1/go.mod h1:VzwV+t+dZ9j/H867F1M2ziD+yLHtB46oM35FxxMJ4d0=
github.com/Azure/azure-sdk-for-go v56.3.0+incompatible h1:DmhwMrUIvpeoTDiWRDtNHqelNUd3Og8JCkrLHQK795c=
github.com/Azure/azure-sdk-for-go v67.2.0+incompatible h1:Uu/Ww6ernvPTrpq31kITVTIm/I5jlJ1wjtEH/bmSB2k=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1 h1:/iHxaJhsFr0+xVFfbMr5vxz848jyiWuIEDhYq3y5odY=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=
Expand Down Expand Up @@ -800,15 +800,12 @@ github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/nwaples/rardecode v1.1.2 h1:Cj0yZY6T1Zx1R7AhTbyGSALm44/Mmq+BAPc4B/p/d3M=
github.com/nwaples/rardecode v1.1.2/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
Expand Down Expand Up @@ -1001,6 +998,8 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vladimirvivien/gexe v0.2.0 h1:nbdAQ6vbZ+ZNsolCgSVb9Fno60kzSuvtzVh6Ytqi/xY=
github.com/vladimirvivien/gexe v0.2.0/go.mod h1:LHQL00w/7gDUKIak24n801ABp8C+ni6eBht9vGVst8w=
github.com/vmware-tanzu/velero v1.11.1 h1:Jw8P1DetGBhmAZQkMRFu2vBvJS0YOR85XfKNpe4BlV8=
github.com/vmware-tanzu/velero v1.11.1/go.mod h1:ZBLIZSSNb6VzCea+rwcMsixm8AvvxCm6j8UjGiPv7XY=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
19 changes: 19 additions & 0 deletions pkg/apis/troubleshoot/v1beta2/collector_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ type Longhorn struct {
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}

type Velero struct {
CollectorMeta `json:",inline" yaml:",inline"`
Namespace string `json:"namespace" yaml:"namespace"`
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}

type RegistryImages struct {
CollectorMeta `json:",inline" yaml:",inline"`
Images []string `json:"images" yaml:"images"`
Expand Down Expand Up @@ -279,6 +285,7 @@ type Collect struct {
Redis *Database `json:"redis,omitempty" yaml:"redis,omitempty"`
Collectd *Collectd `json:"collectd,omitempty" yaml:"collectd,omitempty"`
Ceph *Ceph `json:"ceph,omitempty" yaml:"ceph,omitempty"`
Velero *Velero `json:"velero,omitempty" yaml:"velero,omitempty"`
Longhorn *Longhorn `json:"longhorn,omitempty" yaml:"longhorn,omitempty"`
RegistryImages *RegistryImages `json:"registryImages,omitempty" yaml:"registryImages,omitempty"`
Sysctl *Sysctl `json:"sysctl,omitempty" yaml:"sysctl,omitempty"`
Expand Down Expand Up @@ -573,6 +580,10 @@ func (c *Collect) GetName() string {
collector = "ceph"
name = c.Ceph.CollectorName
}
if c.Velero != nil {
collector = "velero"
name = c.Velero.CollectorName
}
if c.Longhorn != nil {
collector = "longhorn"
name = c.Longhorn.CollectorName
Expand Down Expand Up @@ -628,3 +639,11 @@ func GetCollector(collector *Collect) interface{} {

return nil
}

func labelsToSelector(labels map[string]string) []string {
selector := []string{}
for key, value := range labels {
selector = append(selector, fmt.Sprintf("%s=%s", key, value))
}
return selector
}
27 changes: 0 additions & 27 deletions pkg/collect/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package collect
import (
"context"
"fmt"
"os"
"path"
"strings"

Expand Down Expand Up @@ -236,29 +235,3 @@ func GetCephCollectorFilepath(name, namespace string) string {
parts = append(parts, "ceph")
return path.Join(parts...)
}

func labelsToSelector(labels map[string]string) []string {
selector := []string{}
for key, value := range labels {
selector = append(selector, fmt.Sprintf("%s=%s", key, value))
}
return selector
}

func copyResult(srcResult CollectorResult, dstResult CollectorResult, bundlePath string, srcKey string, dstKey string) error {
reader, err := srcResult.GetReader(bundlePath, srcKey)
if err != nil {
if os.IsNotExist(errors.Cause(err)) {
return nil
}
return errors.Wrap(err, "failed to get reader")
}
defer reader.Close()

err = dstResult.SaveResult(bundlePath, dstKey, reader)
if err != nil {
return errors.Wrap(err, "failed to save file")
}

return nil
}
19 changes: 19 additions & 0 deletions pkg/collect/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -192,3 +193,21 @@ func CollectRemote(c *troubleshootv1beta2.RemoteCollector, additionalRedactors *
collectResult.AllCollectedData = allCollectedData
return collectResult, nil
}

func copyResult(srcResult CollectorResult, dstResult CollectorResult, bundlePath string, srcKey string, dstKey string) error {
reader, err := srcResult.GetReader(bundlePath, srcKey)
if err != nil {
if os.IsNotExist(errors.Cause(err)) {
return nil
}
return errors.Wrap(err, "failed to get reader")
}
defer reader.Close()

err = dstResult.SaveResult(bundlePath, dstKey, reader)
if err != nil {
return errors.Wrap(err, "failed to save file")
}

return nil
}
13 changes: 13 additions & 0 deletions pkg/collect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func GetCollector(collector *troubleshootv1beta2.Collect, bundlePath string, nam
return &CollectSysctl{collector.Sysctl, bundlePath, namespace, clientConfig, client, ctx, RBACErrors}, true
case collector.Certificates != nil:
return &CollectCertificates{collector.Certificates, bundlePath, namespace, clientConfig, client, ctx, RBACErrors}, true
case collector.Velero != nil:
return &CollectVelero{collector.Velero, bundlePath, namespace, clientConfig, client, ctx, RBACErrors}, true
case collector.Helm != nil:
return &CollectHelm{collector.Helm, bundlePath, namespace, clientConfig, client, ctx, RBACErrors}, true
default:
Expand Down Expand Up @@ -185,6 +187,9 @@ func getCollectorName(c interface{}) string {
case *CollectCeph:
collector = "ceph"
name = v.Collector.CollectorName
case *CollectVelero:
collector = "velero"
name = v.Collector.CollectorName
case *CollectLonghorn:
collector = "longhorn"
name = v.Collector.CollectorName
Expand Down Expand Up @@ -261,3 +266,11 @@ func DedupCollectors(allCollectors []*troubleshootv1beta2.Collect) []*troublesho
}
return finalCollectors
}

func labelsToSelector(labels map[string]string) []string {
selector := []string{}
for key, value := range labels {
selector = append(selector, fmt.Sprintf("%s=%s", key, value))
}
return selector
}
Loading

0 comments on commit 8988c4d

Please sign in to comment.