Add warning when editing a service belongs to a stack

This commit is contained in:
cuigh 2017-10-17 16:07:53 +08:00
parent b0c0d3a0d9
commit ec76dbc318
5 changed files with 11 additions and 2 deletions

View File

@ -120,6 +120,7 @@ network.description: Networks are user-defined networks that containers can be a
# service pages # service pages
service.title: Service service.title: Service
service.description: Services are the definitions of tasks to run on a swarm. service.description: Services are the definitions of tasks to run on a swarm.
service.edit.warning: "NOTE: This service belong to '%s' stack, usually you should modify original compose instead of updating it directly."
# service template pages # service template pages
service.template.title: Service Template service.template.title: Service Template

View File

@ -120,6 +120,7 @@ network.description: 能够连接到容器的 Docker 预置和用户自定义的
# service pages # service pages
service.title: 服务 service.title: 服务
service.description: 服务是在 Swarm 集群中运行的任务定义。 service.description: 服务是在 Swarm 集群中运行的任务定义。
service.edit.warning: "注意: 这个服务属于编排 %s通常你应该修改原始的编排而不是直接修改此服务信息否则后续重新部署编排时这些修改将会丢失。"
# service template pages # service template pages
service.template.title: 服务模板 service.template.title: 服务模板

View File

@ -222,9 +222,10 @@ func serviceEdit(ctx web.Context) error {
return err return err
} }
stack := service.Spec.Labels["com.docker.stack.namespace"]
checkedNetworks := set.FromSlice(service.Endpoint.VirtualIPs, func(i int) interface{} { return service.Endpoint.VirtualIPs[i].NetworkID }) checkedNetworks := set.FromSlice(service.Endpoint.VirtualIPs, func(i int) interface{} { return service.Endpoint.VirtualIPs[i].NetworkID })
m := newModel(ctx).Add("Service", model.NewServiceInfo(service)). m := newModel(ctx).Add("Service", model.NewServiceInfo(service)).Add("Stack", stack).
Add("Networks", networks).Add("CheckedNetworks", checkedNetworks). Add("Networks", networks).Add("CheckedNetworks", checkedNetworks).
Add("Secrets", secrets).Add("Configs", configs) Add("Secrets", secrets).Add("Configs", configs)
return ctx.Render("service/edit", m) return ctx.Render("service/edit", m)

View File

@ -53,7 +53,10 @@ func Message(lang string) func(key string, args ...interface{}) string {
} }
return func(key string, args ...interface{}) string { return func(key string, args ...interface{}) string {
return t.Format(key, args...) if s := t.Format(key, args...); s != "" {
return s
}
return "[" + key + "]"
} }
} }

View File

@ -64,6 +64,9 @@
{{ yield form_others() }} {{ yield form_others() }}
{{ yield form_submit(url="/service/") }} {{ yield form_submit(url="/service/") }}
</form> </form>
{{ if .Stack }}
<div class="notification is-warning" style="margin-top: 1.5em">{{ i18n("service.edit.warning", .Stack) }}</div>
{{ end }}
</div> </div>
</section> </section>
{{ yield dialog(name="secret", items=.Secrets) }} {{ yield dialog(name="secret", items=.Secrets) }}