Skip to content

Commit

Permalink
restart pvc via rollingupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
rurkss committed Aug 28, 2024
1 parent 08da7a1 commit 8062906
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1.RedisFailover, labels map[stri
ServiceName: name,
Replicas: &rf.Spec.Redis.Replicas,
UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
Type: appsv1.OnDeleteStatefulSetStrategyType,
Type: appsv1.RollingUpdateStatefulSetStrategyType,
},
PodManagementPolicy: appsv1.ParallelPodManagement,
Selector: &metav1.LabelSelector{
Expand Down
15 changes: 14 additions & 1 deletion service/k8s/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,21 @@ func (s *StatefulSetService) UpdateStatefulSet(namespace string, statefulSet *ap
// CreateOrUpdateStatefulSet will update the statefulset or create it if does not exist
func (s *StatefulSetService) CreateOrUpdateStatefulSet(namespace string, statefulSet *appsv1.StatefulSet) error {
storedStatefulSet, err := s.GetStatefulSet(namespace, statefulSet.Name)

annotations := map[string]string{
"storageCapacity": "0",
}

if err != nil {
// If no resource we need to create.
if errors.IsNotFound(err) {
if len(statefulSet.Spec.VolumeClaimTemplates) != 0 {
annotations = map[string]string{
"storageCapacity": fmt.Sprintf("%d", statefulSet.Spec.VolumeClaimTemplates[0].Spec.Resources.Requests.Storage().Value()),
}
}

statefulSet.Spec.Template.Annotations = util.MergeAnnotations(statefulSet.Spec.Template.Annotations, annotations)
return s.CreateStatefulSet(namespace, statefulSet)
}
return err
Expand All @@ -119,7 +131,7 @@ func (s *StatefulSetService) CreateOrUpdateStatefulSet(namespace string, statefu
// 3.2 Writing successful updates to internal
// 4. Set to old VolumeClaimTemplates to update.Prevent update error reporting
// 5. Set to old annotations to update
annotations := storedStatefulSet.Annotations
annotations = storedStatefulSet.Annotations
if annotations == nil {
annotations = map[string]string{
"storageCapacity": "0",
Expand Down Expand Up @@ -171,6 +183,7 @@ func (s *StatefulSetService) CreateOrUpdateStatefulSet(namespace string, statefu
// set stored.volumeClaimTemplates
statefulSet.Spec.VolumeClaimTemplates = storedStatefulSet.Spec.VolumeClaimTemplates
statefulSet.Annotations = util.MergeAnnotations(storedStatefulSet.Annotations, statefulSet.Annotations)
statefulSet.Spec.Template.Annotations = util.MergeAnnotations(annotations, statefulSet.Spec.Template.Annotations)
return s.UpdateStatefulSet(namespace, statefulSet)
}

Expand Down

0 comments on commit 8062906

Please sign in to comment.