Skip to content

Commit

Permalink
Adding provider specific collectors/analyzers to management cluster s…
Browse files Browse the repository at this point in the history
…upport bundle (#2201)

* Adding capc analyzer to support bundle

* Refactoring support bundle generation
  • Loading branch information
maxdrib authored May 20, 2022
1 parent 6a70bca commit 2554fd7
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/generatebundleconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ func (gsbo *generateSupportBundleOptions) generateBundleConfig(ctx context.Conte
}
defer close(ctx, deps)

return deps.DignosticCollectorFactory.DiagnosticBundleFromSpec(clusterSpec, deps.Provider, kubeconfig.FromClusterName(clusterSpec.Cluster.Name))
return deps.DignosticCollectorFactory.DiagnosticBundleWorkloadCluster(clusterSpec, deps.Provider, kubeconfig.FromClusterName(clusterSpec.Cluster.Name))
}
8 changes: 4 additions & 4 deletions pkg/clustermanager/cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func (c *ClusterManager) generateAwsIamAuthKubeconfig(ctx context.Context, manag
return nil
}

func (c *ClusterManager) SaveLogsManagementCluster(ctx context.Context, cluster *types.Cluster) error {
func (c *ClusterManager) SaveLogsManagementCluster(ctx context.Context, spec *cluster.Spec, cluster *types.Cluster) error {
if cluster == nil {
return nil
}
Expand All @@ -643,9 +643,9 @@ func (c *ClusterManager) SaveLogsManagementCluster(ctx context.Context, cluster
return nil
}

bundle, err := c.diagnosticsFactory.DiagnosticBundleManagementCluster(cluster.KubeconfigFile)
bundle, err := c.diagnosticsFactory.DiagnosticBundleManagementCluster(spec, cluster.KubeconfigFile)
if err != nil {
logger.V(5).Info("Error generating support bundle for bootstrap cluster", "error", err)
logger.V(5).Info("Error generating support bundle for management cluster", "error", err)
return nil
}
return collectDiagnosticBundle(ctx, bundle)
Expand All @@ -660,7 +660,7 @@ func (c *ClusterManager) SaveLogsWorkloadCluster(ctx context.Context, provider p
return nil
}

bundle, err := c.diagnosticsFactory.DiagnosticBundleFromSpec(spec, provider, cluster.KubeconfigFile)
bundle, err := c.diagnosticsFactory.DiagnosticBundleWorkloadCluster(spec, provider, cluster.KubeconfigFile)
if err != nil {
logger.V(5).Info("Error generating support bundle for workload cluster", "error", err)
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/clustermanager/cluster_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ func TestClusterManagerSaveLogsSuccess(t *testing.T) {
c, m := newClusterManager(t)

b := m.diagnosticsBundle
m.diagnosticsFactory.EXPECT().DiagnosticBundleManagementCluster(bootstrapCluster.KubeconfigFile).Return(b, nil)
m.diagnosticsFactory.EXPECT().DiagnosticBundleManagementCluster(clusterSpec, bootstrapCluster.KubeconfigFile).Return(b, nil)
b.EXPECT().CollectAndAnalyze(ctx, gomock.AssignableToTypeOf(&time.Time{}))

m.diagnosticsFactory.EXPECT().DiagnosticBundleFromSpec(clusterSpec, m.provider, workloadCluster.KubeconfigFile).Return(b, nil)
m.diagnosticsFactory.EXPECT().DiagnosticBundleWorkloadCluster(clusterSpec, m.provider, workloadCluster.KubeconfigFile).Return(b, nil)
b.EXPECT().CollectAndAnalyze(ctx, gomock.AssignableToTypeOf(&time.Time{}))

if err := c.SaveLogsManagementCluster(ctx, bootstrapCluster); err != nil {
if err := c.SaveLogsManagementCluster(ctx, clusterSpec, bootstrapCluster); err != nil {
t.Errorf("ClusterManager.SaveLogsManagementCluster() error = %v, wantErr nil", err)
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/diagnostics/analyzers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (a *analyzerFactory) managementClusterDeploymentAnalyzers() []*Analyze {
Name: "capv-controller-manager",
Namespace: constants.CapvSystemNamespace,
ExpectedReplicas: 1,
}, {
Name: "capc-controller-manager",
Namespace: constants.CapcSystemNamespace,
ExpectedReplicas: 1,
}, {
Name: "cert-manager-webhook",
Namespace: constants.CertManagerNamespace,
Expand Down
27 changes: 27 additions & 0 deletions pkg/diagnostics/analyzers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package diagnostics_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/aws/eks-anywhere/pkg/diagnostics"
)

func TestManagementClusterAnalyzers(t *testing.T) {
factory := diagnostics.NewAnalyzerFactory()
analyzers := factory.ManagementClusterAnalyzers()
assert.Equal(t, len(analyzers), 11, "DataCenterConfigCollectors() mismatch between desired collectors and actual")
assert.NotNilf(t, getDeploymentStatusAnalyzer(analyzers, "capc-controller-manager"), "capc controller manager analyzer should be present")
assert.NotNilf(t, getDeploymentStatusAnalyzer(analyzers, "capv-controller-manager"), "capv controller manager analyzer should be present")
}

func getDeploymentStatusAnalyzer(analyzers []*diagnostics.Analyze, name string) *diagnostics.Analyze {
for _, analyzer := range analyzers {
if analyzer.DeploymentStatus != nil && analyzer.DeploymentStatus.Name == name {
return analyzer
}
}

return nil
}
4 changes: 2 additions & 2 deletions pkg/diagnostics/diagnostic_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type EksaDiagnosticBundle struct {
analysis []*executables.SupportBundleAnalysis
}

func newDiagnosticBundleManagementCluster(af AnalyzerFactory, cf CollectorFactory, client BundleClient,
func newDiagnosticBundleManagementCluster(af AnalyzerFactory, cf CollectorFactory, spec *cluster.Spec, client BundleClient,
kubectl *executables.Kubectl, kubeconfig string, writer filewriter.FileWriter,
) (*EksaDiagnosticBundle, error) {
b := &EksaDiagnosticBundle{
Expand All @@ -69,7 +69,7 @@ func newDiagnosticBundleManagementCluster(af AnalyzerFactory, cf CollectorFactor
writer: writer,
}

b.WithDefaultCollectors().WithDefaultAnalyzers().WithManagementCluster(true)
b.WithDefaultCollectors().WithDefaultAnalyzers().WithManagementCluster(true).WithDatacenterConfig(spec.Cluster.Spec.DatacenterRef)

err := b.WriteBundleConfig()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/diagnostics/diagnostic_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestGenerateBundleConfigWithExternalEtcd(t *testing.T) {
}

f := diagnostics.NewFactory(opts)
_, _ = f.DiagnosticBundleFromSpec(spec, p, "")
_, _ = f.DiagnosticBundleWorkloadCluster(spec, p, "")
})
}

Expand Down Expand Up @@ -189,7 +189,7 @@ func TestGenerateBundleConfigWithOidc(t *testing.T) {
}

f := diagnostics.NewFactory(opts)
_, _ = f.DiagnosticBundleFromSpec(spec, p, "")
_, _ = f.DiagnosticBundleWorkloadCluster(spec, p, "")
})
}

Expand Down Expand Up @@ -243,7 +243,7 @@ func TestGenerateBundleConfigWithGitOps(t *testing.T) {
}

f := diagnostics.NewFactory(opts)
_, _ = f.DiagnosticBundleFromSpec(spec, p, "")
_, _ = f.DiagnosticBundleWorkloadCluster(spec, p, "")
})
}

Expand Down Expand Up @@ -362,7 +362,7 @@ func TestBundleFromSpecComplete(t *testing.T) {
}

f := diagnostics.NewFactory(opts)
b, _ := f.DiagnosticBundleFromSpec(spec, p, kubeconfig)
b, _ := f.DiagnosticBundleWorkloadCluster(spec, p, kubeconfig)
err = b.CollectAndAnalyze(ctx, sinceTimeValue)
if err != nil {
t.Errorf("CollectAndAnalyze() error = %v, wantErr nil", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/diagnostics/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ func NewFactory(opts EksaDiagnosticBundleFactoryOpts) *eksaDiagnosticBundleFacto

func (f *eksaDiagnosticBundleFactory) DiagnosticBundle(spec *cluster.Spec, provider providers.Provider, kubeconfig string, bundlePath string) (DiagnosticBundle, error) {
if bundlePath == "" && spec != nil {
b, err := f.DiagnosticBundleFromSpec(spec, provider, kubeconfig)
b, err := f.DiagnosticBundleWorkloadCluster(spec, provider, kubeconfig)
return b, err
}
return f.DiagnosticBundleCustom(kubeconfig, bundlePath), nil
}

func (f *eksaDiagnosticBundleFactory) DiagnosticBundleManagementCluster(kubeconfig string) (DiagnosticBundle, error) {
return newDiagnosticBundleManagementCluster(f.analyzerFactory, f.collectorFactory, f.client, f.kubectl, kubeconfig, f.writer)
func (f *eksaDiagnosticBundleFactory) DiagnosticBundleManagementCluster(spec *cluster.Spec, kubeconfig string) (DiagnosticBundle, error) {
return newDiagnosticBundleManagementCluster(f.analyzerFactory, f.collectorFactory, spec, f.client, f.kubectl, kubeconfig, f.writer)
}

func (f *eksaDiagnosticBundleFactory) DiagnosticBundleFromSpec(spec *cluster.Spec, provider providers.Provider, kubeconfig string) (DiagnosticBundle, error) {
func (f *eksaDiagnosticBundleFactory) DiagnosticBundleWorkloadCluster(spec *cluster.Spec, provider providers.Provider, kubeconfig string) (DiagnosticBundle, error) {
return newDiagnosticBundleFromSpec(f.analyzerFactory, f.collectorFactory, spec, provider, f.client, f.kubectl, kubeconfig, f.writer)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/diagnostics/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type BundleClient interface {

type DiagnosticBundleFactory interface {
DiagnosticBundle(spec *cluster.Spec, provider providers.Provider, kubeconfig string, bundlePath string) (DiagnosticBundle, error)
DiagnosticBundleFromSpec(spec *cluster.Spec, provider providers.Provider, kubeconfig string) (DiagnosticBundle, error)
DiagnosticBundleManagementCluster(kubeconfig string) (DiagnosticBundle, error)
DiagnosticBundleWorkloadCluster(spec *cluster.Spec, provider providers.Provider, kubeconfig string) (DiagnosticBundle, error)
DiagnosticBundleManagementCluster(spec *cluster.Spec, kubeconfig string) (DiagnosticBundle, error)
DiagnosticBundleDefault() DiagnosticBundle
DiagnosticBundleCustom(kubeconfig string, bundlePath string) DiagnosticBundle
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/diagnostics/interfaces/mocks/diagnostics.go

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

2 changes: 1 addition & 1 deletion pkg/workflows/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *CollectWorkloadClusterDiagnosticsTask) Name() string {

func (s *CollectMgmtClusterDiagnosticsTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task {
logger.Info("collecting management cluster diagnostics")
_ = commandContext.ClusterManager.SaveLogsManagementCluster(ctx, commandContext.BootstrapCluster)
_ = commandContext.ClusterManager.SaveLogsManagementCluster(ctx, commandContext.ClusterSpec, commandContext.BootstrapCluster)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/workflows/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ClusterManager interface {
InstallNetworking(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec, provider providers.Provider) error
UpgradeNetworking(ctx context.Context, cluster *types.Cluster, currentSpec, newSpec *cluster.Spec, provider providers.Provider) (*types.ChangeDiff, error)
InstallStorageClass(ctx context.Context, cluster *types.Cluster, provider providers.Provider) error
SaveLogsManagementCluster(ctx context.Context, cluster *types.Cluster) error
SaveLogsManagementCluster(ctx context.Context, spec *cluster.Spec, cluster *types.Cluster) error
SaveLogsWorkloadCluster(ctx context.Context, provider providers.Provider, spec *cluster.Spec, cluster *types.Cluster) error
InstallCustomComponents(ctx context.Context, clusterSpec *cluster.Spec, cluster *types.Cluster, provider providers.Provider) error
CreateEKSAResources(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec, datacenterConfig providers.DatacenterConfig, machineConfigs []providers.MachineConfig) error
Expand Down
8 changes: 4 additions & 4 deletions pkg/workflows/interfaces/mocks/clients.go

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

2 changes: 1 addition & 1 deletion pkg/workflows/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (c *upgradeTestSetup) expectVerifyClusterSpecChanged(expectedCluster *types

func (c *upgradeTestSetup) expectSaveLogs(expectedWorkloadCluster *types.Cluster) {
gomock.InOrder(
c.clusterManager.EXPECT().SaveLogsManagementCluster(c.ctx, c.bootstrapCluster).Return(nil),
c.clusterManager.EXPECT().SaveLogsManagementCluster(c.ctx, c.newClusterSpec, c.bootstrapCluster).Return(nil),
c.clusterManager.EXPECT().SaveLogsWorkloadCluster(c.ctx, c.provider, c.newClusterSpec, expectedWorkloadCluster),
)
}
Expand Down

0 comments on commit 2554fd7

Please sign in to comment.