Skip to content

Commit

Permalink
Fix func names and refresh error
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Nov 29, 2023
1 parent 86cc8f8 commit 978dfad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
31 changes: 16 additions & 15 deletions pkg/clients/exec_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type Volume struct {
MountPath string
}

func (c *ContainerCreationExecContext) CreatePod() error {
func (c *ContainerCreationExecContext) createPod() error {
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: c.podName,
Expand Down Expand Up @@ -250,16 +250,15 @@ func (c *ContainerCreationExecContext) refeshPod() error {
if err != nil {
return err
}
if len(pods.Items) == 0 || len(pods.Items) > 1 {
// I don't think k8s allows more than one pod with the same name
return errors.New("found multiple pods with the same name")
if len(pods.Items) == 0 {
return fmt.Errorf("failed to find pod: %s", c.podName)
}
c.pod = &pods.Items[0]

return nil
}

func (c *ContainerCreationExecContext) IsPodRunning() (bool, error) {
func (c *ContainerCreationExecContext) isPodRunning() (bool, error) {
err := c.refeshPod()
if err != nil {
return false, err
Expand All @@ -270,39 +269,40 @@ func (c *ContainerCreationExecContext) IsPodRunning() (bool, error) {
return false, nil
}

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

func (c *ContainerCreationExecContext) CreatePodAndWaitForStart() error {
func (c *ContainerCreationExecContext) CreatePodAndWait() error {
var err error
running := false
if c.pod != nil {
running, err = c.IsPodRunning()
running, err = c.isPodRunning()
if err != nil {
return err
}
}
if !running {
err := c.CreatePod()
err := c.createPod()
if err != nil {
return err
}
}
return c.WaitForPodToStart()
return c.waitForPodToStart()
}

func (c *ContainerCreationExecContext) DeletePod() error {
func (c *ContainerCreationExecContext) deletePod() error {
deletePolicy := metav1.DeletePropagationForeground
err := c.clientset.K8sClient.CoreV1().Pods(c.pod.Namespace).Delete(
context.TODO(),
Expand All @@ -316,7 +316,7 @@ func (c *ContainerCreationExecContext) DeletePod() error {
return nil
}

func (c *ContainerCreationExecContext) WaitForPodToDelete() error {
func (c *ContainerCreationExecContext) waitForPodToDelete() error {
start := time.Now()
for time.Since(start) <= deletionTimeout {
pods, err := c.listPods(&metav1.ListOptions{})
Expand All @@ -332,16 +332,17 @@ func (c *ContainerCreationExecContext) WaitForPodToDelete() error {
if !found {
return nil
}
time.Sleep(time.Microsecond)
}
return errors.New("pod has not terminated within the timeout")
}

func (c *ContainerCreationExecContext) DeletePodAndWait() error {
err := c.DeletePod()
err := c.deletePod()
if err != nil {
return err
}
return c.WaitForPodToDelete()
return c.waitForPodToDelete()
}

func NewContainerCreationExecContext(
Expand Down
2 changes: 1 addition & 1 deletion pkg/collectors/dpll_collector_netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
// Start sets up the collector so it is ready to be polled
func (dpll *DPLLNetlinkCollector) Start() error {
dpll.running = true
err := dpll.ctx.CreatePodAndWaitForStart()
err := dpll.ctx.CreatePodAndWait()
if err != nil {
return fmt.Errorf("dpll netlink collector failed to start pod: %w", err)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ func (runner *CollectorRunner) start() {
for collectorName, collector := range runner.collectorInstances {
log.Debugf("start collector %v", collector)
err := collector.Start()
log.Info("collector:", collectorName, " start error: ", err)
utils.IfErrorExitOrPanic(err)

log.Debugf("Spawning collector: %v", collector)
Expand Down

0 comments on commit 978dfad

Please sign in to comment.