该代码执行以下操作:
获取安装状态数组并提供一些整体状态,即字符串值
循环在阵列上,如果其中一个安装条目是错误的,则所有安装都视为错误并返回overallstatus=error
如果一个正在运行overallstatus=running
否则overallstatus=installing
我的问题是,如果有更简单/更短的写法?
func overallInstallationStatus(installStatus []apiv.Installstatus) string {
overallStatus := ""
for _, status := range installStatus {
switch status.ReleaseStatus {
case release.StatusFailed.String():
// If at least one installation is in failed, we consider the overallstatus to be in error state
overallStatus = "error"
case release.StatusDeployed.String():
// If no other status was found and there is at least one deployed chart, we consider it "running"
if overallStatus == "" {
overallStatus = "running"
}
default:
// All other statuses are considered to be "installing"
if overallStatus != release.StatusFailed.String() {
overallStatus = "installing"
}
}
}
return overallStatus
}
www说
相关分类