Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the fix for deployment #501

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions capten/common-pkg/plugin-store/plugin_deployment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pluginstore
import (
"bytes"
"context"
"encoding/json"
"fmt"
"text/template"

Expand Down Expand Up @@ -48,10 +49,43 @@ func (p *PluginStore) UnDeployClusterPlugin(ctx context.Context, request *cluste
return nil
}

// func (p *PluginStore) deployPluginWithWorkflow(pluginData *clusterpluginspb.Plugin) {
// wd := workers.NewDeployment(p.tc, p.log)
// _, err := wd.SendEventV2(context.TODO(), wd.GetPluginWorkflowName(), string(model.AppInstallAction), pluginData)
// if err != nil {
// // pluginConfig.InstallStatus = string(model.AppIntallFailedStatus)
// // if err := a.pas.UpsertPluginConfig(pluginConfig); err != nil {
// // a.log.Errorf("failed to update plugin config for plugin %s, %v", pluginConfig.PluginName, err)
// // return
// // }
// p.log.Errorf("sendEventV2 failed, plugin: %s, reason: %v", pluginData.PluginName, err)
// return
// }
// // TODO: workflow will update the final status
// // Write a periodic scheduler which will go through all apps not in installed status and check the status till either success or failed.
// // Make SendEventV2 asynchrounous so that periodic scheduler will take care of monitoring.
// }

func (p *PluginStore) deployPluginWithWorkflow(pluginData *clusterpluginspb.Plugin) {
wd := workers.NewDeployment(p.tc, p.log)
_, err := wd.SendEventV2(context.TODO(), wd.GetPluginWorkflowName(), string(model.AppInstallAction), pluginData)

// Convert pluginData to a JSON string
pluginDataJSON, err := json.Marshal(pluginData)
if err != nil {
p.log.Errorf("failed to marshal pluginData: %s, reason: %v", pluginData.PluginName, err)
return
}

// Create a PluginDeployRequest instance
pluginDeployRequest := &model.PluginDeployRequest{
Data: string(pluginDataJSON),
}
//log.Println("Plugin Deploy Req", pluginDeployRequest.String())

// Ensure the payload is a model.DeployRequest
_, err = wd.SendEventV2(context.TODO(), wd.GetPluginWorkflowName(), string(model.AppInstallAction), pluginDeployRequest)
if err != nil {
// Uncomment and update the plugin configuration if needed
// pluginConfig.InstallStatus = string(model.AppIntallFailedStatus)
// if err := a.pas.UpsertPluginConfig(pluginConfig); err != nil {
// a.log.Errorf("failed to update plugin config for plugin %s, %v", pluginConfig.PluginName, err)
Expand All @@ -60,9 +94,6 @@ func (p *PluginStore) deployPluginWithWorkflow(pluginData *clusterpluginspb.Plug
p.log.Errorf("sendEventV2 failed, plugin: %s, reason: %v", pluginData.PluginName, err)
return
}
// TODO: workflow will update the final status
// Write a periodic scheduler which will go through all apps not in installed status and check the status till either success or failed.
// Make SendEventV2 asynchrounous so that periodic scheduler will take care of monitoring.
}

func (p *PluginStore) unInstallPluginWithWorkflow(request *clusterpluginspb.UnDeployClusterPluginRequest, plugin *clusterpluginspb.Plugin) {
Expand Down
2 changes: 1 addition & 1 deletion capten/common-pkg/workers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (d *Deployment) SendEventV2(
return nil, err
}

d.log.Infof("Sending event to temporal: workflow: %s, action: %s", workflowName, action)
d.log.Infof("Sending event to temporal: workflow: %s, action: %s, payload: %s", workflowName, action, string(deployPayloadJSON))
run, err := d.client.ExecuteWorkflow(ctx, options, workflowName, action, json.RawMessage(deployPayloadJSON))
if err != nil {
d.log.Errorf("failed to send event to workflow for plugin %s, %v", deployPayload.String(), err)
Expand Down
9 changes: 9 additions & 0 deletions capten/model/app_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ type DeployRequest interface {
String() string
}


type PluginDeployRequest struct {
Data string
}

func (p *PluginDeployRequest) String() string {
return p.Data
}

type AppConfig struct {
AppName string `json:"AppName,omitempty"`
Version string `json:"Version,omitempty"`
Expand Down
Loading