Skip to content

Commit

Permalink
reflect the number of clusters found
Browse files Browse the repository at this point in the history
  • Loading branch information
sarataha committed Nov 1, 2023
1 parent 86ef4c9 commit df0aa8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 14 additions & 1 deletion internal/controller/automatedclusterdiscovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,23 @@ func (r *AutomatedClusterDiscoveryReconciler) Reconcile(ctx context.Context, req

clusterDiscovery.Status.Inventory = &clustersv1alpha1.ResourceInventory{Entries: inventoryRefs}

// Get number of clusters in inventory
clusters := 0
for _, item := range inventoryRefs {
objMeta, err := object.ParseObjMetadata(item.ID)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to parse object ID %s: %w", item.ID, err)
}

if objMeta.GroupKind.Kind == "GitopsCluster" {
clusters++
}
}

if inventoryRefs != nil {
logger.Info("reconciled clusters", "count", len(inventoryRefs))
clustersv1alpha1.SetAutomatedClusterDiscoveryReadiness(clusterDiscovery, clusterDiscovery.Status.Inventory, metav1.ConditionTrue, clustersv1alpha1.ReconciliationSucceededReason,
fmt.Sprintf("%d resources created", len(inventoryRefs)))
fmt.Sprintf("%d clusters discovered", clusters))

if err = r.patchStatus(ctx, req, clusterDiscovery.Status); err != nil {
return ctrl.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestAutomatedClusterDiscoveryReconciler(t *testing.T) {
assertInventoryHasItems(t, aksCluster,
newSecret(client.ObjectKeyFromObject(secret)),
newGitopsCluster(secret.GetName(), client.ObjectKeyFromObject(gitopsCluster)))
assertAutomatedClusterDiscoveryCondition(t, aksCluster, meta.ReadyCondition, "2 resources created")
assertAutomatedClusterDiscoveryCondition(t, aksCluster, meta.ReadyCondition, "1 clusters discovered")

clusterRef := metav1.OwnerReference{
Kind: "AutomatedClusterDiscovery",
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestAutomatedClusterDiscoveryReconciler(t *testing.T) {

secret := newSecret(types.NamespacedName{Name: "cluster-1-kubeconfig", Namespace: "default"})
assertInventoryHasItems(t, aksCluster, secret, gitopsCluster)
assertAutomatedClusterDiscoveryCondition(t, aksCluster, meta.ReadyCondition, "2 resources created")
assertAutomatedClusterDiscoveryCondition(t, aksCluster, meta.ReadyCondition, "1 clusters discovered")

testProvider.response = []*providers.ProviderCluster{}

Expand Down Expand Up @@ -348,7 +348,7 @@ func TestAutomatedClusterDiscoveryReconciler(t *testing.T) {

secret := newSecret(types.NamespacedName{Name: "cluster-1-kubeconfig", Namespace: "default"})
assertInventoryHasItems(t, aksCluster, secret, gitopsCluster)
assertAutomatedClusterDiscoveryCondition(t, aksCluster, meta.ReadyCondition, "2 resources created")
assertAutomatedClusterDiscoveryCondition(t, aksCluster, meta.ReadyCondition, "1 clusters discovered")

cluster.KubeConfig.Clusters["cluster-1"].Server = "https://cluster-test.example.com/"

Expand Down Expand Up @@ -478,7 +478,7 @@ func TestAutomatedClusterDiscoveryReconciler(t *testing.T) {
secret := newSecret(types.NamespacedName{Name: "cluster-1-kubeconfig", Namespace: aksCluster.GetNamespace()})
gitopsCluster := newGitopsCluster(secret.GetName(), types.NamespacedName{Name: "cluster-1", Namespace: aksCluster.GetNamespace()})
assertInventoryHasItems(t, aksCluster, secret, gitopsCluster)
assertAutomatedClusterDiscoveryCondition(t, aksCluster, meta.ReadyCondition, "2 resources created")
assertAutomatedClusterDiscoveryCondition(t, aksCluster, meta.ReadyCondition, "1 clusters discovered")

assert.NoError(t, k8sClient.Delete(ctx, secret))
assert.NoError(t, k8sClient.Delete(ctx, gitopsCluster))
Expand Down

0 comments on commit df0aa8a

Please sign in to comment.