Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitOps plugin system and a "kanvas" plugin placeholder #973

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

mumoshu
Copy link
Contributor

@mumoshu mumoshu commented Nov 16, 2023

This is the first step to add the support for kanvas as our alternative deployment tool usable by gocat.

We implement the interactor and the model for kanvas almost reusing our existing InteractorKustomize and ModelKustomize.

The differences between the kustomize and the kanvas supports are the "Prepare" function, which is used to edit the gitops config file in a Git repository and submit a pull request.

The kustomize support does so by using gocat-builtin kustomize support. The new kanvas support does so by calling kanvas.

In this change, we focus on refactoring and adding the placeholder for the kanvas support.

Once this is merged, we will keep adding the actual implementation, gradually replacing the placeholder to a full-fledged feature.

This is the first step to add the support for kanvas as our alternative deployment tool usable by gocat.

We implement the interactor and the model for kanvas almost reusing our existing InteractorKustomize and ModelKustomize.

The differences between the kustomize and the kanvas supports are the "Prepare" function, which is used to edit the gitops config file in a Git repository and submit a pull request.

The kustomize support does so by using gocat-builtin kustomize support. The new kanvas support does so by calling kanvas.

In this change, we focus on refactoring and adding the placeholder for the kanvas support.

Once this is merged, we will keep adding the actual implementation, gradually replacing the placeholder to a full-fledged feature.
@@ -5,31 +5,36 @@ import (
"strings"
)

type ModelKustomize struct {
type ModelGitOps struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We turn the existing ModelKustomize to a reusable Model implementation, that is used for building the kustomize model and the kanvas model.

github *GitHub
git *GitOperator
plugin GitOpsPlugin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we make it reusable; All the reusable logics reside within ModelGitOps, and tool-specific logic resides within each GitOpsPlugin like GitOpsPluginKustomize and GitOpsPluginKanvas.

A ModelGitOps instance along with GitOpsPluginKustomize works exactly same as the current ModelKustomize, so this change is backward-compatible.

InteractorContext
model ModelKustomize
model GitOpsPlugin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we make it reusable; All the reusable logics reside within InteractorGitOps, and tool-specific logic resides within each GitOpsPlugin like GitOpsPluginKustomize and GitOpsPluginKanvas.

A InteractorGitOps instance along with GitOpsPluginKustomize works exactly same as the current InteractorKustomize, so this change is backward-compatible.

This is about Interactor. For Model, see https://github.com/zaiminc/gocat/pull/973/files#r1395058220

func (self ModelKustomize) Deploy(pj DeployProject, phase string, option DeployOption) (do DeployOutput, err error) {
o, err := self.Prepare(pj, phase, option.Branch, option.Assigner, option.Tag)
func (self ModelGitOps) Deploy(pj DeployProject, phase string, option DeployOption) (do DeployOutput, err error) {
o, err := self.plugin.Prepare(pj, phase, option.Branch, option.Assigner, option.Tag)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy works in an implementation-specific way so we call out to the plugin's Prepare here.

This is the only implementation-specific part of ModelGitOps, and therefore this is the only place you see self.plugin.

For example, Commit above works regardless of the tool(kanvas, kustomize, and so on) so it doesn't call out to a plugin = no self.plugin usage.

Copy link
Contributor

@autumo autumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@pirlodog1125 pirlodog1125 merged commit 822d0fd into kufu-ai:master Nov 17, 2023
3 of 5 checks passed
mumoshu added a commit to mumoshu/gocat that referenced this pull request Nov 30, 2023
@mumoshu mumoshu deleted the gitops-plugin-kanvas branch November 30, 2023 01:09
mumoshu added a commit to mumoshu/gocat that referenced this pull request Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants