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:
Bryan Boreham committed 2017-05-17 09:27:22 +00:00
1 parent 3025738377
commit b0da4f6b91
5 files changed
+63 -18

No files matched your search

+19
View File
@@ -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
View File
@@ -17,6 +17,8 @@ import (
"github.com/weaveworks/weave/ipam"
"github.com/weaveworks/weave/nameserver"
"github.com/weaveworks/weave/net/address"
"github.com/weaveworks/weave/plugin"
"github.com/weaveworks/weave/proxy"
weave "github.com/weaveworks/weave/router"
)
@@ -203,6 +205,18 @@ var statusTemplate = defTemplate("status", `\
TTL: {{.DNS.TTL}}
Entries: {{countDNSEntries .DNS.Entries}}
{{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", `\
@@ -280,10 +294,12 @@ type WeaveStatus struct {
Router *weave.NetworkRouterStatus `json:"Router,omitempty"`
IPAM *ipam.Status `json:"IPAM,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
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 {
return WeaveStatus{
waitReady.IsDone(),
@@ -291,7 +307,10 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout
versionCheck(),
weave.NewNetworkRouterStatus(router),
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(
func(w http.ResponseWriter, r *http.Request) {
+8 -2
View File
@@ -427,6 +427,12 @@ func main() {
}
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,
// so there is no point in doing "weave launch --http-addr ''".
// This is here to support stand-alone use of weaver.
@@ -439,7 +445,7 @@ func main() {
ns.HandleHTTP(muxRouter, dockerCli)
}
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())
muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver))
if proxy != nil {
@@ -452,7 +458,7 @@ func main() {
if statusAddr != "" {
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))
statusMux := http.NewServeMux()
statusMux.Handle("/", muxRouter)
+15
View File
@@ -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
}
-14
View File
@@ -1456,20 +1456,6 @@ case "$COMMAND" in
echo "Invalid 'weave status' sub-command: $SUB_COMMAND" >&2
usage
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
[ $res -eq 0 ]
;;