diff options
author | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2022-02-15 22:39:37 +0100 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2022-03-02 22:46:03 +0100 |
commit | 5b18db4fc784763402e0898bf5e996886279347e (patch) | |
tree | 984a315638e1ef87841144fbb6a7e56484ffd12c /src/k8splugin/internal/app/instance.go | |
parent | a73b42b9c3877f1a34939d85941482f7f5c44db9 (diff) |
Implementation of status notification mechanism0.10.0
- Subscription CRUD endpoints
- Subscription notifu executor
- Cleanup of subscriptions on instance delete
- Sending notification to the specified callback
Issue-ID: MULTICLOUD-1445
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Change-Id: I5b867a348e916f6c2c471bcc5326c831d832f45e
Diffstat (limited to 'src/k8splugin/internal/app/instance.go')
-rw-r--r-- | src/k8splugin/internal/app/instance.go | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go index e78eea77..91e2150e 100644 --- a/src/k8splugin/internal/app/instance.go +++ b/src/k8splugin/internal/app/instance.go @@ -121,7 +121,7 @@ type InstanceManager interface { Upgrade(id string, u UpgradeRequest) (InstanceResponse, error) Get(id string) (InstanceResponse, error) GetFull(id string) (InstanceDbData, error) - Status(id string) (InstanceStatus, error) + Status(id string, checkReady bool) (InstanceStatus, error) Query(id, apiVersion, kind, name, labels string) (InstanceStatus, error) List(rbname, rbversion, profilename string) ([]InstanceMiniResponse, error) Find(rbName string, ver string, profile string, labelKeys map[string]string) ([]InstanceMiniResponse, error) @@ -813,7 +813,7 @@ func (v *InstanceClient) Query(id, apiVersion, kind, name, labels string) (Insta } // Status returns the status for the instance -func (v *InstanceClient) Status(id string) (InstanceStatus, error) { +func (v *InstanceClient) Status(id string, checkReady bool) (InstanceStatus, error) { //Read the status from the DB key := InstanceKey{ ID: id, @@ -867,12 +867,14 @@ Main: isReady = false } else { generalStatus = append(generalStatus, status) - ready, err := v.checkRssStatus(oneResource, k8sClient, resResp.Namespace, status) + if checkReady { + ready, err := v.checkRssStatus(oneResource, k8sClient, resResp.Namespace, status) - if !ready || err != nil { - isReady = false - if err != nil { - cumulatedErrorMsg = append(cumulatedErrorMsg, err.Error()) + if !ready || err != nil { + isReady = false + if err != nil { + cumulatedErrorMsg = append(cumulatedErrorMsg, err.Error()) + } } } } @@ -905,7 +907,7 @@ Main: resp := InstanceStatus{ Request: resResp.Request, ResourceCount: int32(len(generalStatus)), - Ready: isReady && resResp.Status == "DONE", + Ready: checkReady && isReady && resResp.Status == "DONE", ResourcesStatus: generalStatus, } @@ -914,7 +916,6 @@ Main: strings.Join(cumulatedErrorMsg, "\n")) return resp, err } - //TODO Filter response content by requested verbosity (brief, ...)? return resp, nil } @@ -925,7 +926,6 @@ func (v *InstanceClient) checkRssStatus(rss helm.KubernetesResource, k8sClient K defer cancel() apiVersion, kind := rss.GVK.ToAPIVersionAndKind() - log.Printf("apiVersion: %s, Kind: %s", apiVersion, kind) var parsedRes runtime.Object //TODO: Should we care about different api version for a same kind? @@ -1143,6 +1143,12 @@ func (v *InstanceClient) Delete(id string) error { } }() } else { + subscriptionClient := NewInstanceStatusSubClient() + err = subscriptionClient.Cleanup(id) + if err != nil { + log.Printf(err.Error()) + } + err = db.DBconn.Delete(v.storeName, key, v.tagInst) if err != nil { return pkgerrors.Wrap(err, "Delete Instance") @@ -1288,6 +1294,11 @@ func (v *InstanceClient) runPostDelete(k8sClient KubernetesClient, hookClient *H return pkgerrors.Wrap(err, "Error running post-delete hooks") } if clearDb { + subscriptionClient := NewInstanceStatusSubClient() + err = subscriptionClient.Cleanup(instance.ID) + if err != nil { + log.Printf(err.Error()) + } err = db.DBconn.Delete(v.storeName, key, v.tagInst) if err != nil { log.Printf("Delete Instance DB Entry for release %s has error.", instance.ReleaseName) |