mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-26 19:35:10 +00:00
Merge pull request #45745 from marun/fed-test-cluster-addition
Automatic merge from submit-queue (batch tested with PRs 45990, 45544, 45745, 45742, 45678) [Federation] Add integration testing for cluster addition This PR adds integration testing of the sync controller for cluster addition. This ensures coverage equivalency between the integration tests and the old controller unit tests, so those tests are removed by this PR. Resolves #45257 cc: @kubernetes/sig-federation-pr-reviews
This commit is contained in:
@@ -20,6 +20,7 @@ go_test(
|
||||
deps = [
|
||||
"//federation/apis/federation/v1beta1:go_default_library",
|
||||
"//federation/pkg/federatedtypes:go_default_library",
|
||||
"//federation/pkg/federatedtypes/crudtester:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/apis/autoscaling/v1:go_default_library",
|
||||
"//pkg/apis/batch/v1:go_default_library",
|
||||
@@ -28,6 +29,7 @@ go_test(
|
||||
"//vendor/github.com/pborman/uuid:go_default_library",
|
||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
|
||||
"github.com/pborman/uuid"
|
||||
|
||||
pkgruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/federation/pkg/federatedtypes"
|
||||
"k8s.io/kubernetes/federation/pkg/federatedtypes/crudtester"
|
||||
"k8s.io/kubernetes/test/integration/federation/framework"
|
||||
)
|
||||
|
||||
@@ -35,41 +37,57 @@ func TestFederationCRUD(t *testing.T) {
|
||||
federatedTypes := federatedtypes.FederatedTypes()
|
||||
for kind, fedType := range federatedTypes {
|
||||
t.Run(kind, func(t *testing.T) {
|
||||
config := fedFixture.APIFixture.NewConfig()
|
||||
fixture := framework.NewControllerFixture(t, kind, fedType.AdapterFactory, config)
|
||||
fixture, crudTester, obj := initCRUDTest(t, &fedFixture, fedType.AdapterFactory, kind)
|
||||
defer fixture.TearDown(t)
|
||||
|
||||
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("crud-test-%s", kind))
|
||||
adapter := fedType.AdapterFactory(client)
|
||||
|
||||
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
|
||||
obj := adapter.NewTestObject(uuid.New())
|
||||
crudtester.CheckLifecycle(obj)
|
||||
crudTester.CheckLifecycle(obj)
|
||||
})
|
||||
}
|
||||
|
||||
// Validate deletion handling where orphanDependents is true or nil for a single resource type since the
|
||||
// underlying logic is common across all types.
|
||||
orphanedDependents := true
|
||||
testCases := map[string]*bool{
|
||||
"Resources should not be deleted from underlying clusters when OrphanDependents is true": &orphanedDependents,
|
||||
"Resources should not be deleted from underlying clusters when OrphanDependents is nil": nil,
|
||||
}
|
||||
// The following tests target a single type since the underlying logic is common across all types.
|
||||
kind := federatedtypes.SecretKind
|
||||
adapterFactory := federatedtypes.NewSecretAdapter
|
||||
|
||||
// Validate deletion handling where orphanDependents is true or nil
|
||||
orphanedDependents := true
|
||||
testCases := map[string]*bool{
|
||||
"Resource should not be deleted from underlying clusters when OrphanDependents is true": &orphanedDependents,
|
||||
"Resource should not be deleted from underlying clusters when OrphanDependents is nil": nil,
|
||||
}
|
||||
for testName, orphanDependents := range testCases {
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
config := fedFixture.APIFixture.NewConfig()
|
||||
fixture := framework.NewControllerFixture(t, kind, adapterFactory, config)
|
||||
fixture, crudTester, obj := initCRUDTest(t, &fedFixture, adapterFactory, kind)
|
||||
defer fixture.TearDown(t)
|
||||
|
||||
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("deletion-test-%s", kind))
|
||||
adapter := adapterFactory(client)
|
||||
|
||||
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
|
||||
obj := adapter.NewTestObject(uuid.New())
|
||||
updatedObj := crudtester.CheckCreate(obj)
|
||||
crudtester.CheckDelete(updatedObj, orphanDependents)
|
||||
updatedObj := crudTester.CheckCreate(obj)
|
||||
crudTester.CheckDelete(updatedObj, orphanDependents)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("Resource should be propagated to a newly added cluster", func(t *testing.T) {
|
||||
fixture, crudTester, obj := initCRUDTest(t, &fedFixture, adapterFactory, kind)
|
||||
defer fixture.TearDown(t)
|
||||
|
||||
updatedObj := crudTester.CheckCreate(obj)
|
||||
// Start a new cluster and validate that the resource is propagated to it.
|
||||
fedFixture.StartCluster(t)
|
||||
// Check propagation to the new cluster by providing the updated set of clients
|
||||
crudTester.CheckPropagationForClients(updatedObj, fedFixture.ClusterClients)
|
||||
})
|
||||
}
|
||||
|
||||
// initCRUDTest initializes common elements of a crud test
|
||||
func initCRUDTest(t *testing.T, fedFixture *framework.FederationFixture, adapterFactory federatedtypes.AdapterFactory, kind string) (
|
||||
*framework.ControllerFixture, *crudtester.FederatedTypeCRUDTester, pkgruntime.Object) {
|
||||
config := fedFixture.APIFixture.NewConfig()
|
||||
fixture := framework.NewControllerFixture(t, kind, adapterFactory, config)
|
||||
|
||||
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("crud-test-%s", kind))
|
||||
adapter := adapterFactory(client)
|
||||
|
||||
crudTester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
|
||||
|
||||
obj := adapter.NewTestObject(uuid.New())
|
||||
|
||||
return fixture, crudTester, obj
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user