From 324362e53ad83358341f807ea75292a2822eeb98 Mon Sep 17 00:00:00 2001 From: Igal Tsoiref Date: Mon, 20 Feb 2023 11:09:59 +0200 Subject: [PATCH] MGMT-13711: it takes the assisted-service few minutes to notice that the cluster installation is completed (#4988) Update trigger_timestamp on update finalization state when it get to 100% Update trigger_timestamp on upload ingress ca --- internal/bminventory/inventory_test.go | 11 +++++++ internal/bminventory/inventory_v2_handlers.go | 9 ++++++ internal/cluster/cluster.go | 3 ++ internal/cluster/progress_test.go | 29 +++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/internal/bminventory/inventory_test.go b/internal/bminventory/inventory_test.go index f35cbd96ee6..f79171e4a27 100644 --- a/internal/bminventory/inventory_test.go +++ b/internal/bminventory/inventory_test.go @@ -9207,6 +9207,7 @@ var _ = Describe("V2UploadClusterIngressCert test", func() { status := models.ClusterStatusInstalled c.Status = &status db.Save(&c) + data, err := os.Open("../../subsystem/test_kubeconfig") Expect(err).ShouldNot(HaveOccurred()) kubeConfigAsBytes, err := io.ReadAll(data) @@ -9217,11 +9218,21 @@ var _ = Describe("V2UploadClusterIngressCert test", func() { objectExists() mockS3Client.EXPECT().Download(ctx, kubeconfigNoingress).Return(kubeconfigFile, int64(0), nil).Times(1) mockS3Client.EXPECT().Upload(ctx, merged, kubeconfigObject).Return(nil) + + // validate triggeredMonitored timestamp is zero + Expect(c.TriggerMonitorTimestamp.IsZero()).To(Equal(true)) + generateReply := bm.V2UploadClusterIngressCert(ctx, installer.V2UploadClusterIngressCertParams{ ClusterID: clusterID, IngressCertParams: ingressCa, }) Expect(generateReply).Should(Equal(installer.NewV2UploadClusterIngressCertCreated())) + + // validate triggeredMonitored was updated + updated, err := common.GetClusterFromDB(db, clusterID, common.UseEagerLoading) + Expect(err).ToNot(HaveOccurred()) + Expect(updated.TriggerMonitorTimestamp.IsZero()).To(Equal(false)) + }) }) var _ = Describe("List clusters", func() { diff --git a/internal/bminventory/inventory_v2_handlers.go b/internal/bminventory/inventory_v2_handlers.go index 98861c9ec12..c3367f19e20 100644 --- a/internal/bminventory/inventory_v2_handlers.go +++ b/internal/bminventory/inventory_v2_handlers.go @@ -274,6 +274,15 @@ func (b *bareMetalInventory) V2UploadClusterIngressCert(ctx context.Context, par return installer.NewV2UploadClusterIngressCertCreated() } + // update trigger_monitor_timestamp in order to run cluster monitor for this cluster as fast as possible + updates := map[string]interface{}{ + "trigger_monitor_timestamp": time.Now(), + } + err = b.db.Model(&common.Cluster{}).Where("id = ?", cluster.ID.String()).UpdateColumns(updates).Error + if err != nil { + return common.NewApiError(http.StatusInternalServerError, err) + } + noingress := fmt.Sprintf("%s/%s-noingress", cluster.ID, constants.Kubeconfig) resp, _, err := b.objectHandler.Download(ctx, noingress) if err != nil { diff --git a/internal/cluster/cluster.go b/internal/cluster/cluster.go index 7d4b960454b..602371db856 100644 --- a/internal/cluster/cluster.go +++ b/internal/cluster/cluster.go @@ -868,6 +868,9 @@ func (m *Manager) UpdateFinalizingProgress(ctx context.Context, db *gorm.DB, clu "progress_finalizing_stage_percentage": finalizingStagePercentage, "progress_total_percentage": totalPercentage, } + if finalizingStagePercentage == 100 { + updates["trigger_monitor_timestamp"] = time.Now() + } return db.Model(&common.Cluster{}).Where("id = ?", cluster.ID.String()).UpdateColumns(updates).Error } diff --git a/internal/cluster/progress_test.go b/internal/cluster/progress_test.go index 67a8b21012f..fdfc62b6bc7 100644 --- a/internal/cluster/progress_test.go +++ b/internal/cluster/progress_test.go @@ -315,6 +315,35 @@ var _ = Describe("Progress bar test", func() { expectProgressToBe(&c, 0, 0, 75) }) }) + It("UpdateFinalizingProgress test - 100%", func() { + clusterId := strfmt.UUID(uuid.New().String()) + c := common.Cluster{ + Cluster: models.Cluster{ + ID: &clusterId, + MonitoredOperators: []*models.MonitoredOperator{ + { + Name: operators.OperatorConsole.Name, + OperatorType: models.OperatorTypeBuiltin, + Status: models.OperatorStatusAvailable, + }, + { + Name: operators.OperatorCVO.Name, + OperatorType: models.OperatorTypeBuiltin, + Status: models.OperatorStatusAvailable, + }, + }, + }, + } + Expect(db.Create(&c).Error).ShouldNot(HaveOccurred()) + err := clusterApi.UpdateFinalizingProgress(ctx, db, clusterId) + Expect(err).NotTo(HaveOccurred()) + + c = getClusterFromDB(clusterId, db) + expectProgressToBe(&c, 0, 0, 100) + // validate triggeredMonitored was updated + Expect(c.TriggerMonitorTimestamp.IsZero()).To(Equal(false)) + + }) Context("update progress on transition", func() {