-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from fedepaol/test_reporter
Add tests failure reporter.
- Loading branch information
Showing
17 changed files
with
19,119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package k8sreporter | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/golang/glog" | ||
clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1" | ||
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type clientSet struct { | ||
corev1client.CoreV1Interface | ||
clientconfigv1.ConfigV1Interface | ||
appsv1client.AppsV1Interface | ||
runtimeclient.Client | ||
} | ||
|
||
// New returns a *ClientBuilder with the given kubeconfig. | ||
func newClient(kubeconfig string, crScheme *runtime.Scheme) *clientSet { | ||
var config *rest.Config | ||
var err error | ||
|
||
if kubeconfig == "" { | ||
kubeconfig = os.Getenv("KUBECONFIG") | ||
} | ||
|
||
if kubeconfig != "" { | ||
glog.V(4).Infof("Loading kube client config from path %q", kubeconfig) | ||
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig) | ||
} else { | ||
glog.V(4).Infof("Using in-cluster kube client config") | ||
config, err = rest.InClusterConfig() | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientSet := &clientSet{} | ||
clientSet.CoreV1Interface = corev1client.NewForConfigOrDie(config) | ||
clientSet.ConfigV1Interface = clientconfigv1.NewForConfigOrDie(config) | ||
clientSet.AppsV1Interface = appsv1client.NewForConfigOrDie(config) | ||
|
||
clientSet.Client, err = runtimeclient.New(config, client.Options{ | ||
Scheme: crScheme, | ||
}) | ||
return clientSet | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
promv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1" | ||
"github.com/openshift-kni/cnf-features-deploy/functests/utils/k8sreporter" | ||
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/utils/pointer" | ||
) | ||
|
||
func main() { | ||
kubeconfig := flag.String("kubeconfig", "", "the kubeconfig path") | ||
report := flag.String("report", "report.log", "the file name used for the report") | ||
|
||
flag.Parse() | ||
|
||
addToScheme := func(s *runtime.Scheme) { | ||
mcfgv1.AddToScheme(s) | ||
promv1.AddToScheme(s) | ||
} | ||
|
||
filterPods := func(pod *v1.Pod) bool { | ||
// never filter | ||
return false | ||
} | ||
|
||
f, err := os.OpenFile(*report, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
log.Fatalf("failed to open the file: %v\n", err) | ||
return | ||
} | ||
defer f.Close() | ||
|
||
crs := []k8sreporter.CRData{ | ||
k8sreporter.CRData{ | ||
Cr: &mcfgv1.MachineConfigPoolList{}, | ||
}, | ||
k8sreporter.CRData{ | ||
Cr: &promv1.ServiceMonitorList{}, | ||
}, | ||
k8sreporter.CRData{ | ||
Cr: &promv1.ServiceMonitorList{}, | ||
Namespace: pointer.StringPtr("openshift-multus"), | ||
}, | ||
} | ||
|
||
reporter := k8sreporter.New(*kubeconfig, addToScheme, filterPods, f, crs...) | ||
reporter.Dump(10 * time.Minute) | ||
} |
Oops, something went wrong.