Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions api-service/controller/env_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func (ctrl *EnvInstanceController) CreateEnvInstance(c *gin.Context) {
backendmodels.JSONErrorWithMessage(c, 404, "Environment not found: "+req.EnvName)
return
}
if backendEnv.DeployConfig == nil {
backendEnv.DeployConfig = make(map[string]interface{})
}
if req.Datasource != "" {
if backendEnv.DeployConfig == nil {
backendEnv.DeployConfig = make(map[string]interface{})
}
// Prefer imagePrefix from DeployConfig, default to empty string
imagePrefix := "docker.io/library/aenv"
if value, ok := backendEnv.DeployConfig["imagePrefix"]; ok {
Expand All @@ -102,7 +102,9 @@ func (ctrl *EnvInstanceController) CreateEnvInstance(c *gin.Context) {
backendEnv.DeployConfig["arguments"] = req.Arguments
}
// Set TTL for environment
backendEnv.DeployConfig["ttl"] = req.TTL
if req.TTL != "" {
backendEnv.DeployConfig["ttl"] = req.TTL
}
Comment on lines +105 to +107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While it's good to avoid setting an empty TTL, this change might have an unintended side effect. If a user wants to explicitly remove a TTL by passing an empty string, this change would prevent that. The previous behavior would set the ttl key with an empty value. Please confirm if the intention is to disallow unsetting the TTL via an empty string.

// Set owner for controller to store in pod label
if req.Owner != "" {
backendEnv.DeployConfig["owner"] = req.Owner
Expand Down
4 changes: 3 additions & 1 deletion api-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

replace envhub => ../envhub
replace (
envhub => ../envhub
)

require (
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
24 changes: 15 additions & 9 deletions api-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,21 @@ func main() {
}

var scheduleClient service.EnvInstanceService
var envServiceController *controller.EnvServiceController
switch scheduleType {
case "k8s":
scheduleClient = service.NewScheduleClient(scheduleAddr)
envServiceController = controller.NewEnvServiceController(scheduleClient, backendClient, redisClient)
case "standard":
scheduleClient = service.NewEnvInstanceClient(scheduleAddr)
case "faas":
scheduleClient = service.NewFaaSClient(scheduleAddr)
default:
log.Fatalf("unsupported schedule type: %v", scheduleType)
}

envInstanceController := controller.NewEnvInstanceController(scheduleClient, backendClient, redisClient)
envServiceController := controller.NewEnvServiceController(scheduleClient, backendClient, redisClient)

// Main route configuration
mainRouter.POST("/env-instance",
middleware.AuthTokenMiddleware(tokenEnabled, backendClient),
Expand All @@ -118,14 +122,16 @@ func main() {
mainRouter.DELETE("/env-instance/:id", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envInstanceController.DeleteEnvInstance)

// Service routes
mainRouter.POST("/env-service",
middleware.AuthTokenMiddleware(tokenEnabled, backendClient),
middleware.RateLimit(qps),
envServiceController.CreateEnvService)
mainRouter.GET("/env-service/:id/list", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envServiceController.ListEnvServices)
mainRouter.GET("/env-service/:id", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envServiceController.GetEnvService)
mainRouter.DELETE("/env-service/:id", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envServiceController.DeleteEnvService)
mainRouter.PUT("/env-service/:id", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envServiceController.UpdateEnvService)
if envServiceController != nil {
mainRouter.POST("/env-service",
middleware.AuthTokenMiddleware(tokenEnabled, backendClient),
middleware.RateLimit(qps),
envServiceController.CreateEnvService)
mainRouter.GET("/env-service/:id/list", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envServiceController.ListEnvServices)
mainRouter.GET("/env-service/:id", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envServiceController.GetEnvService)
mainRouter.DELETE("/env-service/:id", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envServiceController.DeleteEnvService)
mainRouter.PUT("/env-service/:id", middleware.AuthTokenMiddleware(tokenEnabled, backendClient), envServiceController.UpdateEnvService)
}
Comment on lines +125 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The routes for /env-service are now conditionally registered based on whether envServiceController is initialized. This implies that standard and faas schedule types do not support environment services. While this seems reasonable given the context of FaaS, it's a significant functional change that should be documented or confirmed as intended behavior.


mainRouter.GET("/health", healthChecker)
mainRouter.GET("/metrics", gin.WrapH(promhttp.Handler()))
Expand Down
Loading
Loading