Skip to content

Commit

Permalink
Fix 404 issues on container start
Browse files Browse the repository at this point in the history
  • Loading branch information
joyrex2001 committed May 5, 2021
1 parent bfe06ba commit df44b91
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/model/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
14 changes: 14 additions & 0 deletions internal/model/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
4 changes: 4 additions & 0 deletions internal/server/routes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit df44b91

Please sign in to comment.