浏览代码

make engine support cluster config event

Signed-off-by: allencloud <allen.sun@daocloud.io>
allencloud 8 年之前
父节点
当前提交
ed916a233c
共有 5 个文件被更改,包括 40 次插入0 次删除
  1. 2 0
      api/types/events/events.go
  2. 4 0
      daemon/cluster/noderunner.go
  3. 10 0
      daemon/events.go
  4. 4 0
      daemon/events/filter.go
  5. 20 0
      integration-cli/docker_cli_swarm_test.go

+ 2 - 0
api/types/events/events.go

@@ -19,6 +19,8 @@ const (
 	NodeEventType = "node"
 	// SecretEventType is the event type that secrets generate
 	SecretEventType = "secret"
+	// ConfigEventType is the event type that configs generate
+	ConfigEventType = "config"
 )
 
 // Actor describes something that generates events,

+ 4 - 0
daemon/cluster/noderunner.go

@@ -202,6 +202,10 @@ func (n *nodeRunner) watchClusterEvents(ctx context.Context, conn *grpc.ClientCo
 				Kind:   "secret",
 				Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove,
 			},
+			{
+				Kind:   "config",
+				Action: swarmapi.WatchActionKindCreate | swarmapi.WatchActionKindUpdate | swarmapi.WatchActionKindRemove,
+			},
 		},
 		IncludeOldObject: true,
 	})

+ 10 - 0
daemon/events.go

@@ -175,6 +175,8 @@ func (daemon *Daemon) generateClusterEvent(msg *swarmapi.WatchMessage) {
 			daemon.logNetworkEvent(event.Action, v.Network, event.OldObject.GetNetwork())
 		case *swarmapi.Object_Secret:
 			daemon.logSecretEvent(event.Action, v.Secret, event.OldObject.GetSecret())
+		case *swarmapi.Object_Config:
+			daemon.logConfigEvent(event.Action, v.Config, event.OldObject.GetConfig())
 		default:
 			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)
 }
 
+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) {
 	name := node.Spec.Annotations.Name
 	if name == "" && node.Description != nil {

+ 4 - 0
daemon/events/filter.go

@@ -94,6 +94,10 @@ func (ef *Filter) matchSecret(ev events.Message) bool {
 	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 {
 	return ef.filter.FuzzyMatch(eventType, ev.Actor.ID) ||
 		ef.filter.FuzzyMatch(eventType, ev.Actor.Attributes["name"])

+ 20 - 0
integration-cli/docker_cli_swarm_test.go

@@ -2208,3 +2208,23 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSecret(c *check.C) {
 	// filtered by secret
 	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)
+}