Skip to content

Commit 2615244

Browse files
authored
Fixing cache so it will replace workload profiles in case of quick restart (#575)
Signed-off-by: Amit Schendel <[email protected]>
1 parent b369895 commit 2615244

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pkg/objectcache/applicationprofilecache/applicationprofilecache.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (apc *ApplicationProfileCacheImpl) updateAllProfiles(ctx context.Context) {
151151
}
152152

153153
// Get the workload ID from profile
154-
workloadID := profile.Annotations[helpersv1.WlidMetadataKey]
154+
workloadID := apc.wlidKey(profile.Annotations[helpersv1.WlidMetadataKey], profile.Labels[helpersv1.TemplateHashKey])
155155
if workloadID == "" {
156156
continue
157157
}
@@ -429,7 +429,7 @@ func (apc *ApplicationProfileCacheImpl) addContainer(container *containercollect
429429
return err
430430
}
431431

432-
workloadID := sharedData.Wlid
432+
workloadID := apc.wlidKey(sharedData.Wlid, sharedData.InstanceID.GetTemplateHash())
433433
if workloadID == "" {
434434
logger.L().Debug("empty workloadID for container", helpers.String("containerID", containerID))
435435
return nil
@@ -516,6 +516,10 @@ func (apc *ApplicationProfileCacheImpl) profileKey(namespace, name string) strin
516516
return fmt.Sprintf("%s/%s", namespace, name)
517517
}
518518

519+
func (apc *ApplicationProfileCacheImpl) wlidKey(wlid, templateHash string) string {
520+
return fmt.Sprintf("%s/%s", wlid, templateHash)
521+
}
522+
519523
func (apc *ApplicationProfileCacheImpl) performMerge(normalProfile, userManagedProfile *v1beta1.ApplicationProfile) *v1beta1.ApplicationProfile {
520524
mergedProfile := normalProfile.DeepCopy()
521525

pkg/objectcache/networkneighborhoodcache/networkneighborhoodcache.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ func (nnc *NetworkNeighborhoodCacheImpl) updateAllNetworkNeighborhoods(ctx conte
143143
}
144144

145145
// Get the workload ID from network neighborhood
146-
workloadID := nn.Annotations[helpersv1.WlidMetadataKey]
146+
workloadID := nnc.wlidKey(
147+
nn.Annotations[helpersv1.WlidMetadataKey],
148+
nn.Labels[helpersv1.TemplateHashKey],
149+
)
147150
if workloadID == "" {
148151
continue
149152
}
@@ -349,7 +352,7 @@ func (nnc *NetworkNeighborhoodCacheImpl) addContainer(container *containercollec
349352
return err
350353
}
351354

352-
workloadID := sharedData.Wlid
355+
workloadID := nnc.wlidKey(sharedData.Wlid, sharedData.InstanceID.GetTemplateHash())
353356
if workloadID == "" {
354357
logger.L().Debug("empty workloadID for container", helpers.String("containerID", containerID))
355358
return nil
@@ -434,6 +437,10 @@ func (nnc *NetworkNeighborhoodCacheImpl) networkNeighborhoodKey(namespace, name
434437
return fmt.Sprintf("%s/%s", namespace, name)
435438
}
436439

440+
func (nnc *NetworkNeighborhoodCacheImpl) wlidKey(wlid, templateHash string) string {
441+
return fmt.Sprintf("%s/%s", wlid, templateHash)
442+
}
443+
437444
// GetNetworkNeighborhood gets the network neighborhood for a container
438445
func (nnc *NetworkNeighborhoodCacheImpl) GetNetworkNeighborhood(containerID string) *v1beta1.NetworkNeighborhood {
439446
// Get container info

0 commit comments

Comments
 (0)