devstream icon indicating copy to clipboard operation
devstream copied to clipboard

:four_leaf_clover: `Proposal`: refactor plugin install method

Open steinliber opened this issue 2 years ago • 2 comments

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

We have many plugin install methods listed below currently

Install method plugin
Helm argocd, hashicorpvault, jenkins, kubeprometheus, openldap,tekton
Kubectl argocdapp,devlake
Docker gitlabcedocker
Github Client githubactions, jiragithub, reposcaffolding, trellogithub
Trello Client trello, trellogithub
GoClient zentao

The install method's code is separate in a different package, which makes it difficult to manage and extend the install method, we can extract these methods' code into a standalone package, like plugininstaller?

Design

  • put the Install method all in the same package like plugininstaller
  • define installerOption func
// this func input operation params and output operation and error
 type InstallerlOperation func (operation Operation) (Operation, error)
  • define plugin install step
func Create(options map[string]interface{}) (map[string]interface{}, error) {
	// 1. decode options
	var opts Options
        var retErr error
	if err := mapstructure.Decode(options, &opts); err != nil {
		return nil, err
	}
        // 2. define installOperator to install this plugin
	installers := []plugininstaller.InstallerOperation{
                // if func run normal, err is nil and these func will run by order
                // else interrupt execute and return err. just like kubernetes's admission controller logic
		plugininstaller.helm.ValidateBasic, 
		plugininstaller.kubeClient.CreateNameSpace,
		plugininstaller.helm.InstallOrUpdate,
	}

        // 3. run opt with installOperator list
       retErr = plugininstaller.Execute(opts, installers)

        // 4. get installed status
  	retMap := GetStaticState().ToStringInterfaceMap()
	log.Debugf("Return map: %v", retMap)

	return retMap, nil

steinliber avatar Jul 13 '22 15:07 steinliber

Maybe a todo list is needed here so that we can know the progress of the refactoring. @steinliber

e.g.

  • [x] task1
  • [ ] task2

daniel-hutao avatar Jul 28 '22 04:07 daniel-hutao

The rest of the plugins not using installer

  • [x] gitlabci
  • [x] jenkins
  • [x] jenkinspipelinekubernetes
  • [x] trello
  • [ ] trellogithub

steinliber avatar Jul 28 '22 04:07 steinliber