mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
fed: Add integration testing for cluster addition
This commit is contained in:
parent
ea61af57dd
commit
578f17c668
@ -163,11 +163,17 @@ func (c *FederatedTypeCRUDTester) CheckDelete(obj pkgruntime.Object, orphanDepen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckPropagation checks propagation for the crud tester's clients
|
||||||
func (c *FederatedTypeCRUDTester) CheckPropagation(obj pkgruntime.Object) {
|
func (c *FederatedTypeCRUDTester) CheckPropagation(obj pkgruntime.Object) {
|
||||||
|
c.CheckPropagationForClients(obj, c.clusterClients)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckPropagationForClients checks propagation for the provided clients
|
||||||
|
func (c *FederatedTypeCRUDTester) CheckPropagationForClients(obj pkgruntime.Object, clusterClients []clientset.Interface) {
|
||||||
namespacedName := c.adapter.NamespacedName(obj)
|
namespacedName := c.adapter.NamespacedName(obj)
|
||||||
|
|
||||||
c.tl.Logf("Waiting for %s %q in %d clusters", c.kind, namespacedName, len(c.clusterClients))
|
c.tl.Logf("Waiting for %s %q in %d clusters", c.kind, namespacedName, len(clusterClients))
|
||||||
for _, client := range c.clusterClients {
|
for _, client := range clusterClients {
|
||||||
err := c.waitForResource(client, obj)
|
err := c.waitForResource(client, obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.tl.Fatalf("Failed to verify %s %q in a member cluster: %v", c.kind, namespacedName, err)
|
c.tl.Fatalf("Failed to verify %s %q in a member cluster: %v", c.kind, namespacedName, err)
|
||||||
|
@ -48,15 +48,16 @@ func TestFederationCRUD(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate deletion handling where orphanDependents is true or nil for a single resource type since the
|
// The following tests target a single type since the underlying logic is common across all types.
|
||||||
// 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,
|
|
||||||
}
|
|
||||||
kind := federatedtypes.SecretKind
|
kind := federatedtypes.SecretKind
|
||||||
adapterFactory := federatedtypes.NewSecretAdapter
|
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 {
|
for testName, orphanDependents := range testCases {
|
||||||
t.Run(testName, func(t *testing.T) {
|
t.Run(testName, func(t *testing.T) {
|
||||||
config := fedFixture.APIFixture.NewConfig()
|
config := fedFixture.APIFixture.NewConfig()
|
||||||
@ -72,4 +73,22 @@ func TestFederationCRUD(t *testing.T) {
|
|||||||
crudtester.CheckDelete(updatedObj, orphanDependents)
|
crudtester.CheckDelete(updatedObj, orphanDependents)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Run("Resource should be propagated to a newly added cluster", func(t *testing.T) {
|
||||||
|
config := fedFixture.APIFixture.NewConfig()
|
||||||
|
fixture := framework.NewControllerFixture(t, kind, adapterFactory, config)
|
||||||
|
defer fixture.TearDown(t)
|
||||||
|
|
||||||
|
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("cluster-addition-test-%s", kind))
|
||||||
|
adapter := adapterFactory(client)
|
||||||
|
|
||||||
|
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
|
||||||
|
obj := adapter.NewTestObject(uuid.New())
|
||||||
|
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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user