mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
fed: Refactor integ test fixture to support cluster addition by test
This commit is contained in:
parent
e401dc7498
commit
ea61af57dd
@ -23,6 +23,7 @@ import (
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
federationapi "k8s.io/kubernetes/federation/apis/federation/v1beta1"
|
||||
federationclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset"
|
||||
clustercontroller "k8s.io/kubernetes/federation/pkg/federation-controller/cluster"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
"k8s.io/kubernetes/pkg/master"
|
||||
@ -43,6 +44,7 @@ type FederationFixture struct {
|
||||
Clusters []*MemberCluster
|
||||
ClusterClients []clientset.Interface
|
||||
ClusterController *clustercontroller.ClusterController
|
||||
fedClient federationclientset.Interface
|
||||
stopChan chan struct{}
|
||||
}
|
||||
|
||||
@ -64,46 +66,46 @@ func (f *FederationFixture) SetUp(t *testing.T) {
|
||||
monitorPeriod := 1 * time.Second
|
||||
clustercontroller.StartClusterController(f.APIFixture.NewConfig(), f.stopChan, monitorPeriod)
|
||||
|
||||
f.startClusters()
|
||||
f.fedClient = f.APIFixture.NewClient("federation-fixture")
|
||||
for i := 0; i < f.DesiredClusterCount; i++ {
|
||||
f.StartCluster(t)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FederationFixture) startClusters() {
|
||||
fedClient := f.APIFixture.NewClient("federation-fixture")
|
||||
for i := 0; i < f.DesiredClusterCount; i++ {
|
||||
config := framework.NewMasterConfig()
|
||||
_, _, closeFn := framework.RunAMaster(config)
|
||||
host := config.GenericConfig.LoopbackClientConfig.Host
|
||||
func (f *FederationFixture) StartCluster(t *testing.T) {
|
||||
config := framework.NewMasterConfig()
|
||||
_, _, closeFn := framework.RunAMaster(config)
|
||||
host := config.GenericConfig.LoopbackClientConfig.Host
|
||||
|
||||
// Use fmt to ensure the output will be visible when run with go test -v
|
||||
fmt.Printf("Federated cluster %d serving on %s", i, host)
|
||||
clusterClient := clientset.NewForConfigOrDie(config.GenericConfig.LoopbackClientConfig)
|
||||
f.ClusterClients = append(f.ClusterClients, clusterClient)
|
||||
f.Clusters = append(f.Clusters, &MemberCluster{
|
||||
CloseFn: closeFn,
|
||||
Config: config,
|
||||
Client: clusterClient,
|
||||
Host: host,
|
||||
})
|
||||
|
||||
clusterClient := clientset.NewForConfigOrDie(config.GenericConfig.LoopbackClientConfig)
|
||||
f.Clusters = append(f.Clusters, &MemberCluster{
|
||||
CloseFn: closeFn,
|
||||
Config: config,
|
||||
Client: clusterClient,
|
||||
Host: host,
|
||||
})
|
||||
clusterId := len(f.ClusterClients)
|
||||
|
||||
f.ClusterClients = append(f.ClusterClients, clusterClient)
|
||||
t.Logf("Federated cluster %d serving on %s", clusterId, host)
|
||||
|
||||
cluster := &federationapi.Cluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: fmt.Sprintf("cluster-%d", i),
|
||||
},
|
||||
Spec: federationapi.ClusterSpec{
|
||||
ServerAddressByClientCIDRs: []federationapi.ServerAddressByClientCIDR{
|
||||
{
|
||||
ClientCIDR: "0.0.0.0/0",
|
||||
ServerAddress: host,
|
||||
},
|
||||
cluster := &federationapi.Cluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: fmt.Sprintf("cluster-%d", clusterId),
|
||||
},
|
||||
Spec: federationapi.ClusterSpec{
|
||||
ServerAddressByClientCIDRs: []federationapi.ServerAddressByClientCIDR{
|
||||
{
|
||||
ClientCIDR: "0.0.0.0/0",
|
||||
ServerAddress: host,
|
||||
},
|
||||
// Use insecure access
|
||||
SecretRef: nil,
|
||||
},
|
||||
}
|
||||
fedClient.FederationV1beta1().Clusters().Create(cluster)
|
||||
// Use insecure access
|
||||
SecretRef: nil,
|
||||
},
|
||||
}
|
||||
f.fedClient.FederationV1beta1().Clusters().Create(cluster)
|
||||
}
|
||||
|
||||
func (f *FederationFixture) TearDown(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user