Skip to content

Commit

Permalink
deployment strategy recreated when storage disk
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Sep 19, 2023
1 parent a3f9619 commit 89fb4b6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions controllers/limitador_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/limitador/deployment_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 6 additions & 0 deletions pkg/limitador/disk_storage_options.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/limitador/disk_storage_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -40,6 +41,7 @@ func TestDiskDeploymentOptions(t *testing.T) {
},
},
},
DeploymentStrategy: appsv1.DeploymentStrategy{Type: appsv1.RecreateDeploymentStrategyType},
})
})

Expand Down Expand Up @@ -67,6 +69,7 @@ func TestDiskDeploymentOptions(t *testing.T) {
},
},
},
DeploymentStrategy: appsv1.DeploymentStrategy{Type: appsv1.RecreateDeploymentStrategyType},
})
})
}
1 change: 1 addition & 0 deletions pkg/limitador/k8s_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down

0 comments on commit 89fb4b6

Please sign in to comment.