From 91f3d128a89423ace3c1728669f0e16e564db31d Mon Sep 17 00:00:00 2001 From: Gosha Date: Tue, 20 Jun 2023 09:19:03 +0300 Subject: [PATCH 1/3] docs: minor fixes Signed-off-by: Gosha --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4356655a..21f6c2b8 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Welcome to Piper! Piper is open source project that aimed at providing multibran ## Getting Started -Piper configures a webhook in git provider and listens to the webhooks sends. It will create a Workflow CRD out of branches that contains `.workflows` folder. This folder should contain delclerations of the templates and main DAG that will be running. Finally it will submit the Workflow as a K8s resource in the cluster. For farther explantions please check [Usage](docs/usage.md) +Piper configures a webhook in git provider and listens to the webhooks sends. It will create a Workflow CRD out of branches that contains `.workflows` folder. This folder should contain declarations of the templates and main DAG that will be running. Finally, it will submit the Workflow as a K8s resource in the cluster. To access more detailed explanations, please navigate to the [Usage](docs/usage.md). ## Reporting Issues From 337681e324192931aad73844000f40b793efde3e Mon Sep 17 00:00:00 2001 From: Gosha Date: Thu, 22 Jun 2023 14:45:23 +0300 Subject: [PATCH 2/3] docs: add missing Installation file Signed-off-by: Gosha --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 21f6c2b8..bd046ade 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Welcome to Piper! Piper is open source project that aimed at providing multibran ## Table of Contents - [Getting Started](#getting-started) +- [Installation](docs/installation.md) - [Usage](docs/usage.md) - [Reporting Issues](#reporting-issues) - [How to Contribute](docs/CONTRIBUTING.md#how-to-contribute) From 36e066f8f738547af825b7833d97f9f4c4750f08 Mon Sep 17 00:00:00 2001 From: Eli Hatamov <86779379+EliRookout@users.noreply.github.com> Date: Thu, 22 Jun 2023 18:14:20 +0300 Subject: [PATCH 3/3] fix: refactor names (#51) Signed-off-by: Eli Hatamov --- cmd/piper/piper.go | 26 ++++++------- pkg/clients/types.go | 8 ++-- pkg/common/types.go | 12 +++--- pkg/conf/conf.go | 14 +++---- pkg/conf/{git.go => git_provider.go} | 4 +- pkg/conf/{argo.go => workflow_server.go} | 4 +- pkg/conf/workflows_config.go | 4 +- pkg/{git => git_provider}/github.go | 38 +++++++++---------- pkg/{git => git_provider}/github_utils.go | 14 +++---- .../github_utils_test.go | 6 +-- pkg/{git => git_provider}/main.go | 8 ++-- pkg/{git => git_provider}/test_utils.go | 2 +- pkg/{git => git_provider}/types.go | 2 +- pkg/server/routes/healthz.go | 2 +- pkg/server/routes/webhook.go | 6 +-- pkg/server/server.go | 4 +- .../types.go | 0 .../webhook_handler.go | 24 ++++++------ .../types.go | 0 .../workflows.go | 20 +++++----- .../workflows_utils.go | 8 ++-- .../workflows_utils_test.go | 6 +-- 22 files changed, 106 insertions(+), 106 deletions(-) rename pkg/conf/{git.go => git_provider.go} (89%) rename pkg/conf/{argo.go => workflow_server.go} (86%) rename pkg/{git => git_provider}/github.go (86%) rename pkg/{git => git_provider}/github_utils.go (89%) rename pkg/{git => git_provider}/github_utils_test.go (91%) rename pkg/{git => git_provider}/main.go (60%) rename pkg/{git => git_provider}/test_utils.go (99%) rename pkg/{git => git_provider}/types.go (97%) rename pkg/{webhook-handler => webhook_handler}/types.go (100%) rename pkg/{webhook-handler => webhook_handler}/webhook_handler.go (85%) rename pkg/{workflow-handler => workflow_handler}/types.go (100%) rename pkg/{workflow-handler => workflow_handler}/workflows.go (88%) rename pkg/{workflow-handler => workflow_handler}/workflows_utils.go (81%) rename pkg/{workflow-handler => workflow_handler}/workflows_utils_test.go (87%) diff --git a/cmd/piper/piper.go b/cmd/piper/piper.go index a1b84bb7..f25e19c6 100644 --- a/cmd/piper/piper.go +++ b/cmd/piper/piper.go @@ -5,10 +5,10 @@ import ( "github.com/rookout/piper/pkg/clients" "github.com/rookout/piper/pkg/conf" - "github.com/rookout/piper/pkg/git" + "github.com/rookout/piper/pkg/git_provider" "github.com/rookout/piper/pkg/server" "github.com/rookout/piper/pkg/utils" - workflowHandler "github.com/rookout/piper/pkg/workflow-handler" + workflowHandler "github.com/rookout/piper/pkg/workflow_handler" rookout "github.com/Rookout/GoSDK" ) @@ -16,7 +16,7 @@ import ( func main() { cfg, err := conf.LoadConfig() if err != nil { - log.Fatalf("failed to load the configuration for Piper, error: %v", err) + log.Panicf("failed to load the configuration for Piper, error: %v", err) } if cfg.RookoutConfig.Token != "" { @@ -27,26 +27,26 @@ func main() { } } - err = cfg.WorkflowConfig.WorkflowsSpecLoad("/piper-config/..data") + err = cfg.WorkflowsConfig.WorkflowsSpecLoad("/piper-config/..data") if err != nil { - log.Fatalf("Failed to load workflow spec configuration, error: %v", err) + log.Panicf("Failed to load workflow spec configuration, error: %v", err) } - git, err := git.NewGitProviderClient(cfg) + gitProvider, err := git_provider.NewGitProviderClient(cfg) if err != nil { - log.Fatalf("failed to load the Git client for Piper, error: %v", err) + log.Panicf("failed to load the Git client for Piper, error: %v", err) } workflows, err := workflowHandler.NewWorkflowsClient(cfg) if err != nil { - log.Fatalf("failed to load the Argo Workflows client for Piper, error: %v", err) + log.Panicf("failed to load the Argo Workflows client for Piper, error: %v", err) } - clients := &clients.Clients{ - Git: git, - Workflows: workflows, + globalClients := &clients.Clients{ + GitProvider: gitProvider, + Workflows: workflows, } - err = clients.Git.SetWebhook() + err = globalClients.GitProvider.SetWebhook() if err != nil { panic(err) } @@ -56,5 +56,5 @@ func main() { // panic(err) //} - server.Start(cfg, clients) + server.Start(cfg, globalClients) } diff --git a/pkg/clients/types.go b/pkg/clients/types.go index d8975ad7..10aeea0a 100644 --- a/pkg/clients/types.go +++ b/pkg/clients/types.go @@ -1,11 +1,11 @@ package clients import ( - "github.com/rookout/piper/pkg/git" - workflowHandler "github.com/rookout/piper/pkg/workflow-handler" + "github.com/rookout/piper/pkg/git_provider" + "github.com/rookout/piper/pkg/workflow_handler" ) type Clients struct { - Git git.Client - Workflows workflowHandler.WorkflowsClient + GitProvider git_provider.Client + Workflows workflow_handler.WorkflowsClient } diff --git a/pkg/common/types.go b/pkg/common/types.go index 1a841459..0991ede7 100644 --- a/pkg/common/types.go +++ b/pkg/common/types.go @@ -1,14 +1,14 @@ package common import ( - "github.com/rookout/piper/pkg/git" + "github.com/rookout/piper/pkg/git_provider" ) type WorkflowsBatch struct { - OnStart []*git.CommitFile - OnExit []*git.CommitFile - Templates []*git.CommitFile - Parameters *git.CommitFile + OnStart []*git_provider.CommitFile + OnExit []*git_provider.CommitFile + Templates []*git_provider.CommitFile + Parameters *git_provider.CommitFile Config *string - Payload *git.WebhookPayload + Payload *git_provider.WebhookPayload } diff --git a/pkg/conf/conf.go b/pkg/conf/conf.go index af568a6b..a1cb21fc 100644 --- a/pkg/conf/conf.go +++ b/pkg/conf/conf.go @@ -5,14 +5,14 @@ import ( "github.com/kelseyhightower/envconfig" ) -type Config struct { - GitConfig - ArgoConfig +type GlobalConfig struct { + GitProviderConfig + WorkflowServerConfig RookoutConfig - WorkflowConfig + WorkflowsConfig } -func (cfg *Config) Load() error { +func (cfg *GlobalConfig) Load() error { err := envconfig.Process("", cfg) if err != nil { return fmt.Errorf("failed to load the configuration, error: %v", err) @@ -21,8 +21,8 @@ func (cfg *Config) Load() error { return nil } -func LoadConfig() (*Config, error) { - cfg := new(Config) +func LoadConfig() (*GlobalConfig, error) { + cfg := new(GlobalConfig) err := cfg.Load() if err != nil { diff --git a/pkg/conf/git.go b/pkg/conf/git_provider.go similarity index 89% rename from pkg/conf/git.go rename to pkg/conf/git_provider.go index f4e0b6aa..96aede17 100644 --- a/pkg/conf/git.go +++ b/pkg/conf/git_provider.go @@ -6,7 +6,7 @@ import ( "github.com/kelseyhightower/envconfig" ) -type GitConfig struct { +type GitProviderConfig struct { Provider string `envconfig:"GIT_PROVIDER" required:"true"` Token string `envconfig:"GIT_TOKEN" required:"true"` OrgName string `envconfig:"GIT_ORG_NAME" required:"true"` @@ -16,7 +16,7 @@ type GitConfig struct { WebhookSecret string `envconfig:"GIT_WEBHOOK_SECRET" required:"false"` } -func (cfg *GitConfig) GitConfLoad() error { +func (cfg *GitProviderConfig) GitConfLoad() error { err := envconfig.Process("", cfg) if err != nil { return fmt.Errorf("failed to load the Git provider configuration, error: %v", err) diff --git a/pkg/conf/argo.go b/pkg/conf/workflow_server.go similarity index 86% rename from pkg/conf/argo.go rename to pkg/conf/workflow_server.go index 70d45d25..876e0b36 100644 --- a/pkg/conf/argo.go +++ b/pkg/conf/workflow_server.go @@ -5,7 +5,7 @@ import ( "github.com/kelseyhightower/envconfig" ) -type ArgoConfig struct { +type WorkflowServerConfig struct { ArgoToken string `envconfig:"ARGO_WORKFLOWS_TOKEN" required:"true"` ArgoAddress string `envconfig:"ARGO_WORKFLOWS_ADDRESS" required:"true"` CreateCRD bool `envconfig:"ARGO_WORKFLOWS_CREATE_CRD" default:"true"` @@ -13,7 +13,7 @@ type ArgoConfig struct { KubeConfig string `envconfig:"KUBE_CONFIG" default:""` } -func (cfg *ArgoConfig) ArgoConfLoad() error { +func (cfg *WorkflowServerConfig) ArgoConfLoad() error { err := envconfig.Process("", cfg) if err != nil { return fmt.Errorf("failed to load the Argo configuration, error: %v", err) diff --git a/pkg/conf/workflows_config.go b/pkg/conf/workflows_config.go index f5ab907d..3841b7fe 100644 --- a/pkg/conf/workflows_config.go +++ b/pkg/conf/workflows_config.go @@ -7,7 +7,7 @@ import ( "github.com/rookout/piper/pkg/utils" ) -type WorkflowConfig struct { +type WorkflowsConfig struct { Configs map[string]*ConfigInstance } @@ -16,7 +16,7 @@ type ConfigInstance struct { OnExit []v1alpha1.DAGTask `yaml:"onExit"` } -func (wfc *WorkflowConfig) WorkflowsSpecLoad(configPath string) error { +func (wfc *WorkflowsConfig) WorkflowsSpecLoad(configPath string) error { var jsonBytes []byte wfc.Configs = make(map[string]*ConfigInstance) diff --git a/pkg/git/github.go b/pkg/git_provider/github.go similarity index 86% rename from pkg/git/github.go rename to pkg/git_provider/github.go index 00cf1615..cc22ec14 100644 --- a/pkg/git/github.go +++ b/pkg/git_provider/github.go @@ -1,4 +1,4 @@ -package git +package git_provider import ( "context" @@ -14,14 +14,14 @@ import ( type GithubClientImpl struct { client *github.Client - cfg *conf.Config + cfg *conf.GlobalConfig hooks []*github.Hook } -func NewGithubClient(cfg *conf.Config) (Client, error) { +func NewGithubClient(cfg *conf.GlobalConfig) (Client, error) { ctx := context.Background() - client := github.NewTokenClient(ctx, cfg.GitConfig.Token) + client := github.NewTokenClient(ctx, cfg.GitProviderConfig.Token) err := ValidatePermissions(ctx, client, cfg) if err != nil { return nil, fmt.Errorf("failed to validate permissions: %v", err) @@ -38,7 +38,7 @@ func (c *GithubClientImpl) ListFiles(ctx *context.Context, repo string, branch s var files []string opt := &github.RepositoryContentGetOptions{Ref: branch} - _, directoryContent, resp, err := c.client.Repositories.GetContents(*ctx, c.cfg.GitConfig.OrgName, repo, path, opt) + _, directoryContent, resp, err := c.client.Repositories.GetContents(*ctx, c.cfg.GitProviderConfig.OrgName, repo, path, opt) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func (c *GithubClientImpl) GetFile(ctx *context.Context, repo string, branch str var commitFile CommitFile opt := &github.RepositoryContentGetOptions{Ref: branch} - fileContent, _, resp, err := c.client.Repositories.GetContents(*ctx, c.cfg.GitConfig.OrgName, repo, path, opt) + fileContent, _, resp, err := c.client.Repositories.GetContents(*ctx, c.cfg.GitProviderConfig.OrgName, repo, path, opt) if err != nil { return &commitFile, err } @@ -104,20 +104,20 @@ func (c *GithubClientImpl) SetWebhook() error { ctx := context.Background() hook := &github.Hook{ Config: map[string]interface{}{ - "url": c.cfg.GitConfig.WebhookURL, + "url": c.cfg.GitProviderConfig.WebhookURL, "content_type": "json", - "secret": c.cfg.GitConfig.WebhookSecret, // TODO webhook from k8s secret + "secret": c.cfg.GitProviderConfig.WebhookSecret, // TODO webhook from k8s secret }, Events: []string{"push", "pull_request"}, Active: github.Bool(true), } - if c.cfg.GitConfig.OrgLevelWebhook { + if c.cfg.GitProviderConfig.OrgLevelWebhook { respHook, ok := isOrgWebhookEnabled(ctx, c) if !ok { retHook, resp, err := c.client.Organizations.CreateHook( ctx, - c.cfg.GitConfig.OrgName, + c.cfg.GitProviderConfig.OrgName, hook, ) if err != nil { @@ -130,7 +130,7 @@ func (c *GithubClientImpl) SetWebhook() error { } else { updatedHook, resp, err := c.client.Organizations.EditHook( ctx, - c.cfg.GitConfig.OrgName, + c.cfg.GitProviderConfig.OrgName, respHook.GetID(), hook, ) @@ -140,7 +140,7 @@ func (c *GithubClientImpl) SetWebhook() error { if resp.StatusCode != http.StatusOK { return fmt.Errorf( "failed to update org level webhhok for %s, API returned %d", - c.cfg.GitConfig.OrgName, + c.cfg.GitProviderConfig.OrgName, resp.StatusCode, ) } @@ -149,10 +149,10 @@ func (c *GithubClientImpl) SetWebhook() error { return nil } else { - for _, repo := range strings.Split(c.cfg.GitConfig.RepoList, ",") { + for _, repo := range strings.Split(c.cfg.GitProviderConfig.RepoList, ",") { respHook, ok := isRepoWebhookEnabled(ctx, c, repo) if !ok { - _, resp, err := c.client.Repositories.CreateHook(ctx, c.cfg.GitConfig.OrgName, repo, hook) + _, resp, err := c.client.Repositories.CreateHook(ctx, c.cfg.GitProviderConfig.OrgName, repo, hook) if err != nil { return err } @@ -162,7 +162,7 @@ func (c *GithubClientImpl) SetWebhook() error { } c.hooks = append(c.hooks, hook) } else { - updatedHook, resp, err := c.client.Repositories.EditHook(ctx, c.cfg.GitConfig.OrgName, repo, respHook.GetID(), hook) + updatedHook, resp, err := c.client.Repositories.EditHook(ctx, c.cfg.GitProviderConfig.OrgName, repo, respHook.GetID(), hook) if err != nil { return err } @@ -182,9 +182,9 @@ func (c *GithubClientImpl) UnsetWebhook() error { ctx := context.Background() for _, hook := range c.hooks { - if c.cfg.GitConfig.OrgLevelWebhook { + if c.cfg.GitProviderConfig.OrgLevelWebhook { - resp, err := c.client.Organizations.DeleteHook(ctx, c.cfg.GitConfig.OrgName, *hook.ID) + resp, err := c.client.Organizations.DeleteHook(ctx, c.cfg.GitProviderConfig.OrgName, *hook.ID) if err != nil { return err @@ -195,8 +195,8 @@ func (c *GithubClientImpl) UnsetWebhook() error { } } else { - for _, repo := range strings.Split(c.cfg.GitConfig.RepoList, ",") { - resp, err := c.client.Repositories.DeleteHook(ctx, c.cfg.GitConfig.OrgName, repo, *hook.ID) + for _, repo := range strings.Split(c.cfg.GitProviderConfig.RepoList, ",") { + resp, err := c.client.Repositories.DeleteHook(ctx, c.cfg.GitProviderConfig.OrgName, repo, *hook.ID) if err != nil { return fmt.Errorf("failed to delete repo level webhhok for %s, API call returned %d. %s", repo, resp.StatusCode, err) diff --git a/pkg/git/github_utils.go b/pkg/git_provider/github_utils.go similarity index 89% rename from pkg/git/github_utils.go rename to pkg/git_provider/github_utils.go index 87efa525..61f68743 100644 --- a/pkg/git/github_utils.go +++ b/pkg/git_provider/github_utils.go @@ -1,4 +1,4 @@ -package git +package git_provider import ( "context" @@ -14,7 +14,7 @@ import ( func isOrgWebhookEnabled(ctx context.Context, c *GithubClientImpl) (*github.Hook, bool) { emptyHook := github.Hook{} - hooks, resp, err := c.client.Organizations.ListHooks(ctx, c.cfg.GitConfig.OrgName, &github.ListOptions{}) + hooks, resp, err := c.client.Organizations.ListHooks(ctx, c.cfg.GitProviderConfig.OrgName, &github.ListOptions{}) if err != nil { return &emptyHook, false } @@ -25,7 +25,7 @@ func isOrgWebhookEnabled(ctx context.Context, c *GithubClientImpl) (*github.Hook return &emptyHook, false } for _, hook := range hooks { - if hook.GetActive() && hook.GetName() == "web" && hook.Config["url"] == c.cfg.GitConfig.WebhookURL { + if hook.GetActive() && hook.GetName() == "web" && hook.Config["url"] == c.cfg.GitProviderConfig.WebhookURL { return hook, true } } @@ -34,7 +34,7 @@ func isOrgWebhookEnabled(ctx context.Context, c *GithubClientImpl) (*github.Hook func isRepoWebhookEnabled(ctx context.Context, c *GithubClientImpl, repo string) (*github.Hook, bool) { emptyHook := github.Hook{} - hooks, resp, err := c.client.Repositories.ListHooks(ctx, c.cfg.GitConfig.OrgName, repo, &github.ListOptions{}) + hooks, resp, err := c.client.Repositories.ListHooks(ctx, c.cfg.GitProviderConfig.OrgName, repo, &github.ListOptions{}) if err != nil { return &emptyHook, false } @@ -46,7 +46,7 @@ func isRepoWebhookEnabled(ctx context.Context, c *GithubClientImpl, repo string) } for _, hook := range hooks { - if hook.GetActive() && hook.GetName() == "web" && hook.Config["url"] == c.cfg.GitConfig.WebhookURL { + if hook.GetActive() && hook.GetName() == "web" && hook.Config["url"] == c.cfg.GitProviderConfig.WebhookURL { return hook, true } } @@ -77,7 +77,7 @@ func GetScopes(ctx context.Context, client *github.Client) ([]string, error) { } -func ValidatePermissions(ctx context.Context, client *github.Client, cfg *conf.Config) error { +func ValidatePermissions(ctx context.Context, client *github.Client, cfg *conf.GlobalConfig) error { orgScopes := []string{"admin:org_hook"} repoAdminScopes := []string{"admin:repo_hook"} @@ -92,7 +92,7 @@ func ValidatePermissions(ctx context.Context, client *github.Client, cfg *conf.C return fmt.Errorf("permissions error: no scopes found for the github client") } - if cfg.GitConfig.OrgLevelWebhook { + if cfg.GitProviderConfig.OrgLevelWebhook { if utils.ListContains(orgScopes, scopes) { return nil } diff --git a/pkg/git/github_utils_test.go b/pkg/git_provider/github_utils_test.go similarity index 91% rename from pkg/git/github_utils_test.go rename to pkg/git_provider/github_utils_test.go index b4155b21..2b3f7758 100644 --- a/pkg/git/github_utils_test.go +++ b/pkg/git_provider/github_utils_test.go @@ -1,4 +1,4 @@ -package git +package git_provider import ( "context" @@ -37,8 +37,8 @@ func TestIsOrgWebhookEnabled(t *testing.T) { c := GithubClientImpl{ client: client, - cfg: &conf.Config{ - GitConfig: conf.GitConfig{ + cfg: &conf.GlobalConfig{ + GitProviderConfig: conf.GitProviderConfig{ OrgName: "test", WebhookURL: "https://bla.com", }, diff --git a/pkg/git/main.go b/pkg/git_provider/main.go similarity index 60% rename from pkg/git/main.go rename to pkg/git_provider/main.go index 34e7885b..d27207b7 100644 --- a/pkg/git/main.go +++ b/pkg/git_provider/main.go @@ -1,13 +1,13 @@ -package git +package git_provider import ( "fmt" "github.com/rookout/piper/pkg/conf" ) -func NewGitProviderClient(cfg *conf.Config) (Client, error) { +func NewGitProviderClient(cfg *conf.GlobalConfig) (Client, error) { - switch cfg.GitConfig.Provider { + switch cfg.GitProviderConfig.Provider { case "github": gitClient, err := NewGithubClient(cfg) if err != nil { @@ -16,5 +16,5 @@ func NewGitProviderClient(cfg *conf.Config) (Client, error) { return gitClient, nil } - return nil, fmt.Errorf("didn't find matching git provider %s", cfg.GitConfig.Provider) + return nil, fmt.Errorf("didn't find matching git provider %s", cfg.GitProviderConfig.Provider) } diff --git a/pkg/git/test_utils.go b/pkg/git_provider/test_utils.go similarity index 99% rename from pkg/git/test_utils.go rename to pkg/git_provider/test_utils.go index 90b6b0b4..9ac9fae0 100644 --- a/pkg/git/test_utils.go +++ b/pkg/git_provider/test_utils.go @@ -1,4 +1,4 @@ -package git +package git_provider import ( "fmt" diff --git a/pkg/git/types.go b/pkg/git_provider/types.go similarity index 97% rename from pkg/git/types.go rename to pkg/git_provider/types.go index 453f2895..409af67d 100644 --- a/pkg/git/types.go +++ b/pkg/git_provider/types.go @@ -1,4 +1,4 @@ -package git +package git_provider import ( "context" diff --git a/pkg/server/routes/healthz.go b/pkg/server/routes/healthz.go index 9459eb2f..567fca5f 100644 --- a/pkg/server/routes/healthz.go +++ b/pkg/server/routes/healthz.go @@ -8,7 +8,7 @@ import ( "github.com/gin-gonic/gin" ) -func AddHealthRoutes(cfg *conf.Config, rg *gin.RouterGroup) { +func AddHealthRoutes(cfg *conf.GlobalConfig, rg *gin.RouterGroup) { health := rg.Group("/healthz") health.GET("", func(c *gin.Context) { diff --git a/pkg/server/routes/webhook.go b/pkg/server/routes/webhook.go index 5b6bcf2f..eda8a0d1 100644 --- a/pkg/server/routes/webhook.go +++ b/pkg/server/routes/webhook.go @@ -7,15 +7,15 @@ import ( "github.com/gin-gonic/gin" "github.com/rookout/piper/pkg/clients" "github.com/rookout/piper/pkg/conf" - webhookHandler "github.com/rookout/piper/pkg/webhook-handler" + webhookHandler "github.com/rookout/piper/pkg/webhook_handler" ) -func AddWebhookRoutes(cfg *conf.Config, clients *clients.Clients, rg *gin.RouterGroup) { +func AddWebhookRoutes(cfg *conf.GlobalConfig, clients *clients.Clients, rg *gin.RouterGroup) { webhook := rg.Group("/webhook") webhook.POST("", func(c *gin.Context) { ctx := c.Copy().Request.Context() - webhookPayload, err := clients.Git.HandlePayload(c.Request, []byte(cfg.GitConfig.WebhookSecret)) + webhookPayload, err := clients.GitProvider.HandlePayload(c.Request, []byte(cfg.GitProviderConfig.WebhookSecret)) if err != nil { log.Println(err) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) diff --git a/pkg/server/server.go b/pkg/server/server.go index 9b4ae3a3..0916d6d8 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -10,7 +10,7 @@ import ( var router = gin.Default() -func Start(cfg *conf.Config, clients *clients.Clients) { +func Start(cfg *conf.GlobalConfig, clients *clients.Clients) { getRoutes(cfg, clients) err := router.Run() if err != nil { @@ -18,7 +18,7 @@ func Start(cfg *conf.Config, clients *clients.Clients) { } } -func getRoutes(cfg *conf.Config, clients *clients.Clients) { +func getRoutes(cfg *conf.GlobalConfig, clients *clients.Clients) { v1 := router.Group("/") routes.AddHealthRoutes(cfg, v1) routes.AddWebhookRoutes(cfg, clients, v1) diff --git a/pkg/webhook-handler/types.go b/pkg/webhook_handler/types.go similarity index 100% rename from pkg/webhook-handler/types.go rename to pkg/webhook_handler/types.go diff --git a/pkg/webhook-handler/webhook_handler.go b/pkg/webhook_handler/webhook_handler.go similarity index 85% rename from pkg/webhook-handler/webhook_handler.go rename to pkg/webhook_handler/webhook_handler.go index 76a666f3..bdce28b2 100644 --- a/pkg/webhook-handler/webhook_handler.go +++ b/pkg/webhook_handler/webhook_handler.go @@ -6,20 +6,20 @@ import ( "github.com/rookout/piper/pkg/clients" "github.com/rookout/piper/pkg/common" "github.com/rookout/piper/pkg/conf" - "github.com/rookout/piper/pkg/git" + "github.com/rookout/piper/pkg/git_provider" "github.com/rookout/piper/pkg/utils" "gopkg.in/yaml.v3" "log" ) type WebhookHandlerImpl struct { - cfg *conf.Config + cfg *conf.GlobalConfig clients *clients.Clients Triggers *[]Trigger - Payload *git.WebhookPayload + Payload *git_provider.WebhookPayload } -func NewWebhookHandler(cfg *conf.Config, clients *clients.Clients, payload *git.WebhookPayload) (*WebhookHandlerImpl, error) { +func NewWebhookHandler(cfg *conf.GlobalConfig, clients *clients.Clients, payload *git_provider.WebhookPayload) (*WebhookHandlerImpl, error) { var err error return &WebhookHandlerImpl{ @@ -39,7 +39,7 @@ func (wh *WebhookHandlerImpl) RegisterTriggers(ctx *context.Context) error { return fmt.Errorf(".workflows/triggers.yaml file does not exist in %s/%s", wh.Payload.Repo, wh.Payload.Branch) } - triggers, err := wh.clients.Git.GetFile(ctx, wh.Payload.Repo, wh.Payload.Branch, ".workflows/triggers.yaml") + triggers, err := wh.clients.GitProvider.GetFile(ctx, wh.Payload.Repo, wh.Payload.Branch, ".workflows/triggers.yaml") if err != nil { return fmt.Errorf("failed to get triggers content: %v", err) } @@ -71,7 +71,7 @@ func (wh *WebhookHandlerImpl) PrepareBatchForMatchingTriggers(ctx *context.Conte wh.Payload.Branch, ) triggered = true - onStartFiles, err := wh.clients.Git.GetFiles( + onStartFiles, err := wh.clients.GitProvider.GetFiles( ctx, wh.Payload.Repo, wh.Payload.Branch, @@ -84,9 +84,9 @@ func (wh *WebhookHandlerImpl) PrepareBatchForMatchingTriggers(ctx *context.Conte return nil, err } - onExitFiles := make([]*git.CommitFile, 0) + onExitFiles := make([]*git_provider.CommitFile, 0) if trigger.OnExit != nil { - onExitFiles, err = wh.clients.Git.GetFiles( + onExitFiles, err = wh.clients.GitProvider.GetFiles( ctx, wh.Payload.Repo, wh.Payload.Branch, @@ -100,9 +100,9 @@ func (wh *WebhookHandlerImpl) PrepareBatchForMatchingTriggers(ctx *context.Conte } } - templatesFiles := make([]*git.CommitFile, 0) + templatesFiles := make([]*git_provider.CommitFile, 0) if trigger.Templates != nil { - templatesFiles, err = wh.clients.Git.GetFiles( + templatesFiles, err = wh.clients.GitProvider.GetFiles( ctx, wh.Payload.Repo, wh.Payload.Branch, @@ -116,7 +116,7 @@ func (wh *WebhookHandlerImpl) PrepareBatchForMatchingTriggers(ctx *context.Conte } } - parameters, err := wh.clients.Git.GetFile( + parameters, err := wh.clients.GitProvider.GetFile( ctx, wh.Payload.Repo, wh.Payload.Branch, @@ -146,7 +146,7 @@ func (wh *WebhookHandlerImpl) PrepareBatchForMatchingTriggers(ctx *context.Conte } func IsFileExists(ctx *context.Context, wh *WebhookHandlerImpl, path string, file string) bool { - files, err := wh.clients.Git.ListFiles(ctx, wh.Payload.Repo, wh.Payload.Branch, path) + files, err := wh.clients.GitProvider.ListFiles(ctx, wh.Payload.Repo, wh.Payload.Branch, path) if err != nil { log.Printf("Error listing files in repo: %s branch: %s. %v", wh.Payload.Repo, wh.Payload.Branch, err) return false diff --git a/pkg/workflow-handler/types.go b/pkg/workflow_handler/types.go similarity index 100% rename from pkg/workflow-handler/types.go rename to pkg/workflow_handler/types.go diff --git a/pkg/workflow-handler/workflows.go b/pkg/workflow_handler/workflows.go similarity index 88% rename from pkg/workflow-handler/workflows.go rename to pkg/workflow_handler/workflows.go index 6ff95431..22556ab0 100644 --- a/pkg/workflow-handler/workflows.go +++ b/pkg/workflow_handler/workflows.go @@ -20,11 +20,11 @@ const ( type WorkflowsClientImpl struct { clientSet *wfClientSet.Clientset - cfg *conf.Config + cfg *conf.GlobalConfig } -func NewWorkflowsClient(cfg *conf.Config) (WorkflowsClient, error) { - restClientConfig, err := utils.GetClientConfig(cfg.ArgoConfig.KubeConfig) +func NewWorkflowsClient(cfg *conf.GlobalConfig) (WorkflowsClient, error) { + restClientConfig, err := utils.GetClientConfig(cfg.WorkflowServerConfig.KubeConfig) if err != nil { return nil, err } @@ -49,12 +49,12 @@ func (wfc *WorkflowsClientImpl) ConstructTemplates(workflowsBatch *common.Workfl return nil, err } if onExit == nil || len(onExit.DAG.Tasks) == 0 { - _, ok := wfc.cfg.WorkflowConfig.Configs[configName] - if ok && wfc.cfg.WorkflowConfig.Configs[configName].OnExit != nil { + _, ok := wfc.cfg.WorkflowsConfig.Configs[configName] + if ok && wfc.cfg.WorkflowsConfig.Configs[configName].OnExit != nil { template := &v1alpha1.Template{ Name: ONEXIT, DAG: &v1alpha1.DAGTemplate{ - Tasks: wfc.cfg.WorkflowConfig.Configs[configName].OnExit, + Tasks: wfc.cfg.WorkflowsConfig.Configs[configName].OnExit, }, } @@ -74,10 +74,10 @@ func (wfc *WorkflowsClientImpl) ConstructTemplates(workflowsBatch *common.Workfl func (wfc *WorkflowsClientImpl) ConstructSpec(templates []v1alpha1.Template, params []v1alpha1.Parameter, configName string) (*v1alpha1.WorkflowSpec, error) { finalSpec := &v1alpha1.WorkflowSpec{} - _, ok := wfc.cfg.WorkflowConfig.Configs[configName] + _, ok := wfc.cfg.WorkflowsConfig.Configs[configName] if ok { - *finalSpec = wfc.cfg.WorkflowConfig.Configs[configName].Spec - if len(wfc.cfg.WorkflowConfig.Configs[configName].OnExit) != 0 { + *finalSpec = wfc.cfg.WorkflowsConfig.Configs[configName].Spec + if len(wfc.cfg.WorkflowsConfig.Configs[configName].OnExit) != 0 { finalSpec.OnExit = ONEXIT } } @@ -130,7 +130,7 @@ func (wfc *WorkflowsClientImpl) Submit(ctx *context.Context, wf *v1alpha1.Workfl func (wfc *WorkflowsClientImpl) HandleWorkflowBatch(ctx *context.Context, workflowsBatch *common.WorkflowsBatch) error { var params []v1alpha1.Parameter var configName string - _, ok := wfc.cfg.WorkflowConfig.Configs["default"] + _, ok := wfc.cfg.WorkflowsConfig.Configs["default"] if ok { configName = "default" } diff --git a/pkg/workflow-handler/workflows_utils.go b/pkg/workflow_handler/workflows_utils.go similarity index 81% rename from pkg/workflow-handler/workflows_utils.go rename to pkg/workflow_handler/workflows_utils.go index 551e3100..843a1483 100644 --- a/pkg/workflow-handler/workflows_utils.go +++ b/pkg/workflow_handler/workflows_utils.go @@ -4,13 +4,13 @@ import ( "encoding/json" "fmt" "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" - "github.com/rookout/piper/pkg/git" + "github.com/rookout/piper/pkg/git_provider" "github.com/rookout/piper/pkg/utils" "gopkg.in/yaml.v3" "log" ) -func CreateDAGTemplate(fileList []*git.CommitFile, name string) (*v1alpha1.Template, error) { +func CreateDAGTemplate(fileList []*git_provider.CommitFile, name string) (*v1alpha1.Template, error) { if len(fileList) == 0 { log.Printf("empty file list for %s", name) return nil, nil @@ -38,7 +38,7 @@ func CreateDAGTemplate(fileList []*git.CommitFile, name string) (*v1alpha1.Templ return template, nil } -func AddFilesToTemplates(templates []v1alpha1.Template, files []*git.CommitFile) ([]v1alpha1.Template, error) { +func AddFilesToTemplates(templates []v1alpha1.Template, files []*git_provider.CommitFile) ([]v1alpha1.Template, error) { for _, f := range files { t := make([]v1alpha1.Template, 0) jsonBytes, err := utils.ConvertYAMLListToJSONList(*f.Content) @@ -55,7 +55,7 @@ func AddFilesToTemplates(templates []v1alpha1.Template, files []*git.CommitFile) return templates, nil } -func GetParameters(paramsFile *git.CommitFile) ([]v1alpha1.Parameter, error) { +func GetParameters(paramsFile *git_provider.CommitFile) ([]v1alpha1.Parameter, error) { var params []v1alpha1.Parameter err := yaml.Unmarshal([]byte(*paramsFile.Content), ¶ms) if err != nil { diff --git a/pkg/workflow-handler/workflows_utils_test.go b/pkg/workflow_handler/workflows_utils_test.go similarity index 87% rename from pkg/workflow-handler/workflows_utils_test.go rename to pkg/workflow_handler/workflows_utils_test.go index 2a251dd9..42bf08d6 100644 --- a/pkg/workflow-handler/workflows_utils_test.go +++ b/pkg/workflow_handler/workflows_utils_test.go @@ -2,7 +2,7 @@ package workflow_handler import ( "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" - "github.com/rookout/piper/pkg/git" + "github.com/rookout/piper/pkg/git_provider" assertion "github.com/stretchr/testify/assert" "testing" ) @@ -11,7 +11,7 @@ func TestAddFilesToTemplates(t *testing.T) { assert := assertion.New(t) template := make([]v1alpha1.Template, 0) - files := make([]*git.CommitFile, 0) + files := make([]*git_provider.CommitFile, 0) content := ` - name: local-step @@ -26,7 +26,7 @@ func TestAddFilesToTemplates(t *testing.T) { echo "{{ inputs.parameters.message }}" ` path := "path" - files = append(files, &git.CommitFile{ + files = append(files, &git_provider.CommitFile{ Content: &content, Path: &path, })