Skip to content

Commit

Permalink
feat(hatchery/openstack): list worker IP (#6702)
Browse files Browse the repository at this point in the history
Signed-off-by: francois.samin <[email protected]>
  • Loading branch information
fsamin authored Nov 27, 2023
1 parent a441cd4 commit 5e541e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions engine/hatchery/openstack/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/rockbears/log"

"github.com/ovh/cds/sdk"
cdslog "github.com/ovh/cds/sdk/log"
)

// Find image ID from image name
Expand Down Expand Up @@ -53,7 +54,7 @@ func (h *HatcheryOpenstack) getSmallerFlavorThan(flavor flavors.Flavor) flavors.

func (h *HatcheryOpenstack) getImages(ctx context.Context) []images.Image {
t := time.Now()
defer log.Debug(ctx, "getImages(): %fs", time.Since(t).Seconds())
defer func() { log.Debug(ctx, "getImages(): %fs", time.Since(t).Seconds()) }()

is, expired := h.cache.Getimages()
if len(is) > 0 && !expired {
Expand Down Expand Up @@ -91,7 +92,7 @@ func (h *HatcheryOpenstack) refreshImagesCache(ctx context.Context) error {

func (h *HatcheryOpenstack) getServers(ctx context.Context) []servers.Server {
t := time.Now()
defer log.Debug(ctx, "getServers() : %fs", time.Since(t).Seconds())
defer func() { log.Debug(ctx, "getServers() : %fs", time.Since(t).Seconds()) }()

srvs, expired := h.cache.GetServers()
if len(srvs) > 0 && !expired {
Expand All @@ -107,6 +108,7 @@ func (h *HatcheryOpenstack) getServers(ctx context.Context) []servers.Server {
}

func (h *HatcheryOpenstack) refreshServersCache(ctx context.Context) error {
ctx = context.WithValue(ctx, cdslog.Component, "refreshServersCache")
all, err := servers.List(h.openstackClient, nil).AllPages()
if err != nil {
return sdk.WrapError(err, "cannot list openstack servers")
Expand All @@ -125,6 +127,7 @@ func (h *HatcheryOpenstack) refreshServersCache(ctx context.Context) error {
if workerHatcheryName == "" || workerHatcheryName != h.Name() {
continue
}
log.Info(ctx, "worker %q (status=%s) IP %q", s.Name, s.Status, s.AccessIPv4)
filteredServerList = append(filteredServerList, s)
}

Expand Down
4 changes: 3 additions & 1 deletion sdk/log/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
NodeRunID = log.Field("node_run_id")
PermJobID = log.Field("permJobID")
Workflow = log.Field("workflow")
Component = log.Field("component")
)

func init() {
Expand All @@ -65,6 +66,7 @@ func init() {
AuthSessionIAT,
AuthSessionTokenID,
Commit,
Component,
Deprecated,
Duration,
Goroutine,
Expand Down Expand Up @@ -92,7 +94,7 @@ func init() {
AnalyzeID,
NodeRunID,
PermJobID,
Workflow,
Workflow,
)
}

Expand Down

0 comments on commit 5e541e1

Please sign in to comment.