Skip to content

Commit 9469812

Browse files
rstefan1calind
authored andcommitted
Add support for PodDisruptionBudget
Add tests for PodDisruptionBudget
1 parent 1aa6ee4 commit 9469812

File tree

112 files changed

+2746
-1361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+2746
-1361
lines changed

Gopkg.lock

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@ required = [
3939
# https://github.com/robfig/cron
4040
[[constraint]]
4141
name = "github.com/wgliang/cron"
42-
revision = "79834306f6432d41449e7003710d866ceea9b40c"
42+
revision = "79834306f6432d41449e7003710d866ceea9b40c"
43+
44+
[[constraint]]
45+
# Required: the root import path of the project being constrained.
46+
name = "github.com/appscode/kutil"
47+
# Recommended: the version constraint to enforce for the project.
48+
# Note that only one of "branch", "version" or "revision" can be specified.
49+
branch = "pdb"
50+
51+
# Optional: an alternate location (URL or import path) for the project's source.
52+
source = "https://github.com/presslabs/kutil.git"

deploy/mysqlbackups.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,4 @@ spec:
3434
type: string
3535
required:
3636
- clusterName
37-
required:
38-
- spec
3937
version: v1alpha1
40-
status:
41-
acceptedNames:
42-
kind: ""
43-
plural: ""
44-
conditions: null

deploy/mysqlclusters.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ spec:
4141
is removed from service.
4242
format: int64
4343
type: integer
44+
minAvailable:
45+
anyOf:
46+
- type: string
47+
- type: integer
4448
mysqlConf:
4549
description: A map[string]string that will be passed to my.cnf file.
4650
type: object
@@ -185,11 +189,4 @@ spec:
185189
description: VolumeName is the binding reference to the PersistentVolume
186190
backing this claim.
187191
type: string
188-
required:
189-
- spec
190192
version: v1alpha1
191-
status:
192-
acceptedNames:
193-
kind: ""
194-
plural: ""
195-
conditions: null

examples/example-cluster.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ kind: MysqlCluster
33
metadata:
44
name: foo
55
spec:
6-
replicas: 1
6+
replicas: 3
77
secretName: the-secret
88
# mysqlVersion: 5.7
99
# initBucketUri: gs://bucket_name/backup.xtrabackup.gz
1010
# initBucketSecretName:
1111

12+
## PodDisruptionBudget
13+
# minAvailable: 1
14+
1215
## For recurrent backups set backupSchedule with a cronjob expression
1316
# backupSchedule:
1417
# backupUri: s3://bucket_name/

pkg/apis/mysql/v1alpha1/cluster.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
core "k8s.io/api/core/v1"
2727
"k8s.io/apimachinery/pkg/api/resource"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/util/intstr"
2930

3031
"github.com/presslabs/mysql-operator/pkg/util/options"
3132
)
@@ -42,7 +43,8 @@ const (
4243
)
4344

4445
var (
45-
opt *options.Options
46+
opt *options.Options
47+
DefaultMinAvailable intstr.IntOrString = intstr.FromString("50%")
4648
)
4749

4850
func init() {
@@ -80,6 +82,10 @@ func (c *ClusterSpec) UpdateDefaults(opt *options.Options, cluster *MysqlCluster
8082
c.MysqlConf = make(MysqlConf)
8183
}
8284

85+
if c.MinAvailable == nil && c.Replicas > 1 {
86+
c.MinAvailable = &DefaultMinAvailable
87+
}
88+
8389
// configure mysql based on:
8490
// https://www.percona.com/blog/2018/03/26/mysql-8-0-innodb_dedicated_server-variable-optimizes-innodb/
8591

@@ -225,6 +231,8 @@ const (
225231
MasterService ResourceName = "master-service"
226232
// HealthyNodes is the name of a service that continas all healthy nodes
227233
HealthyNodesService ResourceName = "healthy-nodes-service"
234+
// PodDisruptionBudget is the name of pod disruption budget for the stateful set
235+
PodDisruptionBudget ResourceName = "pdb"
228236
)
229237

230238
func (c *MysqlCluster) GetNameForResource(name ResourceName) string {

pkg/apis/mysql/v1alpha1/status.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ const (
155155
EventReasonMasterServiceUpdated = "MasterServiceUpdated"
156156
EventReasonHealthyNodesServiceFailed = "HealthyNodesServiceFailed"
157157
EventReasonHealthyNodesServiceUpdated = "HealthyNodesServiceUpdated"
158+
EventReasonPDBFailed = "PodDisruptionBudgetFailed"
159+
EventReasonPDBUpdated = "PodDisruptionBudgetUpdated"
158160
)
159161

160162
// Event types

pkg/apis/mysql/v1alpha1/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1alpha1
1919
import (
2020
core "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/util/intstr"
2223
)
2324

2425
// +genclient
@@ -67,6 +68,12 @@ type ClusterSpec struct {
6768
InitBucketUri string `json:"initBucketUri,omitempty"`
6869
InitBucketSecretName string `json:"initBucketSecretName,omitempty"`
6970

71+
// The number of pods from that set that must still be available after the
72+
// eviction, even in the absence of the evicted pod
73+
// Defaults to 50%
74+
// +optional
75+
MinAvailable *intstr.IntOrString `json:"minAvailable,omitempty"`
76+
7077
// Specify under crontab format interval to take backups
7178
// leave it empty to deactivate the backup process
7279
// Defaults to ""

pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package v1alpha1
2323
import (
2424
v1 "k8s.io/api/core/v1"
2525
runtime "k8s.io/apimachinery/pkg/runtime"
26+
intstr "k8s.io/apimachinery/pkg/util/intstr"
2627
)
2728

2829
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
@@ -101,6 +102,15 @@ func (in *ClusterCondition) DeepCopy() *ClusterCondition {
101102
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
102103
func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
103104
*out = *in
105+
if in.MinAvailable != nil {
106+
in, out := &in.MinAvailable, &out.MinAvailable
107+
if *in == nil {
108+
*out = nil
109+
} else {
110+
*out = new(intstr.IntOrString)
111+
**out = **in
112+
}
113+
}
104114
if in.MysqlConf != nil {
105115
in, out := &in.MysqlConf, &out.MysqlConf
106116
*out = make(MysqlConf, len(*in))

pkg/mysqlcluster/cluster.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const (
8484
statusFailed = "failed"
8585
statusOk = "ok"
8686
statusSkip = "skip"
87+
statusDeleted = "deleted"
8788
)
8889

8990
type component struct {
@@ -141,6 +142,13 @@ func (f *cFactory) getComponents() []component {
141142
reasonFailed: api.EventReasonHealthyNodesServiceFailed,
142143
reasonUpdated: api.EventReasonHealthyNodesServiceUpdated,
143144
},
145+
component{
146+
alias: "pdb",
147+
name: f.cluster.GetNameForResource(api.PodDisruptionBudget),
148+
syncFn: f.syncPDB,
149+
reasonFailed: api.EventReasonPDBFailed,
150+
reasonUpdated: api.EventReasonPDBUpdated,
151+
},
144152
}
145153
}
146154

0 commit comments

Comments
 (0)