Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Angelina Nikiforova
committed
Nov 19, 2019
1 parent
c0b9c27
commit a9fcf55
Showing
3 changed files
with
122 additions
and
1 deletion.
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,61 @@ | ||
package integration | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
var ( | ||
kubeConfig *rest.Config | ||
kubeClient = KubeClient() | ||
) | ||
|
||
// https://bugzilla.redhat.com/show_bug.cgi?id=1750665 | ||
func TestDefaultUploadFrequency(t *testing.T) { | ||
// delete any existing overriding secret | ||
err := kubeClient.CoreV1().Secrets("openshift-config").Delete("support", &metav1.DeleteOptions{}) | ||
|
||
// if the secret is not found, continue, not a problem | ||
if (err != nil) && (err.Error() != "secrets \"support\" not found") { | ||
panic(err.Error()) | ||
} | ||
|
||
// restart insights-operator (delete pods) | ||
pods, err := kubeClient.CoreV1().Pods("openshift-insights").List(metav1.ListOptions{}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
for _, pod := range pods.Items { | ||
kubeClient.CoreV1().Pods("openshift-insights").Delete(pod.Name, &metav1.DeleteOptions{}) | ||
} | ||
|
||
// check logs for "Gathering cluster info every 2h0m0s" | ||
newPods, err := kubeClient.CoreV1().Pods("openshift-insights").List(metav1.ListOptions{}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
for _, newPod := range newPods.Items { | ||
pod, err := kubeClient.CoreV1().Pods("openshift-insights").Get(newPod.Name, metav1.GetOptions{}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
req := kubeClient.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &corev1.PodLogOptions{}) | ||
podLogs, err := req.Stream() | ||
defer podLogs.Close() | ||
|
||
buf := new(bytes.Buffer) | ||
_, err = io.Copy(buf, podLogs) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
log := buf.String() | ||
print(log) | ||
} | ||
} |
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,56 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
func KubeClient() (result *kubernetes.Clientset) { | ||
kubeconfig := os.Getenv("KUBECONFIG") // variable is a path to the local kubeconfig | ||
|
||
// use the current context in kubeconfig | ||
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) | ||
if err != nil { | ||
fmt.Printf("%#v", err) | ||
os.Exit(1) | ||
} | ||
|
||
kubeClient, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
return kubeClient | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
kubeClient = KubeClient() | ||
// check the operator is up | ||
err := waitForOperator(kubeClient) | ||
if err != nil { | ||
fmt.Println("failed waiting for operator to start") | ||
os.Exit(1) | ||
} | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func waitForOperator(kubeClient *kubernetes.Clientset) error { | ||
depClient := kubeClient.AppsV1().Deployments("openshift-insights") | ||
|
||
err := wait.PollImmediate(1*time.Second, 10*time.Minute, func() (bool, error) { | ||
_, err := depClient.Get("insights-operator", metav1.GetOptions{}) | ||
if err != nil { | ||
fmt.Printf("error waiting for operator deployment to exist: %v\n", err) | ||
return false, nil | ||
} | ||
fmt.Println("found operator deployment") | ||
return true, nil | ||
}) | ||
return err | ||
} |