Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents podman site creation when unable to run the router image #1302

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 validation container: %s", err)
}
ci, err := cli.ContainerInspect(tempName)
if err != nil {
return fmt.Errorf("error inspecting validation container: %s", err)
}
if ci.ExitCode != 0 {
logs, err := cli.ContainerLogs(tempName)
if err != nil {
return fmt.Errorf("error executing validation container (unable to read logs) - exit code: %d", ci.ExitCode)
}
return fmt.Errorf("unable to run %s - reason: %s", ci.Image, logs)
}
return nil
}