mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #34032 from allencloud/support-config-event-in-cluster
make engine support cluster config event
This commit is contained in:
commit
334702ab1f
7 changed files with 43 additions and 0 deletions
|
@ -5678,6 +5678,8 @@ paths:
|
||||||
|
|
||||||
Secrets report these events: `create`, `update`, and `remove`
|
Secrets report these events: `create`, `update`, and `remove`
|
||||||
|
|
||||||
|
Configs report these events: `create`, `update`, and `remove`
|
||||||
|
|
||||||
operationId: "SystemEvents"
|
operationId: "SystemEvents"
|
||||||
produces:
|
produces:
|
||||||
- "application/json"
|
- "application/json"
|
||||||
|
|
|
@ -19,6 +19,8 @@ const (
|
||||||
NodeEventType = "node"
|
NodeEventType = "node"
|
||||||
// SecretEventType is the event type that secrets generate
|
// SecretEventType is the event type that secrets generate
|
||||||
SecretEventType = "secret"
|
SecretEventType = "secret"
|
||||||
|
// ConfigEventType is the event type that configs generate
|
||||||
|
ConfigEventType = "config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Actor describes something that generates events,
|
// Actor describes something that generates events,
|
||||||
|
|
|
@ -202,6 +202,10 @@ func (n *nodeRunner) watchClusterEvents(ctx context.Context, conn *grpc.ClientCo
|
||||||
Kind: "secret",
|
Kind: "secret",
|
||||||
Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove,
|
Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Kind: "config",
|
||||||
|
Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
IncludeOldObject: true,
|
IncludeOldObject: true,
|
||||||
})
|
})
|
||||||
|
|
|
@ -175,6 +175,8 @@ func (daemon *Daemon) generateClusterEvent(msg *swarmapi.WatchMessage) {
|
||||||
daemon.logNetworkEvent(event.Action, v.Network, event.OldObject.GetNetwork())
|
daemon.logNetworkEvent(event.Action, v.Network, event.OldObject.GetNetwork())
|
||||||
case *swarmapi.Object_Secret:
|
case *swarmapi.Object_Secret:
|
||||||
daemon.logSecretEvent(event.Action, v.Secret, event.OldObject.GetSecret())
|
daemon.logSecretEvent(event.Action, v.Secret, event.OldObject.GetSecret())
|
||||||
|
case *swarmapi.Object_Config:
|
||||||
|
daemon.logConfigEvent(event.Action, v.Config, event.OldObject.GetConfig())
|
||||||
default:
|
default:
|
||||||
logrus.Warnf("unrecognized event: %v", event)
|
logrus.Warnf("unrecognized event: %v", event)
|
||||||
}
|
}
|
||||||
|
@ -197,6 +199,14 @@ func (daemon *Daemon) logSecretEvent(action swarmapi.WatchActionKind, secret *sw
|
||||||
daemon.logClusterEvent(action, secret.ID, "secret", attributes, eventTime)
|
daemon.logClusterEvent(action, secret.ID, "secret", attributes, eventTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (daemon *Daemon) logConfigEvent(action swarmapi.WatchActionKind, config *swarmapi.Config, oldConfig *swarmapi.Config) {
|
||||||
|
attributes := map[string]string{
|
||||||
|
"name": config.Spec.Annotations.Name,
|
||||||
|
}
|
||||||
|
eventTime := eventTimestamp(config.Meta, action)
|
||||||
|
daemon.logClusterEvent(action, config.ID, "config", attributes, eventTime)
|
||||||
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) logNodeEvent(action swarmapi.WatchActionKind, node *swarmapi.Node, oldNode *swarmapi.Node) {
|
func (daemon *Daemon) logNodeEvent(action swarmapi.WatchActionKind, node *swarmapi.Node, oldNode *swarmapi.Node) {
|
||||||
name := node.Spec.Annotations.Name
|
name := node.Spec.Annotations.Name
|
||||||
if name == "" && node.Description != nil {
|
if name == "" && node.Description != nil {
|
||||||
|
|
|
@ -94,6 +94,10 @@ func (ef *Filter) matchSecret(ev events.Message) bool {
|
||||||
return ef.fuzzyMatchName(ev, events.SecretEventType)
|
return ef.fuzzyMatchName(ev, events.SecretEventType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ef *Filter) matchConfig(ev events.Message) bool {
|
||||||
|
return ef.fuzzyMatchName(ev, events.ConfigEventType)
|
||||||
|
}
|
||||||
|
|
||||||
func (ef *Filter) fuzzyMatchName(ev events.Message, eventType string) bool {
|
func (ef *Filter) fuzzyMatchName(ev events.Message, eventType string) bool {
|
||||||
return ef.filter.FuzzyMatch(eventType, ev.Actor.ID) ||
|
return ef.filter.FuzzyMatch(eventType, ev.Actor.ID) ||
|
||||||
ef.filter.FuzzyMatch(eventType, ev.Actor.Attributes["name"])
|
ef.filter.FuzzyMatch(eventType, ev.Actor.Attributes["name"])
|
||||||
|
|
|
@ -27,6 +27,7 @@ keywords: "API, Docker, rcli, REST, documentation"
|
||||||
enabled.
|
enabled.
|
||||||
* `GET /images/(name)/get` now includes an `ImageMetadata` field which contains image metadata that is local to the engine and not part of the image config.
|
* `GET /images/(name)/get` now includes an `ImageMetadata` field which contains image metadata that is local to the engine and not part of the image config.
|
||||||
* `POST /services/create` now accepts a `PluginSpec` when `TaskTemplate.Runtime` is set to `plugin`
|
* `POST /services/create` now accepts a `PluginSpec` when `TaskTemplate.Runtime` is set to `plugin`
|
||||||
|
* `GET /events` now supports config events `create`, `update` and `remove` that are emitted when users create, update or remove a config
|
||||||
|
|
||||||
## v1.30 API changes
|
## v1.30 API changes
|
||||||
|
|
||||||
|
|
|
@ -2208,3 +2208,23 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSecret(c *check.C) {
|
||||||
// filtered by secret
|
// filtered by secret
|
||||||
waitForEvent(c, d, t1, "-f type=secret", "secret remove "+id, defaultRetryCount)
|
waitForEvent(c, d, t1, "-f type=secret", "secret remove "+id, defaultRetryCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *check.C) {
|
||||||
|
d := s.AddDaemon(c, true, true)
|
||||||
|
|
||||||
|
testName := "test_config"
|
||||||
|
id := d.CreateConfig(c, swarm.ConfigSpec{
|
||||||
|
Annotations: swarm.Annotations{
|
||||||
|
Name: testName,
|
||||||
|
},
|
||||||
|
Data: []byte("TESTINGDATA"),
|
||||||
|
})
|
||||||
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
||||||
|
|
||||||
|
waitForEvent(c, d, "0", "-f scope=swarm", "config create "+id, defaultRetryCount)
|
||||||
|
|
||||||
|
t1 := daemonUnixTime(c)
|
||||||
|
d.DeleteConfig(c, id)
|
||||||
|
// filtered by config
|
||||||
|
waitForEvent(c, d, t1, "-f type=config", "config remove "+id, defaultRetryCount)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue