Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

refactor: removing the arguments arg from the run python delete flow because it isn't used #29

Merged
merged 4 commits into from
Oct 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion kontrol-service/engine/flow/dev_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func DeleteDevFlow(pluginRunner *plugins.PluginRunner, flowId string, service *r
for pluginIdx, plugin := range service.StatefulPlugins {
logrus.Infof("Attempting to delete flow for plugin '%v' on flow '%v'", plugin.Name, flowId)
pluginId := plugins.GetPluginId(flowId, service.ServiceID, pluginIdx)
err := pluginRunner.DeleteFlow(plugin.Name, pluginId, map[string]string{})
err := pluginRunner.DeleteFlow(plugin.Name, pluginId)
if err != nil {
logrus.Errorf("Error deleting flow: %v.", err)
return stacktrace.Propagate(err, "An error occurred while trying to call delete flow of plugin '%v' on service '%v' for flow '%v'", plugin.Name, service.ServiceID, flowId)
Expand Down
17 changes: 5 additions & 12 deletions kontrol-service/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (pr *PluginRunner) CreateFlow(pluginUrl string, serviceSpec corev1.ServiceS
return newDeploymentSpec, string(configMapBytes), nil
}

func (pr *PluginRunner) DeleteFlow(pluginUrl, flowUuid string, arguments map[string]string) error {
func (pr *PluginRunner) DeleteFlow(pluginUrl, flowUuid string) error {
repoPath, err := pr.getOrCloneRepo(pluginUrl)
if err != nil {
return fmt.Errorf("failed to get or clone repository: %v", err)
Expand All @@ -102,7 +102,7 @@ func (pr *PluginRunner) DeleteFlow(pluginUrl, flowUuid string, arguments map[str
return err
}

_, err = runPythonDeleteFlow(repoPath, configMap, flowUuid, arguments)
_, err = runPythonDeleteFlow(repoPath, configMap, flowUuid)
if err != nil {
return err
}
Expand Down Expand Up @@ -216,7 +216,8 @@ with open('%s', 'w') as f:
return string(resultBytes), nil
}

func runPythonDeleteFlow(repoPath, configMap, flowUuid string, arguments map[string]string) (string, error) {
func runPythonDeleteFlow(repoPath, configMap, flowUuid string) (string, error) {

scriptPath := filepath.Join(repoPath, "main.py")

if _, err := os.Stat(scriptPath); os.IsNotExist(err) {
Expand All @@ -235,11 +236,6 @@ func runPythonDeleteFlow(repoPath, configMap, flowUuid string, arguments map[str
}
}

argsJSON, err := json.Marshal(arguments)
if err != nil {
return "", fmt.Errorf("failed to marshal arguments: %v", err)
}

tempResultFile, err := os.CreateTemp("", "result_*.json")
if err != nil {
return "", fmt.Errorf("failed to create temporary result file: %v", err)
Expand All @@ -255,7 +251,6 @@ import main

config_map = %s
flow_uuid = %q
args = json.loads('''%s''')
sig = inspect.signature(main.delete_flow)

kwargs = {}
Expand All @@ -264,8 +259,6 @@ for param in sig.parameters.values():
kwargs['flow_uuid'] = flow_uuid
elif param.name == 'config_map':
kwargs['config_map'] = config_map
elif param.name in args:
kwargs[param.name] = args[param.name]
elif param.default is not param.empty:
kwargs[param.name] = param.default
else:
Expand All @@ -277,7 +270,7 @@ result = main.delete_flow(**kwargs)
# Write the result to a temporary file
with open('%s', 'w') as f:
json.dump(result, f)
`, repoPath, configMap, flowUuid, argsJSON, tempResultFile.Name())
`, repoPath, configMap, flowUuid, tempResultFile.Name())

if err := executePythonScript(venvPath, repoPath, tempScript); err != nil {
return "", err
Expand Down
8 changes: 4 additions & 4 deletions kontrol-service/plugins/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestSimplePlugin(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "helloworld", configMapData["original_text"])

err = runner.DeleteFlow(simplePlugin, flowUuid, map[string]string{})
err = runner.DeleteFlow(simplePlugin, flowUuid)
require.NoError(t, err)

// Verify that the flow UUID was removed from memory
Expand All @@ -120,7 +120,7 @@ func TestIdentityPlugin(t *testing.T) {
require.NoError(t, err)
require.Equal(t, map[string]interface{}{}, configMapData)

err = runner.DeleteFlow(identityPlugin, flowUuid, map[string]string{})
err = runner.DeleteFlow(identityPlugin, flowUuid)
require.NoError(t, err)

// Verify that the flow UUID was removed from memory
Expand All @@ -146,7 +146,7 @@ func TestComplexPlugin(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "ip_addr", configMapData["original_value"])

err = runner.DeleteFlow(complexPlugin, flowUuid, map[string]string{})
err = runner.DeleteFlow(complexPlugin, flowUuid)
require.NoError(t, err)

// Verify that the flow UUID was removed from memory
Expand All @@ -171,7 +171,7 @@ func TestRedisPluginTest(t *testing.T) {
require.NoError(t, err)
require.Empty(t, configMapData)

err = runner.DeleteFlow(complexPlugin, flowUuid, map[string]string{})
err = runner.DeleteFlow(complexPlugin, flowUuid)
require.NoError(t, err)

// Verify that the flow UUID was removed from memory
Expand Down
Loading