Skip to content

Commit

Permalink
Update tests to run against machine.openshift.io
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed Feb 7, 2019
1 parent 7c4849a commit 1e54d5e
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions test/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/golang/glog"
osconfigv1 "github.com/openshift/api/config/v1"
capiv1alpha1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1"
mapiv1beta1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
caov1alpha1 "github.com/openshift/cluster-autoscaler-operator/pkg/apis"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -17,7 +17,7 @@ const (
)

func init() {
if err := capiv1alpha1.AddToScheme(scheme.Scheme); err != nil {
if err := mapiv1beta1.AddToScheme(scheme.Scheme); err != nil {
glog.Fatal(err)
}

Expand Down Expand Up @@ -68,9 +68,9 @@ func runSuite() error {
}
glog.Info("PASS: ExpectOperatorAvailable")

glog.Info("RUN: ExpectOneClusterObject")
if err := testConfig.ExpectOneClusterObject(); err != nil {
glog.Errorf("FAIL: ExpectOneClusterObject: %v", err)
glog.Info("RUN: ExpectNoClusterObject")
if err := testConfig.ExpectNoClusterObject(); err != nil {
glog.Errorf("FAIL: ExpectNoClusterObject: %v", err)
return err
}
glog.Info("PASS: ExpectOneClusterObject")
Expand Down
28 changes: 14 additions & 14 deletions test/e2e/operator_expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/golang/glog"
osconfigv1 "github.com/openshift/api/config/v1"
capiv1alpha1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1"
mapiv1beta1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
caov1alpha1 "github.com/openshift/cluster-autoscaler-operator/pkg/apis/autoscaling/v1alpha1"
cvoresourcemerge "github.com/openshift/cluster-version-operator/lib/resourcemerge"
kappsapi "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -51,19 +51,19 @@ func (tc *testConfig) ExpectOperatorAvailable() error {
return err
}

func (tc *testConfig) ExpectOneClusterObject() error {
func (tc *testConfig) ExpectNoClusterObject() error {
listOptions := client.ListOptions{
Namespace: namespace,
}
clusterList := capiv1alpha1.ClusterList{}
clusterList := mapiv1beta1.ClusterList{}

err := wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
if err := tc.client.List(context.TODO(), &listOptions, &clusterList); err != nil {
glog.Errorf("error querying api for clusterList object: %v, retrying...", err)
return false, nil
}
if len(clusterList.Items) != 1 {
return false, errors.New("more than one cluster object found")
if len(clusterList.Items) > 0 {
return false, errors.New("a cluster object was found")
}
return true, nil
})
Expand Down Expand Up @@ -94,11 +94,11 @@ func (tc *testConfig) ExpectClusterOperatorStatusAvailable() error {
}

func (tc *testConfig) ExpectAllMachinesLinkedToANode() error {
machineAnnotationKey := "cluster.k8s.io/machine"
machineAnnotationKey := "machine.openshift.io/machine"
listOptions := client.ListOptions{
Namespace: namespace,
}
machineList := capiv1alpha1.MachineList{}
machineList := mapiv1beta1.MachineList{}
nodeList := corev1.NodeList{}

err := wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
Expand Down Expand Up @@ -187,7 +187,7 @@ func (tc *testConfig) ExpectAdditiveReconcileMachineTaints() error {
listOptions := client.ListOptions{
Namespace: namespace,
}
machineList := capiv1alpha1.MachineList{}
machineList := mapiv1beta1.MachineList{}

if err := tc.client.List(context.TODO(), &listOptions, &machineList); err != nil {
return fmt.Errorf("error querying api for machineList object: %v", err)
Expand Down Expand Up @@ -255,7 +255,7 @@ func (tc *testConfig) ExpectNewNodeWhenDeletingMachine() error {
listOptions := client.ListOptions{
Namespace: namespace,
}
machineList := capiv1alpha1.MachineList{}
machineList := mapiv1beta1.MachineList{}
nodeList := corev1.NodeList{}

glog.Info("Get machineList")
Expand Down Expand Up @@ -284,7 +284,7 @@ func (tc *testConfig) ExpectNewNodeWhenDeletingMachine() error {

clusterInitialTotalNodes := len(nodeList.Items)
clusterInitialTotalMachines := len(machineList.Items)
var triagedWorkerMachine capiv1alpha1.Machine
var triagedWorkerMachine mapiv1beta1.Machine
var triagedWorkerNode corev1.Node
MachineLoop:
for _, m := range machineList.Items {
Expand Down Expand Up @@ -361,7 +361,7 @@ func (tc *testConfig) ExpectAutoscalerScalesOut() error {
Namespace: namespace,
}
glog.Info("Get one machineSet")
machineSetList := capiv1alpha1.MachineSetList{}
machineSetList := mapiv1beta1.MachineSetList{}
err := wait.PollImmediate(1*time.Second, waitMedium, func() (bool, error) {
if err := tc.client.List(context.TODO(), &listOptions, &machineSetList); err != nil {
glog.Errorf("error querying api for nodeList object: %v, retrying...", err)
Expand Down Expand Up @@ -408,7 +408,7 @@ func (tc *testConfig) ExpectAutoscalerScalesOut() error {
ScaleTargetRef: caov1alpha1.CrossVersionObjectReference{
Name: targetMachineSet.Name,
Kind: "MachineSet",
APIVersion: "cluster.k8s.io/v1alpha1",
APIVersion: "machine.openshift.io/v1beta1",
},
},
}
Expand Down Expand Up @@ -513,7 +513,7 @@ func (tc *testConfig) ExpectAutoscalerScalesOut() error {
Namespace: namespace,
Name: targetMachineSet.Name,
}
ms := &capiv1alpha1.MachineSet{}
ms := &mapiv1beta1.MachineSet{}
if err := tc.client.Get(context.TODO(), msKey, ms); err != nil {
glog.Errorf("error querying api for clusterAutoscaler object: %v, retrying...", err)
return false, nil
Expand Down Expand Up @@ -581,7 +581,7 @@ func (tc *testConfig) ExpectAutoscalerScalesOut() error {
Namespace: namespace,
Name: targetMachineSet.Name,
}
ms := &capiv1alpha1.MachineSet{}
ms := &mapiv1beta1.MachineSet{}
if err := tc.client.Get(context.TODO(), msKey, ms); err != nil {
glog.Errorf("error querying api for machineSet object: %v, retrying...", err)
return false, nil
Expand Down
36 changes: 18 additions & 18 deletions test/integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"

capiv1alpha1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1"
mapiv1beta1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
"github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset"
capiv1alpha1scheme "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/scheme"
mapiv1beta1scheme "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/scheme"
)

const (
Expand All @@ -51,7 +51,7 @@ func usage() {

// TestConfig stores clients for managing various resources
type TestConfig struct {
CAPIClient *clientset.Clientset
MAPIClient *clientset.Clientset
APIExtensionsClient *apiextensionsclientset.Clientset
KubeClient *kubernetes.Clientset
AWSClient *AWSClient
Expand All @@ -64,7 +64,7 @@ func NewTestConfig(kubeconfig string) *TestConfig {
glog.Fatalf("Could not create Config for talking to the apiserver: %v", err)
}

capiclient, err := clientset.NewForConfig(config)
mapiclient, err := clientset.NewForConfig(config)
if err != nil {
glog.Fatalf("Could not create client for talking to the apiserver: %v", err)
}
Expand All @@ -80,7 +80,7 @@ func NewTestConfig(kubeconfig string) *TestConfig {
}

return &TestConfig{
CAPIClient: capiclient,
MAPIClient: mapiclient,
APIExtensionsClient: apiextensionsclient,
KubeClient: kubeClient,
}
Expand Down Expand Up @@ -222,7 +222,7 @@ var rootCmd = &cobra.Command{
return err
}

capiv1alpha1scheme.AddToScheme(scheme.Scheme)
mapiv1beta1scheme.AddToScheme(scheme.Scheme)
apiextensionsscheme.AddToScheme(scheme.Scheme)
decode := scheme.Codecs.UniversalDeserializer().Decode
// create rbac
Expand Down Expand Up @@ -256,7 +256,7 @@ var rootCmd = &cobra.Command{
}

// create machine CRD
if CRDBytes, err := ioutil.ReadFile(filepath.Join(assetsPath, manifestsFolder, "0000_30_machine-api-operator_02_machine.crd.yaml")); err != nil {
if CRDBytes, err := ioutil.ReadFile(filepath.Join(assetsPath, manifestsFolder, "0000_30_machine-api-operator_08_machine.crd.yaml")); err != nil {
glog.Fatalf("Error reading %#v", err)
} else {
CRDObj, _, err := decode([]byte(CRDBytes), nil, nil)
Expand All @@ -271,7 +271,7 @@ var rootCmd = &cobra.Command{
}

// create machineSet CRD
if CRDBytes, err := ioutil.ReadFile(filepath.Join(assetsPath, manifestsFolder, "0000_30_machine-api-operator_03_machineset.crd.yaml")); err != nil {
if CRDBytes, err := ioutil.ReadFile(filepath.Join(assetsPath, manifestsFolder, "0000_30_machine-api-operator_09_machineset.crd.yaml")); err != nil {
glog.Fatalf("Error reading %#v", err)
} else {
CRDObj, _, err := decode([]byte(CRDBytes), nil, nil)
Expand All @@ -286,7 +286,7 @@ var rootCmd = &cobra.Command{
}

// create machineDeployment CRD
if CRDBytes, err := ioutil.ReadFile(filepath.Join(assetsPath, manifestsFolder, "0000_30_machine-api-operator_04_machinedeployment.crd.yaml")); err != nil {
if CRDBytes, err := ioutil.ReadFile(filepath.Join(assetsPath, manifestsFolder, "0000_30_machine-api-operator_10_machinedeployment.crd.yaml")); err != nil {
glog.Fatalf("Error reading %#v", err)
} else {
CRDObj, _, err := decode([]byte(CRDBytes), nil, nil)
Expand All @@ -301,7 +301,7 @@ var rootCmd = &cobra.Command{
}

// create cluster CRD
if CRDBytes, err := ioutil.ReadFile(filepath.Join(assetsPath, manifestsFolder, "0000_30_machine-api-operator_05_cluster.crd.yaml")); err != nil {
if CRDBytes, err := ioutil.ReadFile(filepath.Join(assetsPath, manifestsFolder, "0000_30_machine-api-operator_11_cluster.crd.yaml")); err != nil {
glog.Fatalf("Error reading %#v", err)
} else {
CRDObj, _, err := decode([]byte(CRDBytes), nil, nil)
Expand Down Expand Up @@ -448,8 +448,8 @@ var rootCmd = &cobra.Command{
if err != nil {
glog.Fatalf("Error decoding %#v", err)
}
cluster := clusterObj.(*capiv1alpha1.Cluster)
if _, err := testConfig.CAPIClient.ClusterV1alpha1().Clusters(targetNamespace).Create(cluster); err != nil {
cluster := clusterObj.(*mapiv1beta1.Cluster)
if _, err := testConfig.MAPIClient.MachineV1beta1().Clusters(targetNamespace).Create(cluster); err != nil {
return err
}
}
Expand All @@ -461,26 +461,26 @@ var rootCmd = &cobra.Command{
if err != nil {
glog.Fatalf("Error decoding %#v", err)
}
machineSet := machineSetObj.(*capiv1alpha1.MachineSet)
if _, err := testConfig.CAPIClient.ClusterV1alpha1().MachineSets(targetNamespace).Create(machineSet); err != nil {
machineSet := machineSetObj.(*mapiv1beta1.MachineSet)
if _, err := testConfig.MAPIClient.MachineV1beta1().MachineSets(targetNamespace).Create(machineSet); err != nil {
return err
}
}

// Verify cluster, machineSet and machines have been deployed
var cluster, machineSet, workers bool
err = wait.Poll(pollInterval, timeoutPoolMachineSetRunningInterval, func() (bool, error) {
if _, err := testConfig.CAPIClient.ClusterV1alpha1().Clusters(targetNamespace).Get(clusterID, metav1.GetOptions{}); err == nil {
if _, err := testConfig.MAPIClient.MachineV1beta1().Clusters(targetNamespace).Get(clusterID, metav1.GetOptions{}); err == nil {
cluster = true
log.Info("Cluster object has been created")
}

if _, err := testConfig.CAPIClient.ClusterV1alpha1().MachineSets(targetNamespace).Get("worker", metav1.GetOptions{}); err == nil {
if _, err := testConfig.MAPIClient.MachineV1beta1().MachineSets(targetNamespace).Get("worker", metav1.GetOptions{}); err == nil {
machineSet = true
log.Info("MachineSet object has been created")
}

if workersList, err := testConfig.CAPIClient.ClusterV1alpha1().Machines(targetNamespace).List(metav1.ListOptions{}); err == nil {
if workersList, err := testConfig.MAPIClient.MachineV1beta1().Machines(targetNamespace).List(metav1.ListOptions{}); err == nil {
if len(workersList.Items) == machineSetReplicas {
workers = true
log.Info("Machine objects has been created")
Expand Down Expand Up @@ -527,7 +527,7 @@ var rootCmd = &cobra.Command{
func tearDown(testConfig *TestConfig, assetsPath string) error {
// delete machine set
// not erroring here so we try to terraform destroy
if err := testConfig.CAPIClient.ClusterV1alpha1().MachineSets(targetNamespace).Delete("worker", &metav1.DeleteOptions{}); err != nil {
if err := testConfig.MAPIClient.MachineV1beta1().MachineSets(targetNamespace).Delete("worker", &metav1.DeleteOptions{}); err != nil {
log.Warningf("unable to delete machineSet, %v", err)
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion test/integration/manifests/cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: cluster.k8s.io/v1alpha1
apiVersion: machine.openshift.io/v1beta1
kind: Cluster
metadata:
name: {{ .ClusterID }}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/manifests/machineset.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: cluster.k8s.io/v1alpha1
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
labels:
Expand Down

0 comments on commit 1e54d5e

Please sign in to comment.