mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 18:29:53 +00:00
* chore(deps): bump the security group with 16 updates Bumps the security group with 16 updates: | Package | From | To | | --- | --- | --- | | [github.com/shirou/gopsutil/v4](https://github.com/shirou/gopsutil) | `4.25.7` | `4.25.8` | | [github.com/spf13/cobra](https://github.com/spf13/cobra) | `1.9.1` | `1.10.1` | | [github.com/spf13/pflag](https://github.com/spf13/pflag) | `1.0.7` | `1.0.9` | | [github.com/stretchr/testify](https://github.com/stretchr/testify) | `1.11.0` | `1.11.1` | | [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go) | `1.37.0` | `1.38.0` | | [go.opentelemetry.io/otel/sdk](https://github.com/open-telemetry/opentelemetry-go) | `1.37.0` | `1.38.0` | | [k8s.io/api](https://github.com/kubernetes/api) | `0.33.4` | `0.34.0` | | [k8s.io/apiextensions-apiserver](https://github.com/kubernetes/apiextensions-apiserver) | `0.33.4` | `0.34.0` | | [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) | `0.33.4` | `0.34.0` | | [k8s.io/apiserver](https://github.com/kubernetes/apiserver) | `0.33.4` | `0.34.0` | | [k8s.io/cli-runtime](https://github.com/kubernetes/cli-runtime) | `0.33.4` | `0.34.0` | | [k8s.io/client-go](https://github.com/kubernetes/client-go) | `0.33.4` | `0.34.0` | | [sigs.k8s.io/controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) | `0.21.0` | `0.22.0` | | [k8s.io/kubelet](https://github.com/kubernetes/kubelet) | `0.33.4` | `0.34.0` | | [k8s.io/metrics](https://github.com/kubernetes/metrics) | `0.33.4` | `0.34.0` | | [k8s.io/utils](https://github.com/kubernetes/utils) | `0.0.0-20241104100929-3ea5e8cea738` | `0.0.0-20250604170112-4c0f3b243397` | Updates `github.com/shirou/gopsutil/v4` from 4.25.7 to 4.25.8 - [Release notes](https://github.com/shirou/gopsutil/releases) - [Commits](https://github.com/shirou/gopsutil/compare/v4.25.7...v4.25.8) Updates `github.com/spf13/cobra` from 1.9.1 to 1.10.1 - [Release notes](https://github.com/spf13/cobra/releases) - [Commits](https://github.com/spf13/cobra/compare/v1.9.1...v1.10.1) Updates `github.com/spf13/pflag` from 1.0.7 to 1.0.9 - [Release notes](https://github.com/spf13/pflag/releases) - [Commits](https://github.com/spf13/pflag/compare/v1.0.7...v1.0.9) Updates `github.com/stretchr/testify` from 1.11.0 to 1.11.1 - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.11.0...v1.11.1) Updates `go.opentelemetry.io/otel` from 1.37.0 to 1.38.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.37.0...v1.38.0) Updates `go.opentelemetry.io/otel/sdk` from 1.37.0 to 1.38.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.37.0...v1.38.0) Updates `k8s.io/api` from 0.33.4 to 0.34.0 - [Commits](https://github.com/kubernetes/api/compare/v0.33.4...v0.34.0) Updates `k8s.io/apiextensions-apiserver` from 0.33.4 to 0.34.0 - [Release notes](https://github.com/kubernetes/apiextensions-apiserver/releases) - [Commits](https://github.com/kubernetes/apiextensions-apiserver/compare/v0.33.4...v0.34.0) Updates `k8s.io/apimachinery` from 0.33.4 to 0.34.0 - [Commits](https://github.com/kubernetes/apimachinery/compare/v0.33.4...v0.34.0) Updates `k8s.io/apiserver` from 0.33.4 to 0.34.0 - [Commits](https://github.com/kubernetes/apiserver/compare/v0.33.4...v0.34.0) Updates `k8s.io/cli-runtime` from 0.33.4 to 0.34.0 - [Commits](https://github.com/kubernetes/cli-runtime/compare/v0.33.4...v0.34.0) Updates `k8s.io/client-go` from 0.33.4 to 0.34.0 - [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md) - [Commits](https://github.com/kubernetes/client-go/compare/v0.33.4...v0.34.0) Updates `sigs.k8s.io/controller-runtime` from 0.21.0 to 0.22.0 - [Release notes](https://github.com/kubernetes-sigs/controller-runtime/releases) - [Changelog](https://github.com/kubernetes-sigs/controller-runtime/blob/main/RELEASE.md) - [Commits](https://github.com/kubernetes-sigs/controller-runtime/compare/v0.21.0...v0.22.0) Updates `k8s.io/kubelet` from 0.33.4 to 0.34.0 - [Commits](https://github.com/kubernetes/kubelet/compare/v0.33.4...v0.34.0) Updates `k8s.io/metrics` from 0.33.4 to 0.34.0 - [Commits](https://github.com/kubernetes/metrics/compare/v0.33.4...v0.34.0) Updates `k8s.io/utils` from 0.0.0-20241104100929-3ea5e8cea738 to 0.0.0-20250604170112-4c0f3b243397 - [Commits](https://github.com/kubernetes/utils/commits) --- updated-dependencies: - dependency-name: github.com/shirou/gopsutil/v4 dependency-version: 4.25.8 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: security - dependency-name: github.com/spf13/cobra dependency-version: 1.10.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: github.com/spf13/pflag dependency-version: 1.0.9 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: security - dependency-name: github.com/stretchr/testify dependency-version: 1.11.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: security - dependency-name: go.opentelemetry.io/otel dependency-version: 1.38.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: go.opentelemetry.io/otel/sdk dependency-version: 1.38.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/api dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/apiextensions-apiserver dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/apimachinery dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/apiserver dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/cli-runtime dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/client-go dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: sigs.k8s.io/controller-runtime dependency-version: 0.22.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/kubelet dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/metrics dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: k8s.io/utils dependency-version: 0.0.0-20250604170112-4c0f3b243397 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: security ... Signed-off-by: dependabot[bot] <support@github.com> * f * f * f --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
637 lines
16 KiB
Go
637 lines
16 KiB
Go
package loader
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/replicatedhq/troubleshoot/internal/testutils"
|
|
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func TestLoadingHelmTemplate_Succeeds(t *testing.T) {
|
|
s := testutils.GetTestFixture(t, "yamldocs/helm-template.yaml")
|
|
l := specLoader{}
|
|
kinds, err := l.loadFromStrings(s)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, kinds)
|
|
|
|
assert.Len(t, kinds.AnalyzersV1Beta2, 0)
|
|
assert.Len(t, kinds.CollectorsV1Beta2, 0)
|
|
assert.Len(t, kinds.HostCollectorsV1Beta2, 0)
|
|
assert.Len(t, kinds.HostPreflightsV1Beta2, 0)
|
|
assert.Len(t, kinds.RemoteCollectorsV1Beta2, 0)
|
|
require.Len(t, kinds.PreflightsV1Beta2, 2)
|
|
require.Len(t, kinds.RedactorsV1Beta2, 1)
|
|
require.Len(t, kinds.SupportBundlesV1Beta2, 3)
|
|
|
|
// Assert a few fields from the loaded troubleshoot specs
|
|
assert.Equal(t, "redactor-spec-1", kinds.RedactorsV1Beta2[0].ObjectMeta.Name)
|
|
assert.Equal(t, "REDACT SECOND TEXT PLEASE", kinds.RedactorsV1Beta2[0].Spec.Redactors[0].Removals.Values[0])
|
|
assert.Equal(t, "sb-spec-1", kinds.SupportBundlesV1Beta2[0].Name)
|
|
assert.Equal(t, "sb-spec-2", kinds.SupportBundlesV1Beta2[1].Name)
|
|
assert.Equal(t, "sb-spec-3", kinds.SupportBundlesV1Beta2[2].Name)
|
|
assert.Equal(t, false, kinds.SupportBundlesV1Beta2[0].Spec.RunHostCollectorsInPod)
|
|
assert.Equal(t, true, kinds.SupportBundlesV1Beta2[2].Spec.RunHostCollectorsInPod)
|
|
assert.Equal(t, "wg-easy", kinds.SupportBundlesV1Beta2[1].Spec.Collectors[0].Logs.CollectorName)
|
|
assert.Equal(t, "Node Count Check", kinds.PreflightsV1Beta2[0].Spec.Analyzers[0].NodeResources.CheckName)
|
|
assert.Len(t, kinds.PreflightsV1Beta2[0].Spec.Collectors, 0)
|
|
assert.Equal(t, true, kinds.PreflightsV1Beta2[1].Spec.Collectors[0].ClusterResources.IgnoreRBAC)
|
|
}
|
|
|
|
func TestLoadingRandomValidYaml_IgnoreDoc(t *testing.T) {
|
|
tests := []string{
|
|
"",
|
|
"---",
|
|
"configVersion: v1",
|
|
`
|
|
array:
|
|
- 1
|
|
- 2
|
|
`,
|
|
}
|
|
|
|
for _, ts := range tests {
|
|
ctx := context.Background()
|
|
kinds, err := LoadSpecs(ctx, LoadOptions{RawSpecs: []string{ts}})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, NewTroubleshootKinds(), kinds)
|
|
}
|
|
}
|
|
|
|
func TestLoadingInvalidYaml_ReturnError(t *testing.T) {
|
|
tests := []string{
|
|
"@",
|
|
"-",
|
|
`
|
|
array:- 1
|
|
- 2
|
|
`,
|
|
}
|
|
|
|
for _, ts := range tests {
|
|
t.Run(ts, func(t *testing.T) {
|
|
ctx := context.Background()
|
|
kinds, err := LoadSpecs(ctx, LoadOptions{RawSpec: ts, Strict: true})
|
|
assert.Error(t, err)
|
|
assert.Nil(t, kinds)
|
|
|
|
kinds, err = LoadSpecs(ctx, LoadOptions{RawSpec: ts, Strict: false})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, NewTroubleshootKinds(), kinds)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLoadingInvalidYaml_IgnoreDocs(t *testing.T) {
|
|
s := testutils.GetTestFixture(t, "yamldocs/multidoc-spec-with-invalids.yaml")
|
|
ctx := context.Background()
|
|
kinds, err := LoadSpecs(ctx, LoadOptions{RawSpec: s})
|
|
require.NoError(t, err)
|
|
require.NotNil(t, kinds)
|
|
|
|
assert.Equal(t, &TroubleshootKinds{
|
|
CollectorsV1Beta2: []troubleshootv1beta2.Collector{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Collector",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.CollectorSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterResources: &troubleshootv1beta2.ClusterResources{
|
|
CollectorMeta: troubleshootv1beta2.CollectorMeta{
|
|
CollectorName: "my-cluster-resources",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
SupportBundlesV1Beta2: []troubleshootv1beta2.SupportBundle{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.SupportBundleSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
Logs: &troubleshootv1beta2.Logs{
|
|
Name: "all-logs",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.SupportBundleSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterInfo: &troubleshootv1beta2.ClusterInfo{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
PreflightsV1Beta2: []troubleshootv1beta2.Preflight{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Preflight",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "preflight-1",
|
|
},
|
|
Spec: troubleshootv1beta2.PreflightSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterResources: &troubleshootv1beta2.ClusterResources{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Preflight",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "preflight-2",
|
|
},
|
|
Spec: troubleshootv1beta2.PreflightSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterResources: &troubleshootv1beta2.ClusterResources{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds)
|
|
}
|
|
|
|
func TestLoadingMultidocsWithTroubleshootSpecs(t *testing.T) {
|
|
s := testutils.GetTestFixture(t, "yamldocs/multidoc-spec-1.yaml")
|
|
ctx := context.Background()
|
|
kinds, err := LoadSpecs(ctx, LoadOptions{RawSpec: s})
|
|
require.NoError(t, err)
|
|
require.NotNil(t, kinds)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.Analyzer{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Analyzer",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.AnalyzerSpec{
|
|
Analyzers: []*troubleshootv1beta2.Analyze{
|
|
{
|
|
ClusterVersion: &troubleshootv1beta2.ClusterVersion{},
|
|
},
|
|
},
|
|
HostAnalyzers: []*troubleshootv1beta2.HostAnalyze{
|
|
{
|
|
TCPLoadBalancer: &troubleshootv1beta2.TCPLoadBalancerAnalyze{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.AnalyzersV1Beta2)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.Collector{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Collector",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.CollectorSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterResources: &troubleshootv1beta2.ClusterResources{
|
|
CollectorMeta: troubleshootv1beta2.CollectorMeta{
|
|
CollectorName: "my-cluster-resources",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.CollectorsV1Beta2)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.HostCollector{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "HostCollector",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "my-host-collector",
|
|
},
|
|
Spec: troubleshootv1beta2.HostCollectorSpec{
|
|
Collectors: []*troubleshootv1beta2.HostCollect{
|
|
{
|
|
CPU: &troubleshootv1beta2.CPU{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.HostCollectorsV1Beta2)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.HostPreflight{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "HostPreflight",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.HostPreflightSpec{
|
|
RemoteCollectors: []*troubleshootv1beta2.RemoteCollect{
|
|
{
|
|
Certificate: &troubleshootv1beta2.RemoteCertificate{
|
|
CertificatePath: "/etc/ssl/corp.crt",
|
|
KeyPath: "/etc/ssl/corp.key",
|
|
},
|
|
},
|
|
},
|
|
Analyzers: []*troubleshootv1beta2.HostAnalyze{
|
|
{
|
|
Certificate: &troubleshootv1beta2.CertificateAnalyze{
|
|
Outcomes: []*troubleshootv1beta2.Outcome{
|
|
{
|
|
Pass: &troubleshootv1beta2.SingleOutcome{
|
|
Message: "Certificate key pair is valid",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.HostPreflightsV1Beta2)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.Preflight{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Preflight",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.PreflightSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
Data: &troubleshootv1beta2.Data{
|
|
Data: "5",
|
|
},
|
|
},
|
|
},
|
|
Analyzers: []*troubleshootv1beta2.Analyze{
|
|
{
|
|
ClusterVersion: &troubleshootv1beta2.ClusterVersion{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.PreflightsV1Beta2)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.Redactor{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Redactor",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.RedactorSpec{
|
|
Redactors: []*troubleshootv1beta2.Redact{
|
|
{
|
|
Name: "replace password",
|
|
FileSelector: troubleshootv1beta2.FileSelector{
|
|
File: "data/my-password-dump",
|
|
},
|
|
Removals: troubleshootv1beta2.Removals{
|
|
Values: []string{"abc123"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.RedactorsV1Beta2)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.RemoteCollector{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "RemoteCollector",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "certificate",
|
|
},
|
|
Spec: troubleshootv1beta2.RemoteCollectorSpec{
|
|
Collectors: []*troubleshootv1beta2.RemoteCollect{
|
|
{
|
|
CPU: &troubleshootv1beta2.RemoteCPU{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.RemoteCollectorsV1Beta2)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.SupportBundle{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "my-support-bundle",
|
|
},
|
|
Spec: troubleshootv1beta2.SupportBundleSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
Logs: &troubleshootv1beta2.Logs{
|
|
Name: "all-logs",
|
|
},
|
|
},
|
|
},
|
|
HostCollectors: []*troubleshootv1beta2.HostCollect{
|
|
{
|
|
HostOS: &troubleshootv1beta2.HostOS{},
|
|
},
|
|
},
|
|
Analyzers: []*troubleshootv1beta2.Analyze{
|
|
{
|
|
ClusterVersion: &troubleshootv1beta2.ClusterVersion{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.SupportBundlesV1Beta2)
|
|
}
|
|
|
|
func TestLoadingV1Beta1CollectorSpec(t *testing.T) {
|
|
kinds, err := LoadSpecs(context.Background(), LoadOptions{RawSpec: `kind: Collector
|
|
apiVersion: troubleshoot.replicated.com/v1beta1
|
|
metadata:
|
|
name: collector-sample
|
|
spec:
|
|
collectors:
|
|
- clusterInfo: {}
|
|
`})
|
|
require.NoError(t, err)
|
|
require.NotNil(t, kinds)
|
|
|
|
assert.Equal(t, []troubleshootv1beta2.Collector{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Collector",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "collector-sample",
|
|
},
|
|
Spec: troubleshootv1beta2.CollectorSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterInfo: &troubleshootv1beta2.ClusterInfo{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds.CollectorsV1Beta2)
|
|
}
|
|
|
|
func TestLoadingConfigMapWithMultipleSpecs_PreflightSupportBundleAndRedactorDataKeys(t *testing.T) {
|
|
s := testutils.GetTestFixture(t, "yamldocs/multidoc-spec-2.yaml")
|
|
l := specLoader{}
|
|
kinds, err := l.loadFromStrings(s)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, kinds)
|
|
|
|
assert.Equal(t, &TroubleshootKinds{
|
|
SupportBundlesV1Beta2: []troubleshootv1beta2.SupportBundle{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.SupportBundleSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
Logs: &troubleshootv1beta2.Logs{
|
|
Name: "all-logs",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
RedactorsV1Beta2: []troubleshootv1beta2.Redactor{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Redactor",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.RedactorSpec{
|
|
Redactors: []*troubleshootv1beta2.Redact{
|
|
{
|
|
Name: "redact-text-1",
|
|
Removals: troubleshootv1beta2.Removals{
|
|
Values: []string{"abc123"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
PreflightsV1Beta2: []troubleshootv1beta2.Preflight{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Preflight",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.PreflightSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterResources: &troubleshootv1beta2.ClusterResources{
|
|
IgnoreRBAC: true,
|
|
},
|
|
},
|
|
},
|
|
Analyzers: []*troubleshootv1beta2.Analyze{
|
|
{
|
|
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
|
|
Outcomes: []*troubleshootv1beta2.Outcome{
|
|
{
|
|
Pass: &troubleshootv1beta2.SingleOutcome{
|
|
Message: "Cluster is up to date",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds)
|
|
}
|
|
|
|
func TestLoadingConfigMapWithMultipleSpecs_SupportBundleMultidoc(t *testing.T) {
|
|
s := testutils.GetTestFixture(t, "yamldocs/multidoc-spec-3.yaml")
|
|
l := specLoader{}
|
|
kinds, err := l.loadFromStrings(s)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, kinds)
|
|
|
|
assert.Equal(t, &TroubleshootKinds{
|
|
SupportBundlesV1Beta2: []troubleshootv1beta2.SupportBundle{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.SupportBundleSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
Logs: &troubleshootv1beta2.Logs{
|
|
Name: "all-logs",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.SupportBundleSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterResources: &troubleshootv1beta2.ClusterResources{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.SupportBundleSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterInfo: &troubleshootv1beta2.ClusterInfo{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, kinds)
|
|
}
|
|
|
|
func TestKindsIsEmpty(t *testing.T) {
|
|
assert.True(t, NewTroubleshootKinds().IsEmpty())
|
|
kinds := NewTroubleshootKinds()
|
|
kinds.AnalyzersV1Beta2 = append(kinds.AnalyzersV1Beta2, troubleshootv1beta2.Analyzer{})
|
|
assert.False(t, kinds.IsEmpty())
|
|
}
|
|
|
|
func TestAddingKinds(t *testing.T) {
|
|
a := troubleshootv1beta2.Analyzer{
|
|
Spec: troubleshootv1beta2.AnalyzerSpec{},
|
|
}
|
|
k1 := NewTroubleshootKinds()
|
|
k1.Add(&TroubleshootKinds{
|
|
AnalyzersV1Beta2: []troubleshootv1beta2.Analyzer{a},
|
|
})
|
|
|
|
k2 := &TroubleshootKinds{
|
|
AnalyzersV1Beta2: []troubleshootv1beta2.Analyzer{a},
|
|
}
|
|
assert.Equal(t, k2, k1)
|
|
}
|
|
|
|
func TestToYaml(t *testing.T) {
|
|
k := &TroubleshootKinds{
|
|
AnalyzersV1Beta2: []troubleshootv1beta2.Analyzer{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "Analyzer",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.AnalyzerSpec{
|
|
Analyzers: []*troubleshootv1beta2.Analyze{
|
|
{
|
|
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
|
|
Outcomes: []*troubleshootv1beta2.Outcome{
|
|
{
|
|
Pass: &troubleshootv1beta2.SingleOutcome{
|
|
Message: "Cluster is up to date",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
SupportBundlesV1Beta2: []troubleshootv1beta2.SupportBundle{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
Spec: troubleshootv1beta2.SupportBundleSpec{
|
|
Collectors: []*troubleshootv1beta2.Collect{
|
|
{
|
|
ClusterResources: &troubleshootv1beta2.ClusterResources{
|
|
IgnoreRBAC: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
y, err := k.ToYaml()
|
|
require.NoError(t, err)
|
|
assert.Contains(t, string(y), `apiVersion: troubleshoot.sh/v1beta2
|
|
kind: SupportBundle
|
|
metadata: {}
|
|
spec:
|
|
collectors:
|
|
- clusterResources:
|
|
ignoreRBAC: true`)
|
|
assert.Contains(t, string(y), "message: Cluster is up to date")
|
|
}
|
|
|
|
func TestLoadingEmptySpec(t *testing.T) {
|
|
s := testutils.GetTestFixture(t, "supportbundle/empty.yaml")
|
|
kinds, err := LoadSpecs(context.Background(), LoadOptions{RawSpec: s})
|
|
require.NoError(t, err)
|
|
require.NotNil(t, kinds)
|
|
|
|
assert.Equal(t, &TroubleshootKinds{
|
|
SupportBundlesV1Beta2: []troubleshootv1beta2.SupportBundle{
|
|
{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "SupportBundle",
|
|
APIVersion: "troubleshoot.sh/v1beta2",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "empty",
|
|
},
|
|
},
|
|
},
|
|
}, kinds)
|
|
}
|