Delete config secret when listener pod gets deleted (#4033)
Co-authored-by: Nikola Jokic <jokicnikola07@gmail.com>
This commit is contained in:
		
							parent
							
								
									e335f53037
								
							
						
					
					
						commit
						d4af75d82e
					
				|  | @ -260,6 +260,19 @@ func (r *AutoscalingListenerReconciler) Reconcile(ctx context.Context, req ctrl. | ||||||
| 				log.Error(err, "Unable to delete the listener pod", "namespace", listenerPod.Namespace, "name", listenerPod.Name) | 				log.Error(err, "Unable to delete the listener pod", "namespace", listenerPod.Namespace, "name", listenerPod.Name) | ||||||
| 				return ctrl.Result{}, err | 				return ctrl.Result{}, err | ||||||
| 			} | 			} | ||||||
|  | 
 | ||||||
|  | 			// delete the listener config secret as well, so it gets recreated when the listener pod is recreated, with any new data if it exists
 | ||||||
|  | 			var configSecret corev1.Secret | ||||||
|  | 			err := r.Get(ctx, types.NamespacedName{Namespace: autoscalingListener.Namespace, Name: scaleSetListenerConfigName(autoscalingListener)}, &configSecret) | ||||||
|  | 			switch { | ||||||
|  | 			case err == nil && configSecret.DeletionTimestamp.IsZero(): | ||||||
|  | 				log.Info("Deleting the listener config secret") | ||||||
|  | 				if err := r.Delete(ctx, &configSecret); err != nil { | ||||||
|  | 					return ctrl.Result{}, fmt.Errorf("failed to delete listener config secret: %w", err) | ||||||
|  | 				} | ||||||
|  | 			case !kerrors.IsNotFound(err): | ||||||
|  | 				return ctrl.Result{}, fmt.Errorf("failed to get the listener config secret: %w", err) | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 		return ctrl.Result{}, nil | 		return ctrl.Result{}, nil | ||||||
| 	case cs.State.Running != nil: | 	case cs.State.Running != nil: | ||||||
|  |  | ||||||
|  | @ -339,7 +339,7 @@ var _ = Describe("Test AutoScalingListener controller", func() { | ||||||
| 				autoscalingListenerTestInterval).Should(BeEquivalentTo(rulesForListenerRole([]string{updated.Spec.EphemeralRunnerSetName})), "Role should be updated") | 				autoscalingListenerTestInterval).Should(BeEquivalentTo(rulesForListenerRole([]string{updated.Spec.EphemeralRunnerSetName})), "Role should be updated") | ||||||
| 		}) | 		}) | ||||||
| 
 | 
 | ||||||
| 		It("It should re-create pod whenever listener container is terminated", func() { | 		It("It should re-create pod and config secret whenever listener container is terminated", func() { | ||||||
| 			// Waiting for the pod is created
 | 			// Waiting for the pod is created
 | ||||||
| 			pod := new(corev1.Pod) | 			pod := new(corev1.Pod) | ||||||
| 			Eventually( | 			Eventually( | ||||||
|  | @ -355,7 +355,18 @@ var _ = Describe("Test AutoScalingListener controller", func() { | ||||||
| 				autoscalingListenerTestInterval, | 				autoscalingListenerTestInterval, | ||||||
| 			).Should(BeEquivalentTo(autoscalingListener.Name), "Pod should be created") | 			).Should(BeEquivalentTo(autoscalingListener.Name), "Pod should be created") | ||||||
| 
 | 
 | ||||||
|  | 			secret := new(corev1.Secret) | ||||||
|  | 			Eventually( | ||||||
|  | 				func() error { | ||||||
|  | 					return k8sClient.Get(ctx, client.ObjectKey{Name: scaleSetListenerConfigName(autoscalingListener), Namespace: autoscalingListener.Namespace}, secret) | ||||||
|  | 				}, | ||||||
|  | 				autoscalingListenerTestTimeout, | ||||||
|  | 				autoscalingListenerTestInterval, | ||||||
|  | 			).Should(Succeed(), "Config secret should be created") | ||||||
|  | 
 | ||||||
| 			oldPodUID := string(pod.UID) | 			oldPodUID := string(pod.UID) | ||||||
|  | 			oldSecretUID := string(secret.UID) | ||||||
|  | 
 | ||||||
| 			updated := pod.DeepCopy() | 			updated := pod.DeepCopy() | ||||||
| 			updated.Status.ContainerStatuses = []corev1.ContainerStatus{ | 			updated.Status.ContainerStatuses = []corev1.ContainerStatus{ | ||||||
| 				{ | 				{ | ||||||
|  | @ -384,6 +395,21 @@ var _ = Describe("Test AutoScalingListener controller", func() { | ||||||
| 				autoscalingListenerTestTimeout, | 				autoscalingListenerTestTimeout, | ||||||
| 				autoscalingListenerTestInterval, | 				autoscalingListenerTestInterval, | ||||||
| 			).ShouldNot(BeEquivalentTo(oldPodUID), "Pod should be re-created") | 			).ShouldNot(BeEquivalentTo(oldPodUID), "Pod should be re-created") | ||||||
|  | 
 | ||||||
|  | 			// Check if config secret is re-created
 | ||||||
|  | 			Eventually( | ||||||
|  | 				func() (string, error) { | ||||||
|  | 					secret := new(corev1.Secret) | ||||||
|  | 					err := k8sClient.Get(ctx, client.ObjectKey{Name: scaleSetListenerConfigName(autoscalingListener), Namespace: autoscalingListener.Namespace}, secret) | ||||||
|  | 					if err != nil { | ||||||
|  | 						return "", err | ||||||
|  | 					} | ||||||
|  | 
 | ||||||
|  | 					return string(secret.UID), nil | ||||||
|  | 				}, | ||||||
|  | 				autoscalingListenerTestTimeout, | ||||||
|  | 				autoscalingListenerTestInterval, | ||||||
|  | 			).ShouldNot(BeEquivalentTo(oldSecretUID), "Config secret should be re-created") | ||||||
| 		}) | 		}) | ||||||
| 	}) | 	}) | ||||||
| }) | }) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue