@@ -171,15 +171,16 @@ func (c *GrpcRegistryReconciler) currentUpdatePods(source grpcCatalogSourceDecor
171
171
return pods
172
172
}
173
173
174
- func (c * GrpcRegistryReconciler ) currentPodsWithCorrectImage (source grpcCatalogSourceDecorator ) []* corev1.Pod {
174
+ func (c * GrpcRegistryReconciler ) currentPodsWithCorrectImageAndSpec (source grpcCatalogSourceDecorator , saName string ) []* corev1.Pod {
175
175
pods , err := c .Lister .CoreV1 ().PodLister ().Pods (source .GetNamespace ()).List (labels .SelectorFromValidatedSet (source .Labels ()))
176
176
if err != nil {
177
177
logrus .WithError (err ).Warn ("couldn't find pod in cache" )
178
178
return nil
179
179
}
180
180
found := []* corev1.Pod {}
181
+ newPod := source .Pod (saName )
181
182
for _ , p := range pods {
182
- if p .Spec .Containers [0 ].Image == source .Spec .Image {
183
+ if p .Spec .Containers [0 ].Image == source .Spec .Image && podHashMatch ( p , newPod ) {
183
184
found = append (found , p )
184
185
}
185
186
}
@@ -192,11 +193,12 @@ func (c *GrpcRegistryReconciler) EnsureRegistryServer(catalogSource *v1alpha1.Ca
192
193
193
194
// if service status is nil, we force create every object to ensure they're created the first time
194
195
overwrite := source .Status .RegistryServiceStatus == nil
195
- // recreate the pod if no existing pod is serving the latest image
196
- overwritePod := overwrite || len (c .currentPodsWithCorrectImage (source )) == 0
197
196
198
197
//TODO: if any of these error out, we should write a status back (possibly set RegistryServiceStatus to nil so they get recreated)
199
198
sa , err := c .ensureSA (source )
199
+ // recreate the pod if no existing pod is serving the latest image or correct spec
200
+ overwritePod := overwrite || len (c .currentPodsWithCorrectImageAndSpec (source , sa .GetName ())) == 0
201
+
200
202
if err != nil && ! k8serror .IsAlreadyExists (err ) {
201
203
return errors .Wrapf (err , "error ensuring service account: %s" , source .GetName ())
202
204
}
@@ -421,10 +423,9 @@ func (c *GrpcRegistryReconciler) removePods(pods []*corev1.Pod, namespace string
421
423
// CheckRegistryServer returns true if the given CatalogSource is considered healthy; false otherwise.
422
424
func (c * GrpcRegistryReconciler ) CheckRegistryServer (catalogSource * v1alpha1.CatalogSource ) (healthy bool , err error ) {
423
425
source := grpcCatalogSourceDecorator {catalogSource }
424
-
425
426
// Check on registry resources
426
427
// TODO: add gRPC health check
427
- if len (c .currentPodsWithCorrectImage (source )) < 1 ||
428
+ if len (c .currentPodsWithCorrectImageAndSpec (source , source . ServiceAccount (). GetName () )) < 1 ||
428
429
c .currentService (source ) == nil {
429
430
healthy = false
430
431
return
@@ -478,3 +479,30 @@ func (c *GrpcRegistryReconciler) podFailed(pod *corev1.Pod) (bool, error) {
478
479
}
479
480
return false , nil
480
481
}
482
+
483
+ // podHashMatch will check the hash info in existing pod to ensure its
484
+ // hash info matches the desired Service's hash.
485
+ func podHashMatch (existing , new * corev1.Pod ) bool {
486
+ labels := existing .GetLabels ()
487
+ newLabels := new .GetLabels ()
488
+ // If both new & existing pods don't have labels, consider it not matched
489
+ if len (labels ) == 0 || len (newLabels ) == 0 {
490
+ return false
491
+ }
492
+
493
+ existingPodSpecHash , ok := labels [PodHashLabelKey ]
494
+ if ! ok {
495
+ return false
496
+ }
497
+
498
+ newPodSpecHash , ok := newLabels [PodHashLabelKey ]
499
+ if ! ok {
500
+ return false
501
+ }
502
+
503
+ if existingPodSpecHash != newPodSpecHash {
504
+ return false
505
+ }
506
+
507
+ return true
508
+ }
0 commit comments