Skip to content

Commit

Permalink
Prevents podman site from being created when unable to run the router…
Browse files Browse the repository at this point in the history
… image

Fixes skupperproject#1298.
  • Loading branch information
fgiorgetti committed Dec 1, 2023
1 parent e56ac97 commit ada6727
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/domain/podman/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"strings"
"time"

"github.com/google/uuid"
"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/client/container"
"github.com/skupperproject/skupper/client/podman"
"github.com/skupperproject/skupper/pkg/config"
"github.com/skupperproject/skupper/pkg/domain"
"github.com/skupperproject/skupper/pkg/images"
"github.com/skupperproject/skupper/pkg/qdr"
"github.com/skupperproject/skupper/pkg/utils"
"github.com/skupperproject/skupper/pkg/version"
Expand Down Expand Up @@ -428,6 +430,11 @@ func (s *SiteHandler) canCreate(site *Site) error {
return fmt.Errorf("You cannot use a remote podman endpoint - %w", err)
}

// Validating router container runs without errors
err = s.runTempContainer()
if err != nil {
return fmt.Errorf("site cannot be created: %s", err)
}
return nil
}

Expand Down Expand Up @@ -902,3 +909,41 @@ func (s *SiteHandler) createPrometheusConfigFiles(site *Site) error {
}
return nil
}

func (s *SiteHandler) runTempContainer() error {
cli := s.cli
err := cli.ImagePull(images.GetRouterImageName())
if err != nil {
return err
}
tempName := fmt.Sprintf("skupper-temp-%s", uuid.NewString()[:5])
err = cli.ContainerCreate(
&container.Container{
Name: tempName,
Image: images.GetRouterImageName(),
RestartPolicy: "no",
Command: []string{"skrouterd", "-version"},
},
)
if err != nil {
return fmt.Errorf("unable to validate container creation: %s", err)
}
defer func() {
_ = cli.ContainerRemove(tempName)
}()
if err = cli.ContainerStart(tempName); err != nil {
return fmt.Errorf("error starting validating container: %s", err)
}
ci, err := cli.ContainerInspect(tempName)
if err != nil {
return fmt.Errorf("error inspecting validating container: %s", err)
}
if ci.ExitCode != 0 {
logs, err := cli.ContainerLogs(tempName)
if err != nil {
return fmt.Errorf("error executing validating container (unable to read logs) - exit code: %d", ci.ExitCode)
}
return fmt.Errorf("unable to run %s - reason: %s", ci.Image, logs)
}
return nil
}

0 comments on commit ada6727

Please sign in to comment.