Move proxy and plugin status from shell to Go
In the process we stop printing out the `PLUGIN_FULL_NAME`, but that is assumed to be something the user can figure out from `docker plugin ls`
This commit is contained in:
1 parent
3025738377
commit
b0da4f6b91
5 files changed
+63
-18
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
package plugin
|
||||||
|
|
||||||
|
type Status struct {
|
||||||
|
DriverName string
|
||||||
|
MeshDriverName string `json:"MeshDriverName,omitempty"`
|
||||||
|
Version int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStatus(address, meshAddress string, isPluginV2 bool) *Status {
|
||||||
|
status := &Status{
|
||||||
|
DriverName: pluginNameFromAddress(address),
|
||||||
|
MeshDriverName: pluginNameFromAddress(meshAddress),
|
||||||
|
Version: 1,
|
||||||
|
}
|
||||||
|
if isPluginV2 {
|
||||||
|
status.Version = 2
|
||||||
|
}
|
||||||
|
return status
|
||||||
|
}
|
||||||
+21
-2
@@ -17,6 +17,8 @@ import (
|
|||||||
"github.com/weaveworks/weave/ipam"
|
"github.com/weaveworks/weave/ipam"
|
||||||
"github.com/weaveworks/weave/nameserver"
|
"github.com/weaveworks/weave/nameserver"
|
||||||
"github.com/weaveworks/weave/net/address"
|
"github.com/weaveworks/weave/net/address"
|
||||||
|
"github.com/weaveworks/weave/plugin"
|
||||||
|
"github.com/weaveworks/weave/proxy"
|
||||||
weave "github.com/weaveworks/weave/router"
|
weave "github.com/weaveworks/weave/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -203,6 +205,18 @@ var statusTemplate = defTemplate("status", `\
|
|||||||
TTL: {{.DNS.TTL}}
|
TTL: {{.DNS.TTL}}
|
||||||
Entries: {{countDNSEntries .DNS.Entries}}
|
Entries: {{countDNSEntries .DNS.Entries}}
|
||||||
{{end}}\
|
{{end}}\
|
||||||
|
{{if .Proxy}}\
|
||||||
|
|
||||||
|
Service: proxy
|
||||||
|
Address: {{printList .Proxy.Addresses}}
|
||||||
|
{{end}}\
|
||||||
|
{{if .Plugin}}\
|
||||||
|
|
||||||
|
Service: plugin (v{{.Plugin.Version}})
|
||||||
|
{{if eq .Plugin.Version 1}}\
|
||||||
|
DriverName: {{.Plugin.DriverName}}
|
||||||
|
{{end}}\
|
||||||
|
{{end}}\
|
||||||
`)
|
`)
|
||||||
|
|
||||||
var targetsTemplate = defTemplate("targetsTemplate", `\
|
var targetsTemplate = defTemplate("targetsTemplate", `\
|
||||||
@@ -280,10 +294,12 @@ type WeaveStatus struct {
|
|||||||
Router *weave.NetworkRouterStatus `json:"Router,omitempty"`
|
Router *weave.NetworkRouterStatus `json:"Router,omitempty"`
|
||||||
IPAM *ipam.Status `json:"IPAM,omitempty"`
|
IPAM *ipam.Status `json:"IPAM,omitempty"`
|
||||||
DNS *nameserver.Status `json:"DNS,omitempty"`
|
DNS *nameserver.Status `json:"DNS,omitempty"`
|
||||||
|
Proxy *proxy.Status `json:"Proxy,omitempty"`
|
||||||
|
Plugin *plugin.Status `json:"Plugin,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read-only functions, suitable for exposing on an unprotected socket
|
// Read-only functions, suitable for exposing on an unprotected socket
|
||||||
func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer, waitReady *common.WaitGroup) {
|
func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer, prxy *proxy.Proxy, pluginStatus *plugin.Status, waitReady *common.WaitGroup) {
|
||||||
status := func() WeaveStatus {
|
status := func() WeaveStatus {
|
||||||
return WeaveStatus{
|
return WeaveStatus{
|
||||||
waitReady.IsDone(),
|
waitReady.IsDone(),
|
||||||
@@ -291,7 +307,10 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout
|
|||||||
versionCheck(),
|
versionCheck(),
|
||||||
weave.NewNetworkRouterStatus(router),
|
weave.NewNetworkRouterStatus(router),
|
||||||
ipam.NewStatus(allocator, defaultSubnet),
|
ipam.NewStatus(allocator, defaultSubnet),
|
||||||
nameserver.NewStatus(ns, dnsserver)}
|
nameserver.NewStatus(ns, dnsserver),
|
||||||
|
proxy.NewStatus(prxy),
|
||||||
|
pluginStatus,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
muxRouter.Methods("GET").Path("/report").Headers("Accept", "application/json").HandlerFunc(
|
muxRouter.Methods("GET").Path("/report").Headers("Accept", "application/json").HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
+8
-2
@@ -427,6 +427,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
checkFatal(router.CreateRestartSentinel())
|
checkFatal(router.CreateRestartSentinel())
|
||||||
|
|
||||||
|
// Slightly ugly that plugin status is separated from the plugin.Start call
|
||||||
|
var pluginStatus *plugin.Status
|
||||||
|
if enablePlugin || enablePluginV2 {
|
||||||
|
pluginStatus = plugin.NewStatus(pluginSocket, pluginMeshSocket, enablePluginV2)
|
||||||
|
}
|
||||||
|
|
||||||
// The weave script always waits for a status call to succeed,
|
// The weave script always waits for a status call to succeed,
|
||||||
// so there is no point in doing "weave launch --http-addr ''".
|
// so there is no point in doing "weave launch --http-addr ''".
|
||||||
// This is here to support stand-alone use of weaver.
|
// This is here to support stand-alone use of weaver.
|
||||||
@@ -439,7 +445,7 @@ func main() {
|
|||||||
ns.HandleHTTP(muxRouter, dockerCli)
|
ns.HandleHTTP(muxRouter, dockerCli)
|
||||||
}
|
}
|
||||||
router.HandleHTTP(muxRouter)
|
router.HandleHTTP(muxRouter)
|
||||||
HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, &waitReady)
|
HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, pluginStatus, &waitReady)
|
||||||
HandleHTTPPeer(muxRouter, allocator, discoveryEndpoint, token, name.String())
|
HandleHTTPPeer(muxRouter, allocator, discoveryEndpoint, token, name.String())
|
||||||
muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver))
|
muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver))
|
||||||
if proxy != nil {
|
if proxy != nil {
|
||||||
@@ -452,7 +458,7 @@ func main() {
|
|||||||
|
|
||||||
if statusAddr != "" {
|
if statusAddr != "" {
|
||||||
muxRouter := mux.NewRouter()
|
muxRouter := mux.NewRouter()
|
||||||
HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, &waitReady)
|
HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, pluginStatus, &waitReady)
|
||||||
muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver))
|
muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver))
|
||||||
statusMux := http.NewServeMux()
|
statusMux := http.NewServeMux()
|
||||||
statusMux.Handle("/", muxRouter)
|
statusMux.Handle("/", muxRouter)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
type Status struct {
|
||||||
|
Addresses []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStatus(proxy *Proxy) *Status {
|
||||||
|
if proxy == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
status := &Status{
|
||||||
|
Addresses: proxy.normalisedAddrs,
|
||||||
|
}
|
||||||
|
return status
|
||||||
|
}
|
||||||
@@ -1456,20 +1456,6 @@ case "$COMMAND" in
|
|||||||
echo "Invalid 'weave status' sub-command: $SUB_COMMAND" >&2
|
echo "Invalid 'weave status' sub-command: $SUB_COMMAND" >&2
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
if [ -z "$SUB_STATUS" ] && PROXY_ADDRS=$(proxy_addrs 2>/dev/null) ; then
|
|
||||||
echo
|
|
||||||
echo " Service: proxy"
|
|
||||||
echo " Address: $PROXY_ADDRS"
|
|
||||||
fi
|
|
||||||
if [ -z "$SUB_STATUS" ] && is_plugin_v1_enabled ; then
|
|
||||||
echo
|
|
||||||
echo " Service: plugin (v1)"
|
|
||||||
echo " DriverName: weave"
|
|
||||||
elif [ -z "$SUB_STATUS" ] && PLUGIN_FULL_NAME=$(is_plugin_v2_enabled) ; then
|
|
||||||
echo
|
|
||||||
echo " Service: plugin (v2)"
|
|
||||||
echo " DriverName: $PLUGIN_FULL_NAME"
|
|
||||||
fi
|
|
||||||
[ -n "$SUB_STATUS" ] || echo
|
[ -n "$SUB_STATUS" ] || echo
|
||||||
[ $res -eq 0 ]
|
[ $res -eq 0 ]
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in new issue
Block a user