Skip to content

🍀 Proposal: Unify the entry of all plugins #1142

Closed

Description

@daniel-hutao

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!

Activity

  1. added
    good first issue
    hacktoberfest
    on Sep 29, 2022
  2. tobehardest commented on Mar 29, 2023

    @tobehardest

    Hello, I want to do this, can you assign it to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuehacktoberfest

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions