@@ -136,10 +136,16 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
136
136
}
137
137
}
138
138
139
- key , tag := c .getPrimaryKeyTag (subsysGossip )
139
+ key , tag , err := c .getPrimaryKeyTag (subsysGossip )
140
+ if err != nil {
141
+ return err
142
+ }
140
143
a .networkDB .SetPrimaryKey (key )
141
144
142
- key , tag = c .getPrimaryKeyTag (subsysIPSec )
145
+ key , tag , err = c .getPrimaryKeyTag (subsysIPSec )
146
+ if err != nil {
147
+ return err
148
+ }
143
149
drvEnc .Primary = key
144
150
drvEnc .PrimaryTag = tag
145
151
@@ -158,82 +164,6 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
158
164
return nil
159
165
}
160
166
161
- func (c * controller ) handleKeyChangeV1 (keys []* types.EncryptionKey ) error {
162
- drvEnc := discoverapi.DriverEncryptionUpdate {}
163
-
164
- // Find the new key and add it to the key ring
165
- a := c .agent
166
- for _ , key := range keys {
167
- same := false
168
- for _ , cKey := range c .keys {
169
- if same = cKey .LamportTime == key .LamportTime ; same {
170
- break
171
- }
172
- }
173
- if ! same {
174
- c .keys = append (c .keys , key )
175
- if key .Subsystem == subsysGossip {
176
- a .networkDB .SetKey (key .Key )
177
- }
178
- if key .Subsystem == subsysGossip /*subsysIPSec*/ {
179
- drvEnc .Key = key .Key
180
- drvEnc .Tag = key .LamportTime
181
- }
182
- break
183
- }
184
- }
185
- // Find the deleted key. If the deleted key was the primary key,
186
- // a new primary key should be set before removing if from keyring.
187
- deleted := []byte {}
188
- for i , cKey := range c .keys {
189
- same := false
190
- for _ , key := range keys {
191
- if same = key .LamportTime == cKey .LamportTime ; same {
192
- break
193
- }
194
- }
195
- if ! same {
196
- if cKey .Subsystem == subsysGossip {
197
- deleted = cKey .Key
198
- }
199
- if cKey .Subsystem == subsysGossip /*subsysIPSec*/ {
200
- drvEnc .Prune = cKey .Key
201
- drvEnc .PruneTag = cKey .LamportTime
202
- }
203
- c .keys = append (c .keys [:i ], c .keys [i + 1 :]... )
204
- break
205
- }
206
- }
207
-
208
- sort .Sort (ByTime (c .keys ))
209
- for _ , key := range c .keys {
210
- if key .Subsystem == subsysGossip {
211
- a .networkDB .SetPrimaryKey (key .Key )
212
- break
213
- }
214
- }
215
- for _ , key := range c .keys {
216
- if key .Subsystem == subsysGossip /*subsysIPSec*/ {
217
- drvEnc .Primary = key .Key
218
- drvEnc .PrimaryTag = key .LamportTime
219
- break
220
- }
221
- }
222
- if len (deleted ) > 0 {
223
- a .networkDB .RemoveKey (deleted )
224
- }
225
-
226
- c .drvRegistry .WalkDrivers (func (name string , driver driverapi.Driver , capability driverapi.Capability ) bool {
227
- err := driver .DiscoverNew (discoverapi .EncryptionKeysUpdate , drvEnc )
228
- if err != nil {
229
- logrus .Warnf ("Failed to update datapath keys in driver %s: %v" , name , err )
230
- }
231
- return false
232
- })
233
-
234
- return nil
235
- }
236
-
237
167
func (c * controller ) agentSetup () error {
238
168
clusterProvider := c .cfg .Daemon .ClusterProvider
239
169
@@ -281,25 +211,22 @@ func (c *controller) getKeys(subsys string) ([][]byte, []uint64) {
281
211
}
282
212
}
283
213
284
- if len (keys ) < keyringSize {
285
- return keys , tags
286
- }
287
214
keys [0 ], keys [1 ] = keys [1 ], keys [0 ]
288
215
tags [0 ], tags [1 ] = tags [1 ], tags [0 ]
289
216
return keys , tags
290
217
}
291
218
292
- // getPrimaryKeyTag returns the primary key for a given subsytem from the
219
+ // getPrimaryKeyTag returns the primary key for a given subsystem from the
293
220
// list of sorted key and the associated tag
294
- func (c * controller ) getPrimaryKeyTag (subsys string ) ([]byte , uint64 ) {
221
+ func (c * controller ) getPrimaryKeyTag (subsys string ) ([]byte , uint64 , error ) {
295
222
sort .Sort (ByTime (c .keys ))
296
223
keys := []* types.EncryptionKey {}
297
224
for _ , key := range c .keys {
298
225
if key .Subsystem == subsys {
299
226
keys = append (keys , key )
300
227
}
301
228
}
302
- return keys [1 ].Key , keys [1 ].LamportTime
229
+ return keys [1 ].Key , keys [1 ].LamportTime , nil
303
230
}
304
231
305
232
func (c * controller ) agentInit (bindAddrOrInterface , advertiseAddr string ) error {
@@ -462,6 +389,7 @@ func (ep *endpoint) addToCluster() error {
462
389
VirtualIP : ep .virtualIP .String (),
463
390
IngressPorts : ingressPorts ,
464
391
Aliases : ep .svcAliases ,
392
+ TaskAliases : ep .myAliases ,
465
393
EndpointIP : ep .Iface ().Address ().IP .String (),
466
394
})
467
395
@@ -540,7 +468,10 @@ func (n *network) addDriverWatches() {
540
468
}
541
469
542
470
c .agent .networkDB .WalkTable (tableName , func (nid , key string , value []byte ) bool {
543
- d .EventNotify (driverapi .Create , n .ID (), tableName , key , value )
471
+ if nid == n .ID () {
472
+ d .EventNotify (driverapi .Create , nid , tableName , key , value )
473
+ }
474
+
544
475
return false
545
476
})
546
477
}
@@ -653,6 +584,7 @@ func (c *controller) handleEpTableEvent(ev events.Event) {
653
584
ip := net .ParseIP (epRec .EndpointIP )
654
585
ingressPorts := epRec .IngressPorts
655
586
aliases := epRec .Aliases
587
+ taskaliases := epRec .TaskAliases
656
588
657
589
if name == "" || ip == nil {
658
590
logrus .Errorf ("Invalid endpoint name/ip received while handling service table event %s" , value )
@@ -668,6 +600,9 @@ func (c *controller) handleEpTableEvent(ev events.Event) {
668
600
}
669
601
670
602
n .addSvcRecords (name , ip , nil , true )
603
+ for _ , alias := range taskaliases {
604
+ n .addSvcRecords (alias , ip , nil , true )
605
+ }
671
606
} else {
672
607
if svcID != "" {
673
608
if err := c .rmServiceBinding (svcName , svcID , nid , eid , vip , ingressPorts , aliases , ip ); err != nil {
@@ -677,5 +612,8 @@ func (c *controller) handleEpTableEvent(ev events.Event) {
677
612
}
678
613
679
614
n .deleteSvcRecords (name , ip , nil , true )
615
+ for _ , alias := range taskaliases {
616
+ n .deleteSvcRecords (alias , ip , nil , true )
617
+ }
680
618
}
681
619
}
0 commit comments