Skip to content

Commit

Permalink
Prevents cli from throwing unexpected error when podman endpoint is n…
Browse files Browse the repository at this point in the history
…o longer available (#1222)

Fixes #1219.
  • Loading branch information
fgiorgetti authored and nluaces committed Dec 6, 2023
1 parent 05afcff commit 2348bb5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion client/podman/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewPodmanClient(endpoint, basePath string) (*PodmanRestClient, error) {
var err error

if endpoint == "" {
defaultEndpoint := fmt.Sprintf("unix://%s/podman/podman.sock", config.GetRuntimeDir())
defaultEndpoint := GetDefaultPodmanEndpoint()
endpoint = utils.DefaultStr(os.Getenv(ENV_PODMAN_ENDPOINT), defaultEndpoint)
}

Expand Down Expand Up @@ -143,6 +143,10 @@ func NewPodmanClient(endpoint, basePath string) (*PodmanRestClient, error) {
return cli, nil
}

func GetDefaultPodmanEndpoint() string {
return fmt.Sprintf("unix://%s/podman/podman.sock", config.GetRuntimeDir())
}

func (p *PodmanRestClient) IsSockEndpoint() bool {
return strings.HasPrefix(p.endpoint, "/") || strings.HasPrefix(p.endpoint, "unix://")
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/skupper/skupper_podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/skupperproject/skupper/api/types"
clientpodman "github.com/skupperproject/skupper/client/podman"
"github.com/skupperproject/skupper/pkg/domain/podman"
"github.com/skupperproject/skupper/test/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -83,13 +84,16 @@ func (s *SkupperPodman) NewClient(cmd *cobra.Command, args []string) {
// endpoint can be provided during init
var endpoint string
var isInitCmd bool
exitOnError := true
switch cmd.Name() {
case "init":
// require site not present
if len(args) == 1 {
endpoint = args[0]
}
isInitCmd = true
case "version":
exitOnError = false
default:
podmanCfg, err := podman.NewPodmanConfigFileHandler().GetConfig()
if err != nil {
Expand All @@ -101,8 +105,9 @@ func (s *SkupperPodman) NewClient(cmd *cobra.Command, args []string) {

c, err := clientpodman.NewPodmanClient(endpoint, "")
if err != nil {
if endpoint != "" {
fmt.Printf("Podman endpoint is not available: %s", endpoint)
if exitOnError {
fmt.Printf("Podman endpoint is not available: %s",
utils.StrDefault(endpoint, clientpodman.GetDefaultPodmanEndpoint()))
fmt.Println()
os.Exit(1)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/skupper/skupper_podman_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ func (s *SkupperPodmanSite) UpdateFlags(cmd *cobra.Command) {
func (s *SkupperPodmanSite) Version(cmd *cobra.Command, args []string) error {
site := s.podman.currentSite
if site == nil {
return fmt.Errorf("Skupper is not enabled for user '%s'", podman.Username)
fmt.Printf("Skupper is not enabled for user '%s'", podman.Username)
fmt.Println()
return nil
}
for _, deploy := range site.GetDeployments() {
for _, component := range deploy.GetComponents() {
Expand Down

0 comments on commit 2348bb5

Please sign in to comment.