Skip to content

Commit

Permalink
Merge branch 'master' into fix1819
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Mar 2, 2020
2 parents ac8d60a + 9b69f6d commit f391b5b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion charts/tidb-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ admissionWebhook:
## validating hook validates the correctness of the resources under pingcap.com group
validating: false
## defaulting hook set default values for the the resources under pingcap.com group
defaulting: false
defaulting: true
## failurePolicy are applied to ValidatingWebhookConfiguration which affect tidb-admission-webhook
## refer to https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#failure-policy
failurePolicy:
Expand Down
2 changes: 1 addition & 1 deletion ci/deploy_tidb_operator_staging.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ admissionWebhook:
pods: true
# TODO: enable validating and defaulting after we ease the constrain
validating: false
defaulting: false
defaulting: true
features:
- AutoScaling=true
'''
Expand Down
6 changes: 5 additions & 1 deletion cmd/admission-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"time"

"github.com/openshift/generic-admission-server/pkg/cmd"

"github.com/pingcap/tidb-operator/pkg/features"
"github.com/pingcap/tidb-operator/pkg/version"
"github.com/pingcap/tidb-operator/pkg/webhook"
"k8s.io/component-base/logs"
"k8s.io/klog"
)

var (
Expand Down Expand Up @@ -51,6 +51,10 @@ func main() {
}
version.LogVersionInfo()

flag.CommandLine.VisitAll(func(flag *flag.Flag) {
klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
})

ah := &webhook.AdmissionHook{
ExtraServiceAccounts: extraServiceAccounts,
EvictRegionLeaderTimeout: evictRegionLeaderTimeout,
Expand Down
4 changes: 4 additions & 0 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func main() {
logs.InitLogs()
defer logs.FlushLogs()

flag.CommandLine.VisitAll(func(flag *flag.Flag) {
klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
})

hostName, err := os.Hostname()
if err != nil {
klog.Fatalf("failed to get hostname: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/discovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func main() {
logs.InitLogs()
defer logs.FlushLogs()

flag.CommandLine.VisitAll(func(flag *flag.Flag) {
klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
})

cfg, err := rest.InClusterConfig()
if err != nil {
klog.Fatalf("failed to get config: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func main() {
logs.InitLogs()
defer logs.FlushLogs()

flag.CommandLine.VisitAll(func(flag *flag.Flag) {
klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
})

cfg, err := rest.InClusterConfig()
if err != nil {
klog.Fatalf("failed to get config: %v", err)
Expand Down
51 changes: 41 additions & 10 deletions pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,59 @@ const (
)

func SetTidbClusterDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiDB.BaseImage == "" {
tc.Spec.TiDB.BaseImage = defaultTiDBImage
setTidbClusterSpecDefault(tc)
setPdSpecDefault(tc)
setTikvSpecDefault(tc)
setTidbSpecDefault(tc)
if tc.Spec.Pump != nil {
setPumpSpecDefault(tc)
}
if tc.Spec.TiKV.BaseImage == "" {
tc.Spec.TiKV.BaseImage = defaultTiKVImage
}

// setTidbClusterSpecDefault is only managed the property under Spec
func setTidbClusterSpecDefault(tc *v1alpha1.TidbCluster) {
if string(tc.Spec.ImagePullPolicy) == "" {
tc.Spec.ImagePullPolicy = corev1.PullIfNotPresent
}
if tc.Spec.PD.BaseImage == "" {
tc.Spec.PD.BaseImage = defaultPDImage
if tc.Spec.EnableTLSCluster == nil {
d := false
tc.Spec.EnableTLSCluster = &d
}
if tc.Spec.Pump != nil && tc.Spec.Pump.BaseImage == "" {
tc.Spec.Pump.BaseImage = defaultBinlogImage
if tc.Spec.EnablePVReclaim == nil {
d := false
tc.Spec.EnablePVReclaim = &d
}
}

func setTidbSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiDB.BaseImage == "" {
tc.Spec.TiDB.BaseImage = defaultTiDBImage
}
if tc.Spec.TiDB.Config == nil {
tc.Spec.TiDB.Config = &v1alpha1.TiDBConfig{}
}
}

func setTikvSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiKV.Config == nil {
tc.Spec.TiKV.Config = &v1alpha1.TiKVConfig{}
}
if tc.Spec.TiKV.BaseImage == "" {
tc.Spec.TiKV.BaseImage = defaultTiKVImage
}
}

func setPdSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.PD.Config == nil {
tc.Spec.PD.Config = &v1alpha1.PDConfig{}
}
if string(tc.Spec.ImagePullPolicy) == "" {
tc.Spec.ImagePullPolicy = corev1.PullIfNotPresent
if tc.Spec.PD.BaseImage == "" {
tc.Spec.PD.BaseImage = defaultPDImage
}
}

func setPumpSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.Pump.BaseImage == "" {
tc.Spec.Pump.BaseImage = defaultBinlogImage
}
}

0 comments on commit f391b5b

Please sign in to comment.