Skip to content

Commit

Permalink
add new test TestClusterDefaultNodeSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelina Nikiforova committed Feb 25, 2020
1 parent 398a611 commit a33ee0a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
42 changes: 42 additions & 0 deletions test/integration/bugs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,45 @@ func TestUnreachableHost(t *testing.T) {
})
t.Log(errDegraded)
}

// https://bugzilla.redhat.com/show_bug.cgi?id=1782151
func TestClusterDefaultNodeSelector(t *testing.T) {
// set default selctor of node-role.kubernetes.io/worker
schedulers, err := configClient.Schedulers().List(metav1.ListOptions{})
t.Log(schedulers)
if err != nil {
t.Fatal(err.Error())
}
for _, scheduler := range schedulers.Items {
if scheduler.ObjectMeta.Name == "cluster" {
scheduler.Spec.DefaultNodeSelector = "node-role.kubernetes.io/worker="
configClient.Schedulers().Update(&scheduler)
}
}

// restart insights-operator (delete pods)
restartInsightsOperator(t)

// check the pod is scheduled
newPods, err := clientset.CoreV1().Pods("openshift-insights").List(metav1.ListOptions{})
if err != nil {
t.Fatal(err.Error())
}

for _, newPod := range newPods.Items {
pod, err := clientset.CoreV1().Pods("openshift-insights").Get(newPod.Name, metav1.GetOptions{})
if err != nil {
panic(err.Error())
}
podConditions := pod.Status.Conditions
for _, condition := range podConditions {
if condition.Type == "PodScheduled" {
if condition.Status != "True" {
t.Log("Pod is not scheduled")
t.Fatal(err.Error())
}
}
}
t.Log("Pod is scheduled")
}
}
23 changes: 7 additions & 16 deletions test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

var clientset = kubeClient()
var configClient = configV1Client()

func kubeClient() (result *kubernetes.Clientset) {
func kubeconfig() (config *restclient.Config) {
kubeconfig, ok := os.LookupEnv("KUBECONFIG") // variable is a path to the local kubeconfig
if !ok {
fmt.Printf("kubeconfig variable is not set\n")
Expand All @@ -34,29 +35,19 @@ func kubeClient() (result *kubernetes.Clientset) {
fmt.Printf("%#v", err)
os.Exit(1)
}
return config
}

clientset, err := kubernetes.NewForConfig(config)
func kubeClient() (result *kubernetes.Clientset) {
clientset, err := kubernetes.NewForConfig(kubeconfig())
if err != nil {
panic(err.Error())
}
return clientset
}

func configV1Client() (result *configv1client.ConfigV1Client) {
kubeconfig, ok := os.LookupEnv("KUBECONFIG") // variable is a path to the local kubeconfig
if !ok {
fmt.Printf("kubeconfig variable is not set\n")
} else {
fmt.Printf("KUBECONFIG=%s\n", kubeconfig)
}
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
fmt.Printf("%#v", err)
os.Exit(1)
}

client, err := configv1client.NewForConfig(config)
client, err := configv1client.NewForConfig(kubeconfig())
if err != nil {
panic(err.Error())
}
Expand Down

0 comments on commit a33ee0a

Please sign in to comment.