Skip to content

Commit ed916a2

Browse files
committed
make engine support cluster config event
Signed-off-by: allencloud <[email protected]>
1 parent 6978a6e commit ed916a2

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

api/types/events/events.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const (
1919
NodeEventType = "node"
2020
// SecretEventType is the event type that secrets generate
2121
SecretEventType = "secret"
22+
// ConfigEventType is the event type that configs generate
23+
ConfigEventType = "config"
2224
)
2325

2426
// Actor describes something that generates events,

daemon/cluster/noderunner.go

+4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ func (n *nodeRunner) watchClusterEvents(ctx context.Context, conn *grpc.ClientCo
202202
Kind: "secret",
203203
Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove,
204204
},
205+
{
206+
Kind: "config",
207+
Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove,
208+
},
205209
},
206210
IncludeOldObject: true,
207211
})

daemon/events.go

+10
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ func (daemon *Daemon) generateClusterEvent(msg *swarmapi.WatchMessage) {
175175
daemon.logNetworkEvent(event.Action, v.Network, event.OldObject.GetNetwork())
176176
case *swarmapi.Object_Secret:
177177
daemon.logSecretEvent(event.Action, v.Secret, event.OldObject.GetSecret())
178+
case *swarmapi.Object_Config:
179+
daemon.logConfigEvent(event.Action, v.Config, event.OldObject.GetConfig())
178180
default:
179181
logrus.Warnf("unrecognized event: %v", event)
180182
}
@@ -197,6 +199,14 @@ func (daemon *Daemon) logSecretEvent(action swarmapi.WatchActionKind, secret *sw
197199
daemon.logClusterEvent(action, secret.ID, "secret", attributes, eventTime)
198200
}
199201

202+
func (daemon *Daemon) logConfigEvent(action swarmapi.WatchActionKind, config *swarmapi.Config, oldConfig *swarmapi.Config) {
203+
attributes := map[string]string{
204+
"name": config.Spec.Annotations.Name,
205+
}
206+
eventTime := eventTimestamp(config.Meta, action)
207+
daemon.logClusterEvent(action, config.ID, "config", attributes, eventTime)
208+
}
209+
200210
func (daemon *Daemon) logNodeEvent(action swarmapi.WatchActionKind, node *swarmapi.Node, oldNode *swarmapi.Node) {
201211
name := node.Spec.Annotations.Name
202212
if name == "" && node.Description != nil {

daemon/events/filter.go

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ func (ef *Filter) matchSecret(ev events.Message) bool {
9494
return ef.fuzzyMatchName(ev, events.SecretEventType)
9595
}
9696

97+
func (ef *Filter) matchConfig(ev events.Message) bool {
98+
return ef.fuzzyMatchName(ev, events.ConfigEventType)
99+
}
100+
97101
func (ef *Filter) fuzzyMatchName(ev events.Message, eventType string) bool {
98102
return ef.filter.FuzzyMatch(eventType, ev.Actor.ID) ||
99103
ef.filter.FuzzyMatch(eventType, ev.Actor.Attributes["name"])

integration-cli/docker_cli_swarm_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -2208,3 +2208,23 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSecret(c *check.C) {
22082208
// filtered by secret
22092209
waitForEvent(c, d, t1, "-f type=secret", "secret remove "+id, defaultRetryCount)
22102210
}
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+
}

0 commit comments

Comments
 (0)