Skip to content

Commit

Permalink
core: add some debug logging and fix small bugs
Browse files Browse the repository at this point in the history
adding logs to get debug start/stop confirmation
and also, fixing minior bugs.

Signed-off-by: subhamkrai <srai@redhat.com>
  • Loading branch information
subhamkrai committed May 22, 2023
1 parent 048417c commit 3beb1b2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/debug/start_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func startDebug(context *k8sutil.Context, clusterNamespace, deploymentName, alte
return err
}

pod, err := k8sutil.WaitForPodToRun(context, clusterNamespace, labelSelector)
if err != nil {
logging.Fatal(err)
}

logging.Info("Debug pod %s is ready use", pod.Name)
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/debug/stop_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ func stopDebug(context *k8sutil.Context, clusterNamespace, deploymentName string
if err := SetDeploymentScale(context, clusterNamespace, original_deployment_name, 1); err != nil {
return err
}
logging.Info("Successfully deleted debug deployment and restored deployment %q", original_deployment_name)
return nil
}
6 changes: 4 additions & 2 deletions pkg/k8sutil/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func WaitForPodToRun(ctx *Context, operatorNamespace, labelSelector string) (cor
if err != nil {
return corev1.Pod{}, fmt.Errorf("failed to list pods with labels matching %s", labelSelector)
}
if pod.Items[0].Status.Phase == corev1.PodRunning && pod.Items[0].DeletionTimestamp.IsZero() {
return pod.Items[0], nil
if len(pod.Items) != 0 {
if pod.Items[0].Status.Phase == corev1.PodRunning && pod.Items[0].DeletionTimestamp.IsZero() {
return pod.Items[0], nil
}
}

logging.Info("waiting for pod to be running")
Expand Down
2 changes: 2 additions & 0 deletions pkg/logging/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package logging

import (
"fmt"
"os"

"github.com/fatih/color"
)
Expand Down Expand Up @@ -48,4 +49,5 @@ func Fatal(err error, args ...interface{}) {
fmt.Print(red("Error: "))
fmt.Printf(err.Error(), args...)
fmt.Println()
os.Exit(1)
}

0 comments on commit 3beb1b2

Please sign in to comment.