Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug where StatefulSets continued to update forever #1702

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
k8s.io/code-generator v0.27.0-alpha.2
k8s.io/klog/v2 v2.80.1
k8s.io/kubectl v0.25.4
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
chitoku-k marked this conversation as resolved.
Show resolved Hide resolved
sigs.k8s.io/structured-merge-diff/v4 v4.2.3
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1558,8 +1558,8 @@ k8s.io/kube-openapi v0.0.0-20230123231816-1cb3ae25d79a h1:s6zvHjyDQX1NtVT88pvw2t
k8s.io/kube-openapi v0.0.0-20230123231816-1cb3ae25d79a/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
k8s.io/kubectl v0.25.4 h1:O3OA1z4V1ZyvxCvScjq0pxAP7ABgznr8UvnVObgI6Dc=
k8s.io/kubectl v0.25.4/go.mod h1:CKMrQ67Bn2YCP26tZStPQGq62zr9pvzEf65A0navm8k=
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk=
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
53 changes: 53 additions & 0 deletions pkg/controller/pools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/ptr"

miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -1079,6 +1080,58 @@ func Test_poolSSMatchesSpec(t *testing.T) {
want: false,
wantErr: false,
},
{
name: "UpdateStrategy Unchanged",
args: args{
expectedSS: &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "tenant-a-pool-0",
},
Spec: appsv1.StatefulSetSpec{
UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
Type: miniov2.DefaultUpdateStrategy,
RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{
MaxUnavailable: nil,
Partition: ptr.To(int32(0)),
},
},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "minio",
},
},
},
},
},
},
existingSS: &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "tenant-a-pool-0",
},
Spec: appsv1.StatefulSetSpec{
UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
Type: miniov2.DefaultUpdateStrategy,
RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{
Partition: ptr.To(int32(0)),
},
},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "minio",
},
},
},
},
},
},
},
want: true,
wantErr: false,
},
{
name: "provide nil statefulset",
args: args{
Expand Down
8 changes: 5 additions & 3 deletions pkg/resources/statefulsets/minio-statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -818,15 +819,15 @@ func NewPool(args *NewPoolArgs) *appsv1.StatefulSet {
}

moreServers := pool.Servers > 4
unavailable := intstr.FromInt(1)
var unavailable *intstr.IntOrString
if moreServers {
// if we have more servers than 4 nodes in a statefulset,
// we can allow rolling update strategy to roll two pods
// at a time instead of just '1' (default), MinIO servers
// beyond 4 servers are capable of tolerating a minimum
// of 2 replicas being down - this allows for faster
// rolling update strategy for all our deployments.
unavailable = intstr.FromInt(2)
unavailable = ptr.To(intstr.FromInt(2))
}

initContainer := getInitContainer(t, operatorImage, pool)
Expand All @@ -837,7 +838,8 @@ func NewPool(args *NewPoolArgs) *appsv1.StatefulSet {
UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
Type: miniov2.DefaultUpdateStrategy,
RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{
MaxUnavailable: &unavailable,
chitoku-k marked this conversation as resolved.
Show resolved Hide resolved
MaxUnavailable: unavailable,
Partition: ptr.To[int32](0),
},
},
PodManagementPolicy: t.Spec.PodManagementPolicy,
Expand Down