Skip to content

Commit

Permalink
Include Support Bundle (#2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-cool-train authored May 6, 2022
1 parent b37b0f2 commit 563187d
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/diagnostics/analyzers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ func (a *analyzerFactory) managementClusterCrdAnalyzers() []*Analyze {
return a.generateCrdAnalyzers(crds)
}

func (a *analyzerFactory) PackageAnalyzers() []*Analyze {
var analyzers []*Analyze
analyzers = append(analyzers, a.packageDeploymentAnalyzers()...)
return append(analyzers, a.packageCrdAnalyzers()...)
}

func (a *analyzerFactory) packageCrdAnalyzers() []*Analyze {
crds := []string{
"packagebundlecontrollers.packages.eks.amazonaws.com",
"packagebundles.packages.eks.amazonaws.com",
"packagecontrollers.packages.eks.amazonaws.com",
"packages.packages.eks.amazonaws.com",
}
return a.generateCrdAnalyzers(crds)
}

func (a *analyzerFactory) packageDeploymentAnalyzers() []*Analyze {
d := []eksaDeployment{
{
Name: "eks-anywhere-packages",
Namespace: constants.EksaPackagesName,
ExpectedReplicas: 1,
},
}
return a.generateDeploymentAnalyzers(d)
}

func (a *analyzerFactory) managementClusterDeploymentAnalyzers() []*Analyze {
d := []eksaDeployment{
{
Expand Down
28 changes: 28 additions & 0 deletions pkg/diagnostics/collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func (c *collectorFactory) ManagementClusterCollectors() []*Collect {
return collectors
}

func (c *collectorFactory) PackagesCollectors() []*Collect {
var collectors []*Collect
collectors = append(collectors, c.packagesCrdCollectors()...)
collectors = append(collectors, c.packagesLogCollectors()...)
return collectors
}

func (c *collectorFactory) getCollectorsMap() map[v1alpha1.OSFamily][]*Collect {
return map[v1alpha1.OSFamily][]*Collect{
v1alpha1.Ubuntu: c.ubuntuHostCollectors(),
Expand Down Expand Up @@ -176,6 +183,17 @@ func (c *collectorFactory) defaultLogCollectors() []*Collect {
}
}

func (c *collectorFactory) packagesLogCollectors() []*Collect {
return []*Collect{
{
Logs: &logs{
Namespace: constants.EksaPackagesName,
Name: logpath(constants.EksaPackagesName),
},
},
}
}

func (c *collectorFactory) managementClusterLogCollectors() []*Collect {
return []*Collect{
{
Expand Down Expand Up @@ -249,6 +267,16 @@ func (c *collectorFactory) vsphereCrdCollectors() []*Collect {
return c.generateCrdCollectors(capvCrds)
}

func (c *collectorFactory) packagesCrdCollectors() []*Collect {
packageCrds := []string{
"packagebundlecontrollers.packages.eks.amazonaws.com",
"packagebundles.packages.eks.amazonaws.com",
"packagecontrollers.packages.eks.amazonaws.com",
"packages.packages.eks.amazonaws.com",
}
return c.generateCrdCollectors(packageCrds)
}

func (c *collectorFactory) generateCrdCollectors(crds []string) []*Collect {
var crdCollectors []*Collect
for _, d := range crds {
Expand Down
1 change: 1 addition & 0 deletions pkg/diagnostics/config/diagnostic-collector-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rules:
- infrastructure.cluster.x-k8s.io
- controlplane.cluster.x-k8s.io
- anywhere.eks.amazonaws.com
- packages.eks.amazonaws.com
resources:
- '*'
verbs:
Expand Down
7 changes: 7 additions & 0 deletions pkg/diagnostics/diagnostic_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func newDiagnosticBundleFromSpec(af AnalyzerFactory, cf CollectorFactory, spec *
WithManagementCluster(spec.Cluster.IsSelfManaged()).
WithDefaultAnalyzers().
WithDefaultCollectors().
WithPackagesCollectors().
WithLogTextAnalyzers()

err := b.WriteBundleConfig()
Expand Down Expand Up @@ -255,6 +256,12 @@ func (e *EksaDiagnosticBundle) WithManagementCluster(isSelfManaged bool) *EksaDi
return e
}

func (e *EksaDiagnosticBundle) WithPackagesCollectors() *EksaDiagnosticBundle {
e.bundle.Spec.Analyzers = append(e.bundle.Spec.Analyzers, e.analyzerFactory.PackageAnalyzers()...)
e.bundle.Spec.Collectors = append(e.bundle.Spec.Collectors, e.collectorFactory.PackagesCollectors()...)
return e
}

func (e *EksaDiagnosticBundle) WithDatacenterConfig(config v1alpha1.Ref) *EksaDiagnosticBundle {
e.bundle.Spec.Analyzers = append(e.bundle.Spec.Analyzers, e.analyzerFactory.DataCenterConfigAnalyzers(config)...)
e.bundle.Spec.Collectors = append(e.bundle.Spec.Collectors, e.collectorFactory.DataCenterConfigCollectors(config)...)
Expand Down
8 changes: 8 additions & 0 deletions pkg/diagnostics/diagnostic_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ func TestGenerateBundleConfigWithExternalEtcd(t *testing.T) {
a.EXPECT().DefaultAnalyzers().Return(nil)
a.EXPECT().EksaLogTextAnalyzers(gomock.Any()).Return(nil)
a.EXPECT().ManagementClusterAnalyzers().Return(nil)
a.EXPECT().PackageAnalyzers().Return(nil)

c := givenMockCollectorsFactory(t)
c.EXPECT().DefaultCollectors().Return(nil)
c.EXPECT().EksaHostCollectors(gomock.Any()).Return(nil)
c.EXPECT().ManagementClusterCollectors().Return(nil)
c.EXPECT().DataCenterConfigCollectors(spec.Cluster.Spec.DatacenterRef).Return(nil)
c.EXPECT().PackagesCollectors().Return(nil)

w := givenWriter(t)
w.EXPECT().Write(gomock.Any(), gomock.Any())
Expand Down Expand Up @@ -168,6 +170,7 @@ func TestGenerateBundleConfigWithOidc(t *testing.T) {
a.EXPECT().DefaultAnalyzers().Return(nil)
a.EXPECT().EksaLogTextAnalyzers(gomock.Any()).Return(nil)
a.EXPECT().ManagementClusterAnalyzers().Return(nil)
a.EXPECT().PackageAnalyzers().Return(nil)

w := givenWriter(t)
w.EXPECT().Write(gomock.Any(), gomock.Any())
Expand All @@ -177,6 +180,7 @@ func TestGenerateBundleConfigWithOidc(t *testing.T) {
c.EXPECT().EksaHostCollectors(gomock.Any()).Return(nil)
c.EXPECT().ManagementClusterCollectors().Return(nil)
c.EXPECT().DataCenterConfigCollectors(spec.Cluster.Spec.DatacenterRef).Return(nil)
c.EXPECT().PackagesCollectors().Return(nil)

opts := diagnostics.EksaDiagnosticBundleFactoryOpts{
AnalyzerFactory: a,
Expand Down Expand Up @@ -220,6 +224,7 @@ func TestGenerateBundleConfigWithGitOps(t *testing.T) {
a.EXPECT().DefaultAnalyzers().Return(nil)
a.EXPECT().EksaLogTextAnalyzers(gomock.Any()).Return(nil)
a.EXPECT().ManagementClusterAnalyzers().Return(nil)
a.EXPECT().PackageAnalyzers().Return(nil)

w := givenWriter(t)
w.EXPECT().Write(gomock.Any(), gomock.Any())
Expand All @@ -229,6 +234,7 @@ func TestGenerateBundleConfigWithGitOps(t *testing.T) {
c.EXPECT().EksaHostCollectors(gomock.Any()).Return(nil)
c.EXPECT().ManagementClusterCollectors().Return(nil)
c.EXPECT().DataCenterConfigCollectors(spec.Cluster.Spec.DatacenterRef).Return(nil)
c.EXPECT().PackagesCollectors().Return(nil)

opts := diagnostics.EksaDiagnosticBundleFactoryOpts{
AnalyzerFactory: a,
Expand Down Expand Up @@ -299,12 +305,14 @@ func TestBundleFromSpecComplete(t *testing.T) {
a.EXPECT().DefaultAnalyzers().Return(nil)
a.EXPECT().EksaLogTextAnalyzers(gomock.Any()).Return(nil)
a.EXPECT().ManagementClusterAnalyzers().Return(nil)
a.EXPECT().PackageAnalyzers().Return(nil)

c := givenMockCollectorsFactory(t)
c.EXPECT().DefaultCollectors().Return(nil)
c.EXPECT().EksaHostCollectors(gomock.Any()).Return(nil)
c.EXPECT().ManagementClusterCollectors().Return(nil)
c.EXPECT().DataCenterConfigCollectors(spec.Cluster.Spec.DatacenterRef).Return(nil)
c.EXPECT().PackagesCollectors().Return(nil)

w := givenWriter(t)
w.EXPECT().Write(gomock.Any(), gomock.Any()).Times(2)
Expand Down
2 changes: 2 additions & 0 deletions pkg/diagnostics/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ type AnalyzerFactory interface {
EksaExternalEtcdAnalyzers() []*Analyze
DataCenterConfigAnalyzers(datacenter v1alpha1.Ref) []*Analyze
ManagementClusterAnalyzers() []*Analyze
PackageAnalyzers() []*Analyze
}

type CollectorFactory interface {
PackagesCollectors() []*Collect
DefaultCollectors() []*Collect
ManagementClusterCollectors() []*Collect
EksaHostCollectors(configs []providers.MachineConfig) []*Collect
Expand Down
28 changes: 28 additions & 0 deletions pkg/diagnostics/interfaces/mocks/diagnostics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 563187d

Please sign in to comment.