Signed-off-by: allencloud <allen.sun@daocloud.io>
allencloud authored on 2017/07/10 12:41:25... | ... |
@@ -19,6 +19,8 @@ const ( |
19 | 19 |
NodeEventType = "node" |
20 | 20 |
// SecretEventType is the event type that secrets generate |
21 | 21 |
SecretEventType = "secret" |
22 |
+ // ConfigEventType is the event type that configs generate |
|
23 |
+ ConfigEventType = "config" |
|
22 | 24 |
) |
23 | 25 |
|
24 | 26 |
// Actor describes something that generates events, |
... | ... |
@@ -202,6 +202,10 @@ func (n *nodeRunner) watchClusterEvents(ctx context.Context, conn *grpc.ClientCo |
202 | 202 |
Kind: "secret", |
203 | 203 |
Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove, |
204 | 204 |
}, |
205 |
+ { |
|
206 |
+ Kind: "config", |
|
207 |
+ Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove, |
|
208 |
+ }, |
|
205 | 209 |
}, |
206 | 210 |
IncludeOldObject: true, |
207 | 211 |
}) |
... | ... |
@@ -175,6 +175,8 @@ func (daemon *Daemon) generateClusterEvent(msg *swarmapi.WatchMessage) { |
175 | 175 |
daemon.logNetworkEvent(event.Action, v.Network, event.OldObject.GetNetwork()) |
176 | 176 |
case *swarmapi.Object_Secret: |
177 | 177 |
daemon.logSecretEvent(event.Action, v.Secret, event.OldObject.GetSecret()) |
178 |
+ case *swarmapi.Object_Config: |
|
179 |
+ daemon.logConfigEvent(event.Action, v.Config, event.OldObject.GetConfig()) |
|
178 | 180 |
default: |
179 | 181 |
logrus.Warnf("unrecognized event: %v", event) |
180 | 182 |
} |
... | ... |
@@ -197,6 +199,14 @@ func (daemon *Daemon) logSecretEvent(action swarmapi.WatchActionKind, secret *sw |
197 | 197 |
daemon.logClusterEvent(action, secret.ID, "secret", attributes, eventTime) |
198 | 198 |
} |
199 | 199 |
|
200 |
+func (daemon *Daemon) logConfigEvent(action swarmapi.WatchActionKind, config *swarmapi.Config, oldConfig *swarmapi.Config) { |
|
201 |
+ attributes := map[string]string{ |
|
202 |
+ "name": config.Spec.Annotations.Name, |
|
203 |
+ } |
|
204 |
+ eventTime := eventTimestamp(config.Meta, action) |
|
205 |
+ daemon.logClusterEvent(action, config.ID, "config", attributes, eventTime) |
|
206 |
+} |
|
207 |
+ |
|
200 | 208 |
func (daemon *Daemon) logNodeEvent(action swarmapi.WatchActionKind, node *swarmapi.Node, oldNode *swarmapi.Node) { |
201 | 209 |
name := node.Spec.Annotations.Name |
202 | 210 |
if name == "" && node.Description != nil { |
... | ... |
@@ -94,6 +94,10 @@ func (ef *Filter) matchSecret(ev events.Message) bool { |
94 | 94 |
return ef.fuzzyMatchName(ev, events.SecretEventType) |
95 | 95 |
} |
96 | 96 |
|
97 |
+func (ef *Filter) matchConfig(ev events.Message) bool { |
|
98 |
+ return ef.fuzzyMatchName(ev, events.ConfigEventType) |
|
99 |
+} |
|
100 |
+ |
|
97 | 101 |
func (ef *Filter) fuzzyMatchName(ev events.Message, eventType string) bool { |
98 | 102 |
return ef.filter.FuzzyMatch(eventType, ev.Actor.ID) || |
99 | 103 |
ef.filter.FuzzyMatch(eventType, ev.Actor.Attributes["name"]) |
... | ... |
@@ -2208,3 +2208,23 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSecret(c *check.C) { |
2208 | 2208 |
// filtered by secret |
2209 | 2209 |
waitForEvent(c, d, t1, "-f type=secret", "secret remove "+id, defaultRetryCount) |
2210 | 2210 |
} |
2211 |
+ |
|
2212 |
+func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *check.C) { |
|
2213 |
+ d := s.AddDaemon(c, true, true) |
|
2214 |
+ |
|
2215 |
+ testName := "test_config" |
|
2216 |
+ id := d.CreateConfig(c, swarm.ConfigSpec{ |
|
2217 |
+ Annotations: swarm.Annotations{ |
|
2218 |
+ Name: testName, |
|
2219 |
+ }, |
|
2220 |
+ Data: []byte("TESTINGDATA"), |
|
2221 |
+ }) |
|
2222 |
+ c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id)) |
|
2223 |
+ |
|
2224 |
+ waitForEvent(c, d, "0", "-f scope=swarm", "config create "+id, defaultRetryCount) |
|
2225 |
+ |
|
2226 |
+ t1 := daemonUnixTime(c) |
|
2227 |
+ d.DeleteConfig(c, id) |
|
2228 |
+ // filtered by config |
|
2229 |
+ waitForEvent(c, d, t1, "-f type=config", "config remove "+id, defaultRetryCount) |
|
2230 |
+} |