Skip to content

Commit

Permalink
added suggested changes
Browse files Browse the repository at this point in the history
Signed-off-by: adarsh-jaiss <[email protected]>

added suggested changes

Signed-off-by: adarsh-jaiss <[email protected]>
  • Loading branch information
Adarsh-jaiss committed Sep 10, 2024
1 parent fe51c90 commit c6b61e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pkg/shp/cmd/build/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/shipwright-io/cli/pkg/shp/params"
"github.com/spf13/cobra"

k8serrors "k8s.io/apimachinery/pkg/api/errors" // Import the k8serrors package
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
Expand Down Expand Up @@ -70,14 +71,18 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams
}
_, err = k8sclient.CoreV1().Namespaces().Get(c.cmd.Context(), params.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("namespace %s not found. Please ensure that the namespace exists and try again", params.Namespace())
if k8serrors.IsNotFound(err) {
fmt.Fprintf(io.Out, "Namespace '%s' not found. Please ensure that the namespace exists and try again.\n", params.Namespace())
return nil
}
return err
}

if buildList, err = clientset.ShipwrightV1alpha1().Builds(params.Namespace()).List(c.cmd.Context(), metav1.ListOptions{}); err != nil {
return err
}
if len(buildList.Items) == 0 {
fmt.Fprintf(io.Out, "No builds found in namespace '%s'. Please initiate a build or verify the namespace.\n", params.Namespace())
fmt.Fprintf(io.Out, "No builds found in namespace '%s'. Please create a build or verify the namespace.\n", params.Namespace())
return nil
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/shp/cmd/buildrun/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/spf13/cobra"
k8serrors "k8s.io/apimachinery/pkg/api/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/duration"
Expand Down Expand Up @@ -73,15 +74,19 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams
}
_, err = k8sclient.CoreV1().Namespaces().Get(c.cmd.Context(), params.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("namespace %s not found. Please ensure that the namespace exists and try again", params.Namespace())
if k8serrors.IsNotFound(err) {
fmt.Fprintf(io.Out, "Namespace '%s' not found. Please ensure that the namespace exists and try again.\n", params.Namespace())
return nil
}
return err
}

var brs *buildv1alpha1.BuildRunList
if brs, err = clientset.ShipwrightV1alpha1().BuildRuns(params.Namespace()).List(c.cmd.Context(), metav1.ListOptions{}); err != nil {
return err
}
if len(brs.Items) == 0 {
fmt.Fprintf(io.Out, "No buildruns found in namespace '%s'. Please initiate a buildrun or verify the namespace.\n", params.Namespace())
fmt.Fprintf(io.Out, "No buildruns found in namespace '%s'. Please create a buildrun or verify the namespace.\n", params.Namespace())
return nil
}

Expand Down

0 comments on commit c6b61e8

Please sign in to comment.