forked from coop-cloud/abra
evaluate if autoupdates are enabled
This commit is contained in:
parent
ee00823027
commit
af0d15ef79
@ -77,10 +77,11 @@ var UpgradeAll = cli.Command{
|
||||
stackName := stackInfo.Name
|
||||
recipeName := getRecipe(cl, stackName)
|
||||
chaos := getChaos(cl, stackName)
|
||||
if recipeName != "" && (!chaos || internal.Force) {
|
||||
updatesEnabled := getUpdateActivation(cl, stackName)
|
||||
if recipeName != "" && updatesEnabled && (!chaos || internal.Force) {
|
||||
upgrade(cl, stackName, recipeName)
|
||||
} else {
|
||||
logrus.Infof("Don't update %s due to missing recipe name or chaos deployment", stackName)
|
||||
logrus.Infof("Don't update %s due to missing recipe name, disabled updates or chaos deployment", stackName)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -129,6 +130,29 @@ func getChaos(cl *dockerclient.Client, stackName string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Read chaos deployment from docker label
|
||||
func getUpdateActivation(cl *dockerclient.Client, stackName string) bool {
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("label", fmt.Sprintf("%s=%s", convert.LabelNamespace, stackName))
|
||||
|
||||
services, err := cl.ServiceList(context.Background(), types.ServiceListOptions{Filters: filter})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
for _, service := range services {
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.autoupdate", stackName)
|
||||
if chaosLabel, ok := service.Spec.Labels[labelKey]; ok {
|
||||
chaos, err := strconv.ParseBool(chaosLabel)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
return chaos
|
||||
}
|
||||
}
|
||||
logrus.Debugf("no autoupdate label found for %s", stackName)
|
||||
return false
|
||||
}
|
||||
|
||||
// Read Env variables from docker services
|
||||
func getEnv(cl *dockerclient.Client, stackName string) config.AppEnv {
|
||||
envMap := make(map[string]string)
|
||||
@ -279,7 +303,6 @@ func upgrade(cl *dockerclient.Client, stackName string, recipeName string) {
|
||||
Server: "localhost",
|
||||
Env: getEnv(cl, stackName),
|
||||
}
|
||||
// TODO: evaluate ENABLE_AUTO_UPDATE env var
|
||||
|
||||
availableUpgrades := getAvailableUpgrades(cl, stackName, recipeName)
|
||||
if len(availableUpgrades) == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user