Skip to content

Commit

Permalink
Merge pull request #423 from kube-tarian/get-plugin-val
Browse files Browse the repository at this point in the history
get plugin values from plugin store project
  • Loading branch information
vramk23 authored Mar 12, 2024
2 parents c7e81ae + ef4d08b commit cc84cc3
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions server/pkg/plugin-store/plugin_store_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pluginstore
import (
"fmt"
"os"
"strings"

"github.com/intelops/go-common/logging"
"github.com/kelseyhightower/envconfig"
Expand Down Expand Up @@ -37,7 +38,16 @@ func (p *PluginStore) ConfigureStore(clusterId string, config *pluginstorepb.Plu

func (p *PluginStore) GetStoreConfig(clusterId string, storeType pluginstorepb.StoreType) (*pluginstorepb.PluginStoreConfig, error) {
if storeType == pluginstorepb.StoreType_LOCAL_STORE {
return p.dbStore.ReadPluginStoreConfig(clusterId)
config, err := p.dbStore.ReadPluginStoreConfig(clusterId)
if err != nil {
if strings.Contains(err.Error(), "not found") {
return &pluginstorepb.PluginStoreConfig{
StoreType: pluginstorepb.StoreType_LOCAL_STORE,
}, nil
}
return nil, err
}
return config, nil
} else if storeType == pluginstorepb.StoreType_CENTRAL_STORE {
return &pluginstorepb.PluginStoreConfig{
StoreType: pluginstorepb.StoreType_CENTRAL_STORE,
Expand Down Expand Up @@ -141,7 +151,14 @@ func (p *PluginStore) GetPlugins(clusterId string, storeType pluginstorepb.Store
return nil, err
}

return p.dbStore.ReadPlugins(config.GitProjectId)
plugins, err := p.dbStore.ReadPlugins(config.GitProjectId)
if err != nil {
if strings.Contains(err.Error(), "not found") {
return []*pluginstorepb.Plugin{}, nil
}
return nil, err
}
return plugins, nil
}

func (p *PluginStore) GetPluginData(clusterId string, storeType pluginstorepb.StoreType, pluginName string) (*pluginstorepb.PluginData, error) {
Expand All @@ -155,7 +172,24 @@ func (p *PluginStore) GetPluginData(clusterId string, storeType pluginstorepb.St

func (p *PluginStore) GetPluginValues(clusterId string, storeType pluginstorepb.StoreType,
pluginName, version string) ([]byte, error) {
return nil, nil
config, err := p.GetStoreConfig(clusterId, storeType)
if err != nil {
return nil, err
}

pluginStoreDir, err := p.clonePluginStoreProject(config.GitProjectURL, config.GitProjectId)
if err != nil {
return nil, err
}
defer os.RemoveAll(pluginStoreDir)

pluginValuesPath := pluginStoreDir + "/" + p.cfg.PluginsStorePath + "/" + pluginName + "/" + version + "/" + "values.yaml"
p.log.Infof("Loading %s plugin values from %s", pluginName, pluginValuesPath)
pluginListData, err := os.ReadFile(pluginValuesPath)
if err != nil {
return nil, errors.WithMessage(err, "failed to read plugins values file")
}
return pluginListData, nil
}

func (p *PluginStore) DeployPlugin(clusterId string, storeType pluginstorepb.StoreType,
Expand Down

0 comments on commit cc84cc3

Please sign in to comment.