From 8c0cc1278cc4d84863b076b2014b9bc9d8805218 Mon Sep 17 00:00:00 2001 From: "Igor D.C" Date: Fri, 25 Sep 2020 22:31:11 +0000 Subject: Implement Terminate operation in DCM Also makes minor changes to non-terminate code as a side-effect of supporting the new Terminate operation (such as including tagContext in the LogicalCloudClient implementation of LogicalCloudManager interface). These changes are/will also be leveraged by other operations. Issue-ID: MULTICLOUD-1143 Change-Id: Idbd2ec9f6cf0e5584a0f51cf4c16144db56d9fa0 Signed-off-by: Igor D.C --- src/dcm/pkg/module/apply.go | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'src/dcm/pkg/module/apply.go') diff --git a/src/dcm/pkg/module/apply.go b/src/dcm/pkg/module/apply.go index dbcbf8ac..84eb7ef7 100644 --- a/src/dcm/pkg/module/apply.go +++ b/src/dcm/pkg/module/apply.go @@ -28,11 +28,16 @@ import ( "strings" "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/installappclient" log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller" pkgerrors "github.com/pkg/errors" "gopkg.in/yaml.v2" ) +// rsyncName denotes the name of the rsync controller +const rsyncName = "rsync" + type Resource struct { ApiVersion string `yaml:"apiVersion"` Kind string `yaml:"kind"` @@ -218,6 +223,45 @@ func createUserCSR(logicalcloud LogicalCloud) (string, error) { } +/* +queryDBAndSetRsyncInfo queries the MCO db to find the record the sync controller +and then sets the RsyncInfo global variable. +*/ +func queryDBAndSetRsyncInfo() (installappclient.RsyncInfo, error) { + client := controller.NewControllerClient() + vals, _ := client.GetControllers() + for _, v := range vals { + if v.Metadata.Name == rsyncName { + log.Info("Initializing RPC connection to resource synchronizer", log.Fields{ + "Controller": v.Metadata.Name, + }) + rsyncInfo := installappclient.NewRsyncInfo(v.Metadata.Name, v.Spec.Host, v.Spec.Port) + return rsyncInfo, nil + } + } + return installappclient.RsyncInfo{}, pkgerrors.Errorf("queryRsyncInfoInMCODB Failed - Could not get find rsync by name : %v", rsyncName) +} + +/* +callRsyncUninstall method shall take in the app context id and invoke the rsync service via grpc +*/ +func callRsyncUninstall(contextid interface{}) error { + rsyncInfo, err := queryDBAndSetRsyncInfo() + log.Info("Calling the Rsync ", log.Fields{ + "RsyncName": rsyncInfo.RsyncName, + }) + if err != nil { + return err + } + + appContextID := fmt.Sprintf("%v", contextid) + err = installappclient.InvokeUninstallApp(appContextID) + if err != nil { + return err + } + return nil +} + // TODO: // Install istio // Store user key for user creation @@ -422,3 +466,49 @@ func CreateEtcdContext(logicalcloud LogicalCloud, clusterList []Cluster, return nil } + +// TODO: rename these methods +// DestroyEtcdContext remove from rsync then delete appcontext and all resources +func DestroyEtcdContext(logicalcloud LogicalCloud, clusterList []Cluster, + quotaList []Quota) error { + + logicalCloudName := logicalcloud.MetaData.LogicalCloudName + // project := "test-project" // FIXME(igordc): temporary, need to do some rework in the LC structs + + _, ctxVal, err := NewLogicalCloudClient().GetLogicalCloudContext(logicalCloudName) + if err != nil { + return pkgerrors.Wrapf(err, "Error finding AppContext for Logical Cloud: %v", logicalCloudName) + } + + // call resource synchronizer to delete the CRs from every cluster of the logical cloud + err = callRsyncUninstall(ctxVal) + if err != nil { + return err + } + + // TODO: status handling for logical cloud after terminate: + // rsync updates the status of the appcontext to Terminated + // dcm should launch thread to observe status of appcontext before concluding logical cloud is terminated + // dcm should somewhat mimic the status tracking of rsync + // logical cloud might be in a non-applied non-terminated state for a long period of time......... + + // // remove the app context + // err = context.DeleteCompositeApp() + // if err != nil { + // return pkgerrors.Wrap(err, "Error deleting AppContext CompositeApp") + // } + + // remove the app context field from the cluster db record + // lckey := LogicalCloudKey{ + // LogicalCloudName: logicalcloud.MetaData.LogicalCloudName, + // Project: project, + // } + // err = db.DBconn.RemoveTag("orchestrator", lckey, "lccontext") + // if err != nil { + // log.Warn("Error removing AppContext from Logical Cloud", log.Fields{ + // "logical-cloud": logicalCloudName, + // }) + // } + + return nil +} -- cgit 1.2.3-korg