From 782984e161ba9eb7936141665b7dc9e73cd66a86 Mon Sep 17 00:00:00 2001 From: Fernando Giorgetti Date: Tue, 5 Dec 2023 11:43:02 -0300 Subject: [PATCH] Prevents podman site from being created when unable to run the router image (#1302) Fixes #1298. --- pkg/domain/podman/site.go | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/domain/podman/site.go b/pkg/domain/podman/site.go index 3af668726..4f025a3a9 100644 --- a/pkg/domain/podman/site.go +++ b/pkg/domain/podman/site.go @@ -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" @@ -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 } @@ -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 +}