Skip to content

Commit

Permalink
Make pod run before building fetchers
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Nov 6, 2023
1 parent e4877f0 commit bf560cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
23 changes: 20 additions & 3 deletions pkg/clients/exec_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,42 @@ func (c *ContainerCreationExecContext) refeshPod() error {
return nil
}

func (c *ContainerCreationExecContext) IsPodRunning() (bool, error) {
err := c.refeshPod()
if err != nil {
return false, err
}
if c.pod.Status.Phase == corev1.PodRunning {
return true, nil
}
return false, nil
}

func (c *ContainerCreationExecContext) WaitForPodToStart() error {
start := time.Now()
for time.Since(start) <= startTimeout {
err := c.refeshPod()
running, err := c.IsPodRunning()
if err != nil {
return err
}
if c.pod.Status.Phase == corev1.PodRunning {
if running {
return nil
}
}
return errors.New("timed out waiting for pod to start")
}

func (c *ContainerCreationExecContext) CreatePodAndWaitForStart() error {
err := c.CreatePod()
running, err := c.IsPodRunning()
if err != nil {
return err
}
if !running {
err := c.CreatePod()
if err != nil {
return err
}
}
return c.WaitForPodToStart()
}

Expand Down
19 changes: 8 additions & 11 deletions pkg/collectors/dpll_collector_netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func (dpll *DPLLNetlinkCollector) Start() error {
if err != nil {
return fmt.Errorf("dpll netlink collector failed to start pod: %w", err)
}
clockIDStuct, err := devices.GetClockID(dpll.ctx, dpll.interfaceName)
if err != nil {
return fmt.Errorf("dpll netlink collector failed to find clock id: %w", err)
}
err = devices.BuildDPLLNetlinkInfoFetcher(clockIDStuct.ClockID)
if err != nil {
return fmt.Errorf("failed to build fetcher for DPLLInfo %w", err)
}
return nil
}

Expand Down Expand Up @@ -92,19 +100,8 @@ func NewDPLLNetlinkCollector(constructor *CollectionConstructor) (Collector, err
return &DPLLNetlinkCollector{}, fmt.Errorf("failed to create DPLLNetlinkCollector: %w", err)
}

clockIDStuct, err := devices.GetClockID(ctx, constructor.PTPInterface)
if err != nil {
return &DPLLNetlinkCollector{}, fmt.Errorf("dpll netlink collector failed to find clock id: %w", err)
}

err = devices.BuildDPLLNetlinkInfoFetcher(clockIDStuct.ClockID)
if err != nil {
return &DPLLNetlinkCollector{}, fmt.Errorf("failed to build fetcher for DPLLInfo %w", err)
}

collector := DPLLNetlinkCollector{
interfaceName: constructor.PTPInterface,
clockID: clockIDStuct.ClockID,
ctx: ctx,
running: false,
callback: constructor.Callback,
Expand Down

0 comments on commit bf560cd

Please sign in to comment.