forked from kubernetes-sigs/cluster-api-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 44
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
1 parent
012575c
commit 560711f
Showing
2 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"github.com/golang/glog" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
capiv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
) | ||
|
||
const ( | ||
namespace = "openshift-cluster-api" | ||
) | ||
|
||
func init() { | ||
if err := capiv1alpha1.AddToScheme(scheme.Scheme); err != nil { | ||
glog.Fatal(err) | ||
} | ||
} | ||
|
||
type testConfig struct { | ||
client client.Client | ||
} | ||
|
||
func newClient() (client.Client, error) { | ||
// Get a config to talk to the apiserver | ||
cfg, err := config.GetConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return client.New(cfg, client.Options{}) | ||
|
||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
if err := runSuite(); err != nil { | ||
glog.Fatal(err) | ||
} | ||
} | ||
|
||
func runSuite() error { | ||
|
||
client, err := newClient() | ||
if err != nil { | ||
return err | ||
} | ||
testConfig := &testConfig{ | ||
client: client, | ||
} | ||
glog.Info("RUN: ExpectProviderAvailable") | ||
if err := testConfig.ExpectProviderAvailable(); err != nil { | ||
glog.Errorf("FAIL: ExpectProviderAvailable: %v", err) | ||
return err | ||
} | ||
glog.Info("PASS: ExpectProviderAvailable") | ||
|
||
glog.Info("RUN: ExpectOneClusterObject") | ||
if err := testConfig.ExpectOneClusterObject(); err != nil { | ||
glog.Errorf("FAIL: ExpectOneClusterObject: %v", err) | ||
return err | ||
} | ||
glog.Info("PASS: ExpectOneClusterObject") | ||
|
||
return nil | ||
} |
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,60 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"context" | ||
"errors" | ||
"github.com/golang/glog" | ||
kappsapi "k8s.io/api/apps/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
capiv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
const ( | ||
waitShort = 1 * time.Minute | ||
waitMedium = 3 * time.Minute | ||
waitLong = 10 * time.Minute | ||
) | ||
|
||
func (tc *testConfig) ExpectProviderAvailable() error { | ||
name := "clusterapi-manager-controllers" | ||
key := types.NamespacedName{ | ||
Namespace: namespace, | ||
Name: name, | ||
} | ||
d := &kappsapi.Deployment{} | ||
|
||
err := wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) { | ||
if err := tc.client.Get(context.TODO(), key, d); err != nil { | ||
glog.Errorf("error querying api for Deployment object: %v, retrying...", err) | ||
return false, nil | ||
} | ||
if d.Status.ReadyReplicas < 1 { | ||
return false, nil | ||
} | ||
return true, nil | ||
}) | ||
return err | ||
} | ||
|
||
func (tc *testConfig) ExpectOneClusterObject() error { | ||
listOptions := client.ListOptions{ | ||
Namespace: namespace, | ||
} | ||
clusterList := capiv1alpha1.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") | ||
} | ||
return true, nil | ||
}) | ||
return err | ||
} |