Skip to content

Commit

Permalink
setup /v2/skaffoldLogs endpoint (#5951)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarlonGamez authored Jun 5, 2021
1 parent f30fcc0 commit 20e00dc
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 136 deletions.
11 changes: 11 additions & 0 deletions pkg/skaffold/event/v2/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type eventHandler struct {
logLock sync.Mutex
applicationLogs []proto.Event
applicationLogsLock sync.Mutex
skaffoldLogs []proto.Event
skaffoldLogsLock sync.Mutex
cfg Config

iteration int
Expand All @@ -76,6 +78,7 @@ type eventHandler struct {
eventChan chan *proto.Event
eventListeners []*listener
applicationLogListeners []*listener
skaffoldLogListeners []*listener
}

type listener struct {
Expand All @@ -101,6 +104,10 @@ func ForEachApplicationLog(callback func(*proto.Event) error) error {
return handler.forEachApplicationLog(callback)
}

func ForEachSkaffoldLog(callback func(*proto.Event) error) error {
return handler.forEachSkaffoldLog(callback)
}

func Handle(event *proto.Event) error {
if event != nil {
handler.handle(event)
Expand Down Expand Up @@ -178,6 +185,10 @@ func (ev *eventHandler) forEachApplicationLog(callback func(*proto.Event) error)
return ev.forEach(&ev.applicationLogListeners, &ev.applicationLogs, &ev.applicationLogsLock, callback)
}

func (ev *eventHandler) forEachSkaffoldLog(callback func(*proto.Event) error) error {
return ev.forEach(&ev.skaffoldLogListeners, &ev.skaffoldLogs, &ev.skaffoldLogsLock, callback)
}

func emptyState(cfg Config) proto.State {
builds := map[string]string{}
for _, p := range cfg.GetPipelines() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/server/v2/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (s *Server) ApplicationLogs(_ *empty.Empty, stream proto.SkaffoldV2Service_
return event.ForEachApplicationLog(stream.Send)
}

func (s *Server) SkaffoldLogs(_ *empty.Empty, stream proto.SkaffoldV2Service_SkaffoldLogsServer) error {
return event.ForEachSkaffoldLog(stream.Send)
}

func (s *Server) Handle(ctx context.Context, e *proto.Event) (*empty.Empty, error) {
return &empty.Empty{}, event.Handle(e)
}
Expand Down
Loading

0 comments on commit 20e00dc

Please sign in to comment.