k8sreporter

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2023 License: Apache-2.0 Imports: 20 Imported by: 5

README

Kubernetes Reporter

This is a small library to produce a readeable dump of the required information contained in a k8s cluster.

The idea is to use it after an end to end test failure, to collect information useful for the failure.

Usage

Init the reporter with the information about namespaces and the resources that requires to be dumped:

 // When using custom crds, we need to add them to the scheme
 addToScheme := func(s *runtime.Scheme) error {
  err := sriovv1.AddToScheme(s)
  if err != nil {
   return err
  }
  err = metallbv1beta1.AddToScheme(s)
  if err != nil {
   return err
  }
  return nil
 }

  // The namespaces we want to dump resources for (including pods and pod logs)
  dumpNamespace := func(ns string) bool {
      if strings.HasPrefix(ns, "test") {
          return true
      }
      return false
  }

 // The list of CRDs we want to dump
 crds := []k8sreporter.CRData{
  {Cr: &sriovv1.SriovNetworkNodePolicyList{}},
  {Cr: &sriovv1.SriovNetworkList{}},
  {Cr: &sriovv1.SriovNetworkNodePolicyList{}},
  {Cr: &sriovv1.SriovOperatorConfigList{}},
  {Cr: &metallbv1beta1.MetalLBList{}},
 }

Create the reporter and invoke dump (note reportbase must exists):

 reporter, err := k8sreporter.New(*kubeconfig, addToScheme, dumpNamespace, "/reportbase", crds...)
 if err != nil {
  log.Fatalf("Failed to initialize the reporter %s", err)
 }
 reporter.Dump(10*time.Minute, "nameofthetest")

The output will look like

├── reportbase
│   └── test
│       ├── crs.log
│       ├── metallb-system-pods_logs.log
│       ├── metallb-system-pods_specs.log
│       └── nodes.log

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddToScheme

type AddToScheme func(*runtime.Scheme) error

AddToScheme is a function for extend the reporter scheme and the CRs we are able to dump

type CRData

type CRData struct {
	Cr        runtimeclient.ObjectList
	Namespace *string
}

CRData represents a cr to dump

type KubernetesReporter

type KubernetesReporter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

KubernetesReporter is a Ginkgo reporter that dumps info about configured kubernetes objects.

func New

func New(kubeconfig string, addToScheme AddToScheme, namespaceToLog NamespaceFilter, reportPath string, crs ...CRData) (*KubernetesReporter, error)

New returns a new Kubernetes reporter from the given configuration.

func (*KubernetesReporter) Dump

func (r *KubernetesReporter) Dump(duration time.Duration, dumpSubpath string)

Dump dumps the relevant crs + pod logs. duration represents how much in the past we need to go when fetching the pod logs. dumpSubpath is the subpath relative to reportPath where the reporter will dump the output.

type NamespaceFilter

type NamespaceFilter func(string) bool

NamespaceFilter is a filter function to choose what namespaces to dump.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL