diff --git a/internal/model/database.go b/internal/model/database.go index 7eda5f6..f46fb1a 100644 --- a/internal/model/database.go +++ b/internal/model/database.go @@ -97,6 +97,9 @@ func (in *Database) SaveContainer(con *types.Container) error { if err != nil { return err } + if id[:1] == "c" { + id = "b" + id[1:] + } con.ID = id con.Created = time.Now() } diff --git a/internal/model/database_test.go b/internal/model/database_test.go index 31014f2..4e9974c 100644 --- a/internal/model/database_test.go +++ b/internal/model/database_test.go @@ -94,3 +94,17 @@ func TestDatabase(t *testing.T) { t.Errorf("Expected error when loading an exec that doesn't exist") } } + +func TestContainerIDWorkaround(t *testing.T) { + db, _ := New() + for i := 0; i < 1000; i++ { + con := &types.Container{} + if err := db.SaveContainer(con); err != nil { + t.Errorf("Unexpected error when creating a new container") + } + if con.ID[:1] == "c" { + t.Errorf("Container ID that start with a c cause problems in the server router setup...") + return + } + } +} diff --git a/internal/server/routes/main.go b/internal/server/routes/main.go index 24d9dbd..64d6d8c 100644 --- a/internal/server/routes/main.go +++ b/internal/server/routes/main.go @@ -30,8 +30,12 @@ func New(router *gin.Engine, kube kubernetes.Kubernetes) (*Router, error) { // initRoutes will add all suported routes. func (cr *Router) initRoutes(router *gin.Engine) { + // DEBT: "POST /containers/create" and "POST /containers/:id/start" overlap + // which (currently) means :id that start with a c will 404 by the router; + // as work around, no container-ids are generated that start with a 'c'... router.POST("/containers/create", cr.ContainerCreate) router.POST("/containers/:id/start", cr.ContainerStart) + router.GET("/containers/:id/json", cr.ContainerInfo) router.DELETE("/containers/:id", cr.ContainerDelete) router.POST("/containers/:id/exec", cr.ContainerExec)