Skip to content

Commit

Permalink
chore: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Apr 8, 2022
1 parent acbe508 commit 9f84d3e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions runtime/kubernetes/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package kubernetes
import (
"context"
"fmt"
"k8s.io/client-go/tools/cache"
"time"

"github.com/go-vela/types/pipeline"
"github.com/go-vela/worker/runtime/kubernetes/apis/vela/v1alpha1"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"

// The k8s libraries have some quirks around yaml marshaling (see opts.go).
// So, just use the same library for all kubernetes-related YAML.
Expand Down Expand Up @@ -127,6 +127,7 @@ func (c *client) SetupBuild(ctx context.Context, b *pipeline.Build) error {
}
}

// initialize the PodTracker now that we have a Pod for it to track
tracker, err := NewPodTracker(c.Logger, c.Kubernetes, c.Pod, time.Second*30)
if err != nil {
return err
Expand Down Expand Up @@ -192,7 +193,7 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error {
}
}

// Populate the PodTracker caches
// Populate the PodTracker caches before creating the pipeline pod
c.PodTracker.Start(ctx.Done())
if ok := cache.WaitForCacheSync(ctx.Done(), c.PodTracker.PodSynced); !ok {
return fmt.Errorf("failed to wait for caches to sync")
Expand Down
2 changes: 2 additions & 0 deletions runtime/kubernetes/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io
func (c *client) WaitContainer(ctx context.Context, ctn *pipeline.Container) error {
c.Logger.Tracef("waiting for container %s", ctn.ID)

// get the containerTracker for this container
tracker, ok := c.PodTracker.Containers[ctn.ID]
if !ok {
return fmt.Errorf("containerTracker is missing for %s", ctn.ID)
Expand All @@ -339,6 +340,7 @@ func (p podTracker) inspectContainerStatuses(pod *v1.Pod) {

// iterate through each container in the pod
for _, cst := range pod.Status.ContainerStatuses {
// get the containerTracker for this container
tracker, ok := p.Containers[cst.Name]
if !ok {
// unknown container
Expand Down
4 changes: 3 additions & 1 deletion runtime/kubernetes/pod_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func NewPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Po
}
}

// initialize podTracker
tracker := podTracker{
Logger: log,
TrackedPod: trackedPod,
Expand All @@ -177,7 +178,8 @@ func NewPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Po
Containers: containers,
}

tracker.podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
// register event handler funcs in podInformer
podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: tracker.HandlePodAdd,
UpdateFunc: tracker.HandlePodUpdate,
DeleteFunc: tracker.HandlePodDelete,
Expand Down

0 comments on commit 9f84d3e

Please sign in to comment.