Skip to content

Commit

Permalink
Fix metrics agent test
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t committed Sep 12, 2024
1 parent ff1c443 commit fd1877e
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion controllers/k8ssandra/cassandra_metrics_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,55 @@ func createSingleDcClusterWithMetricsAgent(t *testing.T, ctx context.Context, f
t.Log("check that the datacenter was created")
dcKey := framework.ClusterKey{NamespacedName: types.NamespacedName{Namespace: namespace, Name: "dc1"}, K8sContext: f.DataPlaneContexts[0]}
require.Eventually(f.DatacenterExists(ctx, dcKey), timeout, interval)

t.Log("update datacenter status to ready")
kcKey := framework.NewClusterKey(f.ControlPlaneContext, namespace, kc.Name)
err = f.PatchDatacenterStatus(ctx, dcKey, func(dc *cassdcapi.CassandraDatacenter) {
dc.Status.CassandraOperatorProgress = cassdcapi.ProgressReady
dc.SetCondition(cassdcapi.DatacenterCondition{
Type: cassdcapi.DatacenterReady,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Now(),
})
})
require.NoError(err, "failed to update datacenter status to ready")

t.Log("check that the K8ssandraCluster status is updated")
require.Eventually(func() bool {
kc := &api.K8ssandraCluster{}
err = f.Get(ctx, kcKey, kc)

if err != nil {
t.Logf("failed to get K8ssandraCluster: %v", err)
return false
}

if len(kc.Status.Datacenters) == 0 {
return false
}

k8ssandraStatus, found := kc.Status.Datacenters[dcKey.Name]
if !found {
t.Logf("status for datacenter %s not found", dcKey)
return false
}

condition := findDatacenterCondition(k8ssandraStatus.Cassandra, cassdcapi.DatacenterReady)
return condition != nil && condition.Status == corev1.ConditionTrue
}, timeout, interval, "timed out waiting for K8ssandraCluster status update")

require.Eventually(func() bool {
return f.UpdateDatacenterGeneration(ctx, t, dcKey)
}, timeout, interval, "failed to update dc1 generation")

// Check that we have the right volumes and volume mounts.
dc := &cassdcapi.CassandraDatacenter{}
if err := f.Get(ctx, dcKey, dc); err != nil {
require.Fail("could not find dc")
}

// check that we have the right ConfigMap
agentCmKey := framework.ClusterKey{NamespacedName: types.NamespacedName{Name: "test-dc1" + "-metrics-agent-config", Namespace: namespace}, K8sContext: f.DataPlaneContexts[0]}
agentCmKey := framework.ClusterKey{NamespacedName: types.NamespacedName{Name: "test-dc1-metrics-agent-config", Namespace: namespace}, K8sContext: f.DataPlaneContexts[0]}
agentCm := corev1.ConfigMap{}
require.Eventually(func() bool {
if err := f.Get(ctx, agentCmKey, &agentCm); err != nil {
Expand Down Expand Up @@ -112,3 +153,12 @@ func createSingleDcClusterWithMetricsAgent(t *testing.T, ctx context.Context, f
require.NoError(err, "failed to delete K8ssandraCluster")
f.AssertObjectDoesNotExist(ctx, t, dcKey, &cassdcapi.CassandraDatacenter{}, timeout, interval)
}

func findDatacenterCondition(status *cassdcapi.CassandraDatacenterStatus, condType cassdcapi.DatacenterConditionType) *cassdcapi.DatacenterCondition {
for _, condition := range status.Conditions {
if condition.Type == condType {
return &condition
}
}
return nil
}

0 comments on commit fd1877e

Please sign in to comment.