feat: implement the scheduler plugin
This also performs a one-time migration of the DOKKU_SCHEDULER values the scheduler plugin properties. Closes #4739
This commit is contained in:
71
plugins/scheduler/triggers.go
Normal file
71
plugins/scheduler/triggers.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package scheduler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// TriggerSchedulerDetect outputs a manually selected scheduler for the app
|
||||
func TriggerSchedulerDetect(appName string) error {
|
||||
if scheduler := common.PropertyGet("scheduler", appName, "selected"); scheduler != "" {
|
||||
fmt.Println(scheduler)
|
||||
return nil
|
||||
}
|
||||
|
||||
if scheduler := common.PropertyGet("scheduler", "--global", "selected"); scheduler != "" {
|
||||
fmt.Println(scheduler)
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Println("docker-local")
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerInstall runs the install step for the scheduler plugin
|
||||
func TriggerInstall() error {
|
||||
if err := common.PropertySetup("scheduler"); err != nil {
|
||||
return fmt.Errorf("Unable to install the scheduler plugin: %s", err.Error())
|
||||
}
|
||||
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
globalScheduler := config.GetWithDefault("--scheduler", "DOKKU_SCHEDULER", "")
|
||||
if globalScheduler != "" {
|
||||
common.LogVerboseQuiet(fmt.Sprintf("Setting scheduler property 'selected' to %v", globalScheduler))
|
||||
if err := common.PropertyWrite("scheduler", "--global", "selected", globalScheduler); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := config.UnsetMany("--global", []string{"DOKKU_SCHEDULER"}, false); err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
for _, appName := range apps {
|
||||
scheduler := config.GetWithDefault(appName, "DOKKU_SCHEDULER", "")
|
||||
if scheduler == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
common.LogVerboseQuiet(fmt.Sprintf("Setting scheduler property 'selected' to %v", scheduler))
|
||||
if err := common.PropertyWrite("scheduler", appName, "selected", scheduler); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := config.UnsetMany(appName, []string{"DOKKU_SCHEDULER"}, false); err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostDelete destroys the scheduler property for a given app container
|
||||
func TriggerPostDelete(appName string) error {
|
||||
return common.PropertyDestroy("scheduler", appName)
|
||||
}
|
||||
Reference in New Issue
Block a user