From 89fb4b682ef0eb5465e0db0f17abd8791e35a252 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Tue, 19 Sep 2023 16:00:41 +0200 Subject: [PATCH] deployment strategy recreated when storage disk --- controllers/limitador_controller.go | 1 + pkg/limitador/deployment_options.go | 15 +++++++++------ pkg/limitador/disk_storage_options.go | 6 ++++++ pkg/limitador/disk_storage_options_test.go | 3 +++ pkg/limitador/k8s_objects.go | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/controllers/limitador_controller.go b/controllers/limitador_controller.go index 826914b3..1b7e41a0 100644 --- a/controllers/limitador_controller.go +++ b/controllers/limitador_controller.go @@ -316,6 +316,7 @@ func (r *LimitadorReconciler) getDeploymentOptions(ctx context.Context, limObj * deploymentOptions.Command = limitador.DeploymentCommand(limObj, deploymentStorageOptions) deploymentOptions.VolumeMounts = limitador.DeploymentVolumeMounts(deploymentStorageOptions) deploymentOptions.Volumes = limitador.DeploymentVolumes(limObj, deploymentStorageOptions) + deploymentOptions.DeploymentStrategy = deploymentStorageOptions.DeploymentStrategy return deploymentOptions, nil } diff --git a/pkg/limitador/deployment_options.go b/pkg/limitador/deployment_options.go index c62f0c20..a41034f3 100644 --- a/pkg/limitador/deployment_options.go +++ b/pkg/limitador/deployment_options.go @@ -3,21 +3,24 @@ package limitador import ( "path/filepath" + appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" ) type DeploymentOptions struct { - Command []string - VolumeMounts []v1.VolumeMount - Volumes []v1.Volume + Command []string + VolumeMounts []v1.VolumeMount + Volumes []v1.Volume + DeploymentStrategy appsv1.DeploymentStrategy } type DeploymentStorageOptions struct { - Command []string - VolumeMounts []v1.VolumeMount - Volumes []v1.Volume + Command []string + VolumeMounts []v1.VolumeMount + Volumes []v1.Volume + DeploymentStrategy appsv1.DeploymentStrategy } const ( diff --git a/pkg/limitador/disk_storage_options.go b/pkg/limitador/disk_storage_options.go index 685f267c..6ee4ffac 100644 --- a/pkg/limitador/disk_storage_options.go +++ b/pkg/limitador/disk_storage_options.go @@ -1,6 +1,7 @@ package limitador import ( + appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" @@ -24,6 +25,11 @@ func DiskDeploymentOptions(limObj *limitadorv1alpha1.Limitador, diskObj limitado Command: command, VolumeMounts: diskVolumeMounts(), Volumes: diskVolumes(limObj), + // Disk storage requires killing all existing pods before creating a new one, as the PV canont be shared. + // Limitador adds a lock to the disk. If the lock is not released before the new pod is created, + // the new pod will panic and never start. Seen error: + // thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: "IO error: While lock file: /var/lib/limitador/data/LOCK: Resource temporarily unavailable" }', /usr/src/limitador/limitador/src/storage/disk/rocksdb_storage.rs:155:40 + DeploymentStrategy: appsv1.DeploymentStrategy{Type: appsv1.RecreateDeploymentStrategyType}, }, nil } diff --git a/pkg/limitador/disk_storage_options_test.go b/pkg/limitador/disk_storage_options_test.go index ca5990ba..5eb34798 100644 --- a/pkg/limitador/disk_storage_options_test.go +++ b/pkg/limitador/disk_storage_options_test.go @@ -4,6 +4,7 @@ import ( "testing" "gotest.tools/assert" + appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -40,6 +41,7 @@ func TestDiskDeploymentOptions(t *testing.T) { }, }, }, + DeploymentStrategy: appsv1.DeploymentStrategy{Type: appsv1.RecreateDeploymentStrategyType}, }) }) @@ -67,6 +69,7 @@ func TestDiskDeploymentOptions(t *testing.T) { }, }, }, + DeploymentStrategy: appsv1.DeploymentStrategy{Type: appsv1.RecreateDeploymentStrategyType}, }) }) } diff --git a/pkg/limitador/k8s_objects.go b/pkg/limitador/k8s_objects.go index a7eb2ad7..4c5f3ddf 100644 --- a/pkg/limitador/k8s_objects.go +++ b/pkg/limitador/k8s_objects.go @@ -77,6 +77,7 @@ func Deployment(limitador *limitadorv1alpha1.Limitador, deploymentOptions Deploy }, Spec: appsv1.DeploymentSpec{ Replicas: &replicas, + Strategy: deploymentOptions.DeploymentStrategy, Selector: &metav1.LabelSelector{ MatchLabels: Labels(limitador), },