Skip to content

A go library do dump the state of a k8s cluster, to be used after an e2e test failure

License

Notifications You must be signed in to change notification settings

openshift-kni/k8sreporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A go library do dump the state of a k8s cluster, to be used after an e2e test failure

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages