Skip to content
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
2 changes: 1 addition & 1 deletion pkg/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Start(ctx context.Context, stop context.CancelFunc, cfg *conf.GlobalConfig,

srv := NewServer(cfg, clients)
gracefulShutdownHandler := NewGracefulShutdown(ctx, stop)
srv.Start()
srv.Start(ctx)

gracefulShutdownHandler.Shutdown(srv)

Expand Down
10 changes: 6 additions & 4 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"context"
"github.com/gin-gonic/gin"
"github.com/quickube/piper/pkg/clients"
"github.com/quickube/piper/pkg/conf"
Expand Down Expand Up @@ -28,6 +29,7 @@ func (s *Server) startServer() *http.Server {
}

go func() {
log.Printf("Server is listening on %s", s.httpServer.Addr)
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %s\n", err)
}
Expand All @@ -53,18 +55,18 @@ func (s *Server) getRoutes() {
routes.AddWebhookRoutes(s.config, s.clients, v1, s.webhookCreator)
}

func (s *Server) startServices() {
s.webhookCreator.Start()
func (s *Server) startServices(ctx context.Context) {
s.webhookCreator.Start(ctx)
}

func (s *Server) Start() {
func (s *Server) Start(ctx context.Context) {

s.registerMiddlewares()

s.getRoutes()

s.httpServer = s.startServer()

s.startServices()
s.startServices(ctx)

}
7 changes: 3 additions & 4 deletions pkg/webhook_creator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func (wc *WebhookCreatorImpl) GetHooks() *map[int64]*git_provider.HookWithStatus
return &wc.hooks
}

func (wc *WebhookCreatorImpl) Start() {
func (wc *WebhookCreatorImpl) Start(ctx context.Context) {

err := wc.initWebhooks()
err := wc.initWebhooks(ctx)
if err != nil {
log.Print(err)
panic("failed in initializing webhooks")
Expand Down Expand Up @@ -85,9 +85,8 @@ func (wc *WebhookCreatorImpl) setAllHooksHealth(status bool) {
log.Printf("set all hooks health status for to %s", strconv.FormatBool(status))
}

func (wc *WebhookCreatorImpl) initWebhooks() error {
func (wc *WebhookCreatorImpl) initWebhooks(ctx context.Context) error {

ctx := context.Background()
if wc.cfg.GitProviderConfig.OrgLevelWebhook && len(wc.cfg.GitProviderConfig.RepoList) != 0 {
return fmt.Errorf("org level webhook wanted but provided repositories list")
} else if !wc.cfg.GitProviderConfig.OrgLevelWebhook && len(wc.cfg.GitProviderConfig.RepoList) == 0 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/webhook_creator/tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestWebhookCreatorImpl_SetAllHooksHealth(t *testing.T) {

func TestWebhookCreatorImpl_InitWebhooks(t *testing.T) {
assertion := assert.New(t)
ctx := context.Background()
// Mock the necessary methods of the GitProvider client
mockClient := &MockGitProviderClient{
SetWebhookFunc: func(ctx context.Context, repoName *string) (*git_provider.HookWithStatus, error) {
Expand All @@ -149,7 +150,7 @@ func TestWebhookCreatorImpl_InitWebhooks(t *testing.T) {
})

// Initialize the webhooks
err := wc.initWebhooks()
err := wc.initWebhooks(ctx)

// Run tests
assertion.NoError(err)
Expand Down
Loading