Skip to content

Commit

Permalink
able to scale in/out with delete slots feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cofyc committed Dec 23, 2019
1 parent c781ba1 commit 1a007b1
Show file tree
Hide file tree
Showing 32 changed files with 1,345 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rules:
- apiGroups:
- ''
resources:
- 'events'
- 'pods'
- 'persistentvolumeclaims'
- 'persistentvolumes'
Expand Down
5 changes: 3 additions & 2 deletions charts/tidb-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ apiserver:
# AdvancedStatefulSet controller.
# Note that AdvancedStatefulSet CRD must be installed manually via the following
# command:
# kubectl apply -f manifests/advanced-statefulset-crd.v1beta1.yaml
# kubectl apply -f manifests/advanced-statefulset-crd.v1beta1.yaml # k8s version < 1.16.0
# kubectl apply -f manifests/advanced-statefulset-crd.v1.yaml # k8s version >= 1.16.0
advancedStatefulset:
create: false
image: pingcap/advanced-statefulset:v0.1.0
image: pingcap/advanced-statefulset:v0.2.1
imagePullPolicy: IfNotPresent
serviceAccount: advanced-statefulset-controller
logLevel: 2
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
"time"

"github.com/pingcap/advanced-statefulset/pkg/apis/apps/v1alpha1/helper"
"github.com/pingcap/advanced-statefulset/pkg/apis/apps/v1/helper"
asclientset "github.com/pingcap/advanced-statefulset/pkg/client/clientset/versioned"
"github.com/pingcap/tidb-operator/pkg/client/clientset/versioned"
informers "github.com/pingcap/tidb-operator/pkg/client/informers/externalversions"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
github.com/openshift/generic-admission-server v1.14.0
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/pingcap/advanced-statefulset v0.1.0
github.com/pingcap/advanced-statefulset v0.2.1
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8 // indirect
github.com/pingcap/errors v0.11.0
github.com/pingcap/kvproto v0.0.0-20190516013202-4cf58ad90b6c
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,10 @@ github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+v
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pingcap/advanced-statefulset v0.1.0 h1:rjUx6Tc90YwlRrgIXWTvjr8D97fx0GP4E49dObmBqj0=
github.com/pingcap/advanced-statefulset v0.1.0/go.mod h1:rg2p1v6AGsKhvEZi6Sm0YNYJCmdXdZZhQ6Sviei7Ivs=
github.com/pingcap/advanced-statefulset v0.2.0 h1:XtMrL6WOlmsKQv8j/IAAfDNq2rpCs6EylyT7ABeh7bw=
github.com/pingcap/advanced-statefulset v0.2.0/go.mod h1:rg2p1v6AGsKhvEZi6Sm0YNYJCmdXdZZhQ6Sviei7Ivs=
github.com/pingcap/advanced-statefulset v0.2.1 h1:XgPBAj7aUDogWLUAZp/MHUcQv0i092Qij6oc0wclePg=
github.com/pingcap/advanced-statefulset v0.2.1/go.mod h1:rg2p1v6AGsKhvEZi6Sm0YNYJCmdXdZZhQ6Sviei7Ivs=
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8 h1:USx2/E1bX46VG32FIw034Au6seQ2fY9NEILmNh/UlQg=
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8/go.mod h1:B1+S9LNcuMyLH/4HMTViQOJevkGiik3wW2AN9zb2fNQ=
github.com/pingcap/errors v0.11.0 h1:DCJQB8jrHbQ1VVlMFIrbj2ApScNNotVmkSNplu2yUt4=
Expand Down
161 changes: 161 additions & 0 deletions manifests/advanced-statefulset-crd.v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# For Kubernetes 1.16+.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: statefulsets.apps.pingcap.com
spec:
group: apps.pingcap.com
versions:
- name: v1alpha1
served: true
storage: false
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
required:
- replicas
- selector
- template
- serviceName
properties:
replicas:
type: integer
minimum: 0
default: 1
selector:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
template:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
volumeClaimTemplates:
type: array
items:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
serviceName:
type: string
podManagementPolicy:
type: string
# TODO OrderedReady/Parallel
updateStrategy:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
revisionHistoryLimit:
type: integer
minimum: 0
default: 10
status:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
additionalPrinterColumns:
- name: Desired
type: integer
jsonPath: .spec.replicas
- name: Current
type: integer
jsonPath: .status.readyReplicas
- name: Age
type: date
jsonPath: .metadata.creationTimestamp
# subresources describes the subresources for custom resources.
subresources:
# status enables the status subresource.
status: {}
# scale enables the scale subresource.
scale:
# specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
specReplicasPath: .spec.replicas
# statusReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Replicas.
statusReplicasPath: .status.replicas
# labelSelectorPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Selector.
labelSelectorPath: .status.labelSelector
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
required:
- replicas
- selector
- template
- serviceName
properties:
replicas:
type: integer
minimum: 0
default: 1
selector:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
template:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
volumeClaimTemplates:
type: array
items:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
serviceName:
type: string
podManagementPolicy:
type: string
# TODO OrderedReady/Parallel
updateStrategy:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
revisionHistoryLimit:
type: integer
minimum: 0
default: 10
status:
type: object
# TODO validate all fields
x-kubernetes-preserve-unknown-fields: true
additionalPrinterColumns:
- name: Desired
type: integer
jsonPath: .spec.replicas
- name: Current
type: integer
jsonPath: .status.readyReplicas
- name: Age
type: date
jsonPath: .metadata.creationTimestamp
# subresources describes the subresources for custom resources.
subresources:
# status enables the status subresource.
status: {}
# scale enables the scale subresource.
scale:
# specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
specReplicasPath: .spec.replicas
# statusReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Replicas.
statusReplicasPath: .status.replicas
# labelSelectorPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Selector.
labelSelectorPath: .status.labelSelector
scope: Namespaced
names:
plural: statefulsets
singular: statefulset
kind: StatefulSet
shortNames:
- asts
categories:
- all
39 changes: 31 additions & 8 deletions manifests/advanced-statefulset-crd.v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
# For Kubernetes before 1.16.
# TODO more validations, etc.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: statefulsets.apps.pingcap.com
spec:
group: apps.pingcap.com
version: v1alpha1
scope: Namespaced
names:
plural: statefulsets
singular: statefulset
kind: StatefulSet
shortNames:
- asts
versions:
- name: v1alpha1
served: true
storage: false
- name: v1
served: true
storage: true
validation:
openAPIV3Schema:
type: object
properties:
spec:
type: object
required:
- replicas
- selector
- template
- serviceName
properties:
replicas:
type: integer
minimum: 0
selector:
type: object
template:
type: object
volumeClaimTemplates:
type: array
serviceName:
type: string
template:
podManagementPolicy:
type: string
pattern: '^(OrderedReady|Parallel)$'
updateStrategy:
type: object
revisionHistoryLimit:
type: integer
minimum: 1
versions:
- name: v1alpha1
served: true
storage: true
minimum: 0
# subresources describes the subresources for custom resources.
subresources:
# status enables the status subresource.
Expand All @@ -49,3 +62,13 @@ spec:
statusReplicasPath: .status.replicas
# labelSelectorPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Selector.
labelSelectorPath: .status.labelSelector
additionalPrinterColumns:
- name: Desired
type: integer
JSONPath: .spec.replicas
- name: Current
type: integer
JSONPath: .status.readyReplicas
- name: Age
type: date
JSONPath: .metadata.creationTimestamp
39 changes: 39 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package features
import (
"flag"
"fmt"
"strconv"
"strings"
"sync"

utilflags "github.com/pingcap/tidb-operator/pkg/util/flags"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -45,9 +47,15 @@ type FeatureGate interface {
AddFlag(flagset *flag.FlagSet)
// Enabled returns true if the key is enabled.
Enabled(key string) bool
// Set parses and stores flag gates for known features
// from a string like feature1=true,feature2=false,...
Set(value string) error
// SetFromMap stores flag gates for enabled features from a map[string]bool
SetFromMap(m map[string]bool)
}

type featureGate struct {
lock sync.Mutex
enabledFeatures map[string]bool
}

Expand All @@ -62,6 +70,37 @@ func (f *featureGate) Enabled(key string) bool {
return false
}

func (f *featureGate) Set(value string) error {
m := make(map[string]bool)
for _, s := range strings.Split(value, ",") {
if len(s) == 0 {
continue
}
arr := strings.SplitN(s, "=", 2)
k := strings.TrimSpace(arr[0])
if len(arr) != 2 {
return fmt.Errorf("missing bool value for %s", k)
}
v := strings.TrimSpace(arr[1])
boolValue, err := strconv.ParseBool(v)
if err != nil {
return fmt.Errorf("invalid value of %s=%s, err: %v", k, v, err)
}
m[k] = boolValue
}
f.SetFromMap(m)
return nil
}

func (f *featureGate) SetFromMap(m map[string]bool) {
f.lock.Lock()
defer f.lock.Unlock()

for k, v := range m {
f.enabledFeatures[k] = v
}
}

func NewFeatureGate() FeatureGate {
f := &featureGate{
enabledFeatures: make(map[string]bool),
Expand Down
7 changes: 7 additions & 0 deletions pkg/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ const (
// AnnSysctlInitVal is pod annotation value to indicate whether configuring sysctls with init container
AnnSysctlInitVal = "true"

// AnnPDDeleteSlots is annotation key of pd delete slots.
AnnPDDeleteSlots = "pd.tidb.pingcap.com/delete-slots"
// TiDBDeleteSlots is annotation key of tidb delete slots.
AnnTiDBDeleteSlots = "tidb.tidb.pingcap.com/delete-slots"
// TiKVDeleteSlots is annotation key of tikv delete slots.
AnnTiKVDeleteSlots = "tikv.tidb.pingcap.com/delete-slots"

// PDLabelVal is PD label value
PDLabelVal string = "pd"
// TiDBLabelVal is TiDB label value
Expand Down
Loading

0 comments on commit 1a007b1

Please sign in to comment.