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

queue new apps when the manifests show up #93

Merged
merged 24 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions cmd/controller_cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"os"
"os/signal"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/zapier/kubechecks/pkg"
"github.com/zapier/kubechecks/pkg/config"
"github.com/zapier/kubechecks/pkg/events"
"github.com/zapier/kubechecks/pkg/repo"
"github.com/zapier/kubechecks/pkg/server"
)

Expand All @@ -24,13 +26,28 @@ var ControllerCmd = &cobra.Command{
Short: "Start the VCS Webhook handler.",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Starting KubeChecks:", pkg.GitTag, pkg.GitCommit)
clientType := viper.GetString("vcs-type")
client, err := createVCSClient(clientType)
if err != nil {
log.Fatal().Err(err).Msg("failed to create vcs client")
}

server := server.NewServer(&config.ServerConfig{
cfg := config.ServerConfig{
UrlPrefix: viper.GetString("webhook-url-prefix"),
WebhookSecret: viper.GetString("webhook-secret"),
})
go server.Start()
VcsClient: client,
}

log.Info().Msg("Initializing git settings")
if err := repo.InitializeGitSettings(cfg.VcsClient.Username(), cfg.VcsClient.Email()); err != nil {
log.Fatal().Err(err).Msg("failed to initialize git settings")
}

fmt.Println("Starting KubeChecks:", pkg.GitTag, pkg.GitCommit)
server := server.NewServer(&cfg)

ctx := context.Background()
go server.Start(ctx)

// graceful termination handler.
// when we receive a SIGTERM from kubernetes, check for in-flight requests before exiting.
Expand Down
52 changes: 52 additions & 0 deletions cmd/process.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cmd

import (
"context"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/zapier/kubechecks/pkg/config"
"github.com/zapier/kubechecks/pkg/server"
)

var processCmd = &cobra.Command{
Use: "process",
Short: "Process a pull request",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
ctx := context.TODO()

log.Info().Msg("building apps map from argocd")
result, err := config.BuildAppsMap(ctx)
if err != nil {
log.Fatal().Err(err).Msg("failed to build apps map")
}

clientType := viper.GetString("vcs-type")
client, err := createVCSClient(clientType)
if err != nil {
log.Fatal().Err(err).Msg("failed to create vcs client")
}

cfg := config.ServerConfig{
UrlPrefix: "--unused--",
WebhookSecret: "--unused--",
VcsToArgoMap: result,
VcsClient: client,
}

repo, err := client.LoadHook(ctx, args[0])
if err != nil {
log.Fatal().Err(err).Msg("failed to load hook")
return
}

server.ProcessCheckEvent(ctx, repo, &cfg)
},
}

func init() {
RootCmd.AddCommand(processCmd)
}
20 changes: 20 additions & 0 deletions cmd/vcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"fmt"

"github.com/zapier/kubechecks/pkg/vcs"
"github.com/zapier/kubechecks/pkg/vcs/github_client"
"github.com/zapier/kubechecks/pkg/vcs/gitlab_client"
)

func createVCSClient(clientType string) (vcs.Client, error) {
switch clientType {
case "gitlab":
return gitlab_client.CreateGitlabClient()
case "github":
return github_client.CreateGithubClient()
default:
return nil, fmt.Errorf("unknown vcs type: %s", clientType)
}
}
124 changes: 0 additions & 124 deletions pkg/affected_apps/best_effort.go

This file was deleted.

Loading
Loading