devstream icon indicating copy to clipboard operation
devstream copied to clipboard

:four_leaf_clover: `Proposal`: Unify the entry of all plugins

Open daniel-hutao opened this issue 3 years ago • 0 comments

What Would You Like to Add? Why Is This Needed?

The DevStream plugin template(dtm develop create-plugin --name=xxx) has been updated with #1135, but there are still many plugins in stock have structure or comments drifted.

e.g.

  • template (internal/pkg/develop/plugin/template/read.go)
package [[ .Name | format ]]

import (
	"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
	"github.com/devstream-io/devstream/internal/pkg/statemanager"
	"github.com/devstream-io/devstream/pkg/util/log"
)

func Read(options map[string]interface{}) (map[string]interface{}, error) {
	// Initialize Operator with Operations
	operator := &plugininstaller.Operator{
		PreExecuteOperations: plugininstaller.PreExecuteOperations{
			// TODO(dtm): Add your PreExecuteOperations here.
		},
		GetStateOperation: func(options plugininstaller.RawOptions) (statemanager.ResourceState, error) {
			// TODO(dtm): Add your GetStateOperation here.
			return nil, nil
		},
	}

	// Execute all Operations in Operator
	status, err := operator.Execute(plugininstaller.RawOptions(options))
	if err != nil {
		return nil, err
	}
	log.Debugf("Return map: %v", status)
	return status, nil
}
  • argocd/read.go (internal/pkg/plugin/argocd/read.go)
package argocd

import (
	"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
	"github.com/devstream-io/devstream/internal/pkg/plugininstaller/helm"
	"github.com/devstream-io/devstream/pkg/util/log"
)

const (
	ArgocdDefaultNamespace = "argocd"
)

func Read(options map[string]interface{}) (map[string]interface{}, error) {
	// Initialize Operator with Operations
	operator := &plugininstaller.Operator{
		PreExecuteOperations: plugininstaller.PreExecuteOperations{
			helm.SetDefaultConfig(&defaultHelmConfig),
			helm.Validate,
		},
		GetStateOperation: helm.GetPluginAllState,
	}

	// 2. get plugin status
	status, err := operator.Execute(plugininstaller.RawOptions(options))
	if err != nil {
		return nil, err
	}
	log.Debugf("Return map: %v", status)
	return status, nil
}

There are 2 optimization points:

  1. Remove unused constant:
const (
	ArgocdDefaultNamespace = "argocd"
)
  1. Change one line log:3.

line 23

from

// 2. get plugin status

to

// Execute all Operations in Operator

Design

I don't know how many plugins have this kind of problem(s), not affecting the functionality, but not elegant. I hope that all these kinds of problem(s) will be fixed.

Anything else

Happy hacking!

daniel-hutao avatar Sep 29 '22 12:09 daniel-hutao