Skip to content

Commit

Permalink
delete plugins dropped plugins during synch
Browse files Browse the repository at this point in the history
  • Loading branch information
vramk23 committed Mar 31, 2024
1 parent 2ec593f commit e7d6e62
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func executeAppDeployment(
PluginName: req.PluginName,
PluginDescription: req.Description,
ApiEndpoint: apiEndpoint,
PluginStoreType: agentpb.PluginStoreType(req.StoreType),
},
Values: &agentpb.AppValues{
OverrideValues: req.OverrideValues,
Expand Down
20 changes: 20 additions & 0 deletions server/pkg/plugin-store/plugin_store_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,34 @@ func (p *PluginStore) SyncPlugins(orgId, clusterId string, storeType pluginstore
return errors.WithMessage(err, "failed to unmarshall store config file")
}

addedPlugins := map[string]bool{}
for _, pluginName := range plugins.Plugins {
err := p.addPluginApp(config.GitProjectId, pluginStoreDir, pluginName)
if err != nil {
p.log.Errorf("%v", err)
continue
}
addedPlugins[pluginName] = true
p.log.Infof("stored plugin data for plugin %s for cluster %s", pluginName, clusterId)
}

dbPlugins, err := p.dbStore.ReadPlugins(config.GitProjectId)
if err != nil {
if !strings.Contains(err.Error(), "not found") {
return err
}
}

for _, dbPlugin := range dbPlugins {
if _, ok := addedPlugins[dbPlugin.PluginName]; !ok {
if err = p.dbStore.DeletePlugin(config.GitProjectId, dbPlugin.PluginName); err != nil {
p.log.Infof("failed to deleted plugin data for plugin %s for cluster %s",
dbPlugin.PluginName, clusterId)
}
p.log.Infof("deleted plugin data for plugin %s for cluster %s", dbPlugin.PluginName, clusterId)
}
}

return nil
}

Expand Down
17 changes: 15 additions & 2 deletions server/pkg/store/astra/plugin_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
updatePluginData = `UPDATE %s.plugin_data SET last_updated_time = '%s', store_type = %d, description = '%s', category = '%s', icon = '%s', chart_name = '%s', chart_repo = '%s', versions = %v, default_namespace = '%s', privileged_namespace = %t, api_endpoint = '%s', ui_endpoint = '%s', capabilities = %v WHERE git_project_id = %s and plugin_name = '%s'`
readPlugins = `SELECT plugin_name, last_updated_time, store_type, description, category, icon, versions FROM %s.plugin_data WHERE git_project_id = %s`
readPluginDataForPluginName = `SELECT plugin_name, last_updated_time, store_type, description, category, icon, chart_name, chart_repo, versions, default_namespace, privileged_namespace, api_endpoint, ui_endpoint, capabilities FROM %s.plugin_data WHERE git_project_id = %s and plugin_name = '%s'`
deletePluginData = "DELETE FROM %s.plugin_data WHERE git_project_id = %s and plugin_name = '%s'"
)

func (a *AstraServerStore) WritePluginStoreConfig(clusterId string, config *pluginstorepb.PluginStoreConfig) error {
Expand Down Expand Up @@ -131,8 +132,7 @@ func (a *AstraServerStore) WritePluginData(gitProjectId string, pluginData *plug
if err != nil {
return fmt.Errorf("failed to update the plugin data, %s, %w", query.Cql, err)
}
a.log.Debugf("updated store plugin %s, %v", pluginData.PluginName)

a.log.Debugf("updated store plugin %s", pluginData.PluginName)
return nil
}

Expand Down Expand Up @@ -186,6 +186,19 @@ func (a *AstraServerStore) ReadPlugins(gitProjectId string) ([]*pluginstorepb.Pl
return plugins, nil
}

func (a *AstraServerStore) DeletePlugin(gitProjectId, pluginName string) error {
deleteQuery := &pb.Query{
Cql: fmt.Sprintf(deletePluginData, a.keyspace, gitProjectId, pluginName),
}

_, err := a.c.Session().ExecuteQuery(deleteQuery)
if err != nil {
return fmt.Errorf("failed to delete plugin, %w", err)
}

return nil
}

func toPluginData(row *pb.Row, columns []*pb.ColumnSpec) (*pluginstorepb.PluginData, error) {
pluginName, err := client.ToString(row.Values[0])
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions server/pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ServerStore interface {
WritePluginData(gitProjectId string, pluginData *pluginstorepb.PluginData) error
ReadPluginData(gitProjectId string, pluginName string) (*pluginstorepb.PluginData, error)
ReadPlugins(gitProjectId string) ([]*pluginstorepb.Plugin, error)
DeletePlugin(gitProjectId, pluginName string) error
}

func NewStore(log logging.Logger, db string) (ServerStore, error) {
Expand Down

0 comments on commit e7d6e62

Please sign in to comment.