forked from toolshed/abra
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			private-re
			...
			deploy-rel
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 5a4dac7e76 | |||
| 628a9a4b3f | 
| @ -10,6 +10,7 @@ import ( | |||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"coopcloud.tech/abra/pkg/envfile" | 	"coopcloud.tech/abra/pkg/envfile" | ||||||
| 	"coopcloud.tech/abra/pkg/secret" | 	"coopcloud.tech/abra/pkg/secret" | ||||||
|  | 	"coopcloud.tech/tagcmp" | ||||||
|  |  | ||||||
| 	appPkg "coopcloud.tech/abra/pkg/app" | 	appPkg "coopcloud.tech/abra/pkg/app" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| @ -45,7 +46,8 @@ Please note, "upgrade"/"rollback" do not support chaos operations.`, | |||||||
| 	ValidArgsFunction: func( | 	ValidArgsFunction: func( | ||||||
| 		cmd *cobra.Command, | 		cmd *cobra.Command, | ||||||
| 		args []string, | 		args []string, | ||||||
| 		toComplete string) ([]string, cobra.ShellCompDirective) { | 		toComplete string, | ||||||
|  | 	) ([]string, cobra.ShellCompDirective) { | ||||||
| 		switch l := len(args); l { | 		switch l := len(args); l { | ||||||
| 		case 0: | 		case 0: | ||||||
| 			return autocomplete.AppNameComplete() | 			return autocomplete.AppNameComplete() | ||||||
| @ -138,10 +140,6 @@ Please note, "upgrade"/"rollback" do not support chaos operations.`, | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if deployMeta.IsDeployed && !(internal.Force || internal.Chaos) { |  | ||||||
| 			log.Fatalf("%s is already deployed", app.Name) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if !internal.Chaos && specificVersion == "" { | 		if !internal.Chaos && specificVersion == "" { | ||||||
| 			versions, err := app.Recipe.Tags() | 			versions, err := app.Recipe.Tags() | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| @ -181,6 +179,33 @@ Please note, "upgrade"/"rollback" do not support chaos operations.`, | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if deployMeta.IsDeployed { | ||||||
|  | 			if !internal.Force { | ||||||
|  | 				appStatus, err := app.Status() | ||||||
|  | 				if err != nil { | ||||||
|  | 					log.Fatal(err) | ||||||
|  | 				} | ||||||
|  | 				if appStatus.Chaos && !internal.Chaos { | ||||||
|  | 					log.Fatalf("%s is deployed from a chaos version. Are you sure the local changes are in the current version (%s)?", app.Name, toDeployVersion) | ||||||
|  | 				} | ||||||
|  |  | ||||||
|  | 				if toDeployVersion != "" && appStatus.Version != "" { | ||||||
|  | 					localVersion, err := tagcmp.Parse(toDeployVersion) | ||||||
|  | 					if err != nil { | ||||||
|  | 						log.Fatal(err) | ||||||
|  | 					} | ||||||
|  | 					remoteVersion, err := tagcmp.Parse(appStatus.Version) | ||||||
|  | 					if err != nil { | ||||||
|  | 						log.Fatal(err) | ||||||
|  | 					} | ||||||
|  |  | ||||||
|  | 					if localVersion.IsLessThan(remoteVersion) { | ||||||
|  | 						log.Fatalf("%s is deployed at %s. Are you sure you want to downgrade to %s?", app.Name, appStatus.Version, toDeployVersion) | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath) | 		abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.Fatal(err) | 			log.Fatal(err) | ||||||
|  | |||||||
| @ -89,6 +89,8 @@ type App struct { | |||||||
| 	Env    envfile.AppEnv | 	Env    envfile.AppEnv | ||||||
| 	Server string | 	Server string | ||||||
| 	Path   string | 	Path   string | ||||||
|  |  | ||||||
|  | 	status *Status | ||||||
| } | } | ||||||
|  |  | ||||||
| // Type aliases to make code hints easier to understand | // Type aliases to make code hints easier to understand | ||||||
| @ -132,6 +134,19 @@ func StackName(appName string) string { | |||||||
| 	return stackName | 	return stackName | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (a App) Status() (Status, error) { | ||||||
|  | 	if a.status != nil { | ||||||
|  | 		return *a.status, nil | ||||||
|  | 	} | ||||||
|  | 	appStatuses, err := GetAppStatuses([]App{a}, true) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return Status{}, err | ||||||
|  | 	} | ||||||
|  | 	appStatus := appStatuses[a.StackName()] | ||||||
|  | 	a.status = &appStatus | ||||||
|  | 	return appStatus, nil | ||||||
|  | } | ||||||
|  |  | ||||||
| // Filters retrieves app filters for querying the container runtime. By default | // Filters retrieves app filters for querying the container runtime. By default | ||||||
| // it filters on all services in the app. It is also possible to pass an | // it filters on all services in the app. It is also possible to pass an | ||||||
| // otional list of service names, which get filtered instead. | // otional list of service names, which get filtered instead. | ||||||
| @ -397,9 +412,17 @@ func SanitiseAppName(name string) string { | |||||||
| 	return strings.ReplaceAll(name, ".", "_") | 	return strings.ReplaceAll(name, ".", "_") | ||||||
| } | } | ||||||
|  |  | ||||||
|  | type Status struct { | ||||||
|  | 	Status       string | ||||||
|  | 	Version      string | ||||||
|  | 	Chaos        bool | ||||||
|  | 	ChaosVersion string | ||||||
|  | 	AutoUpdate   bool | ||||||
|  | } | ||||||
|  |  | ||||||
| // GetAppStatuses queries servers to check the deployment status of given apps. | // GetAppStatuses queries servers to check the deployment status of given apps. | ||||||
| func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]string, error) { | func GetAppStatuses(apps []App, MachineReadable bool) (map[string]Status, error) { | ||||||
| 	statuses := make(map[string]map[string]string) | 	statuses := make(map[string]Status) | ||||||
|  |  | ||||||
| 	servers := make(map[string]struct{}) | 	servers := make(map[string]struct{}) | ||||||
| 	for _, app := range apps { | 	for _, app := range apps { | ||||||
| @ -435,36 +458,32 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for _, service := range status.Services { | 		for _, service := range status.Services { | ||||||
| 			result := make(map[string]string) | 			result := Status{} | ||||||
| 			name := service.Spec.Labels[convert.LabelNamespace] | 			name := service.Spec.Labels[convert.LabelNamespace] | ||||||
|  |  | ||||||
| 			if _, ok := statuses[name]; !ok { | 			if _, ok := statuses[name]; !ok { | ||||||
| 				result["status"] = "deployed" | 				result.Status = "deployed" | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			labelKey := fmt.Sprintf("coop-cloud.%s.chaos", name) | 			labelKey := fmt.Sprintf("coop-cloud.%s.chaos", name) | ||||||
| 			chaos, ok := service.Spec.Labels[labelKey] | 			chaos, ok := service.Spec.Labels[labelKey] | ||||||
| 			if ok { | 			if ok { | ||||||
| 				result["chaos"] = chaos | 				result.Chaos = chaos == "true" | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			labelKey = fmt.Sprintf("coop-cloud.%s.chaos-version", name) | 			labelKey = fmt.Sprintf("coop-cloud.%s.chaos-version", name) | ||||||
| 			if chaosVersion, ok := service.Spec.Labels[labelKey]; ok { | 			if chaosVersion, ok := service.Spec.Labels[labelKey]; ok { | ||||||
| 				result["chaosVersion"] = chaosVersion | 				result.ChaosVersion = chaosVersion | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			labelKey = fmt.Sprintf("coop-cloud.%s.autoupdate", name) | 			labelKey = fmt.Sprintf("coop-cloud.%s.autoupdate", name) | ||||||
| 			if autoUpdate, ok := service.Spec.Labels[labelKey]; ok { | 			if autoUpdate, ok := service.Spec.Labels[labelKey]; ok { | ||||||
| 				result["autoUpdate"] = autoUpdate | 				result.AutoUpdate = autoUpdate == "true" | ||||||
| 			} else { |  | ||||||
| 				result["autoUpdate"] = "false" |  | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			labelKey = fmt.Sprintf("coop-cloud.%s.version", name) | 			labelKey = fmt.Sprintf("coop-cloud.%s.version", name) | ||||||
| 			if version, ok := service.Spec.Labels[labelKey]; ok { | 			if version, ok := service.Spec.Labels[labelKey]; ok { | ||||||
| 				result["version"] = version | 				result.Version = version | ||||||
| 			} else { |  | ||||||
| 				continue |  | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			statuses[name] = result | 			statuses[name] = result | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user