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

Pause rolling-upgrade process of tidb statefulset #470

Merged
merged 23 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d61af18
add webhook and clietn
shuijing198799 May 9, 2019
9a3b917
make change via comments
shuijing198799 May 10, 2019
841cf41
fix the binary name
shuijing198799 May 10, 2019
26acae3
init deserialzer instead of create it everytime
shuijing198799 May 11, 2019
847c00e
Merge remote-tracking branch 'upstream/master' into pause-upgrade2
shuijing198799 May 15, 2019
b94ef93
1. add pause test 2. use helm to manager 3. fix test case bug 4. dele…
shuijing198799 May 17, 2019
2e2d8da
make check
shuijing198799 May 17, 2019
635d3b1
add rbac yaml
shuijing198799 May 17, 2019
178115e
only pause tidb rolling upgrade once and increse the sleep time
shuijing198799 May 20, 2019
3fa15d8
make check and fix lint
shuijing198799 May 20, 2019
fe4387e
add comment to introduce the usage of admission-controller
shuijing198799 May 21, 2019
f64fa78
Merge branch 'master' into pause-upgrade2
weekface May 21, 2019
3ebdec4
Merge branch 'master' into pause-upgrade2
weekface May 21, 2019
01dbd25
Merge branch 'master' into pause-upgrade2
weekface May 21, 2019
35f3dd4
use yaml to manage the admission-controller and modify via comment
shuijing198799 May 22, 2019
3100024
Merge branch 'pause-upgrade2' of github.com:shuijing198799/tidb-opera…
shuijing198799 May 22, 2019
2f7de79
go fmt
shuijing198799 May 22, 2019
d9f7a4c
make check
shuijing198799 May 22, 2019
97c220e
no sidecar-injector
shuijing198799 May 22, 2019
97aed78
fix manifest dir for e2e test
shuijing198799 May 22, 2019
d43eb93
use common image
shuijing198799 May 22, 2019
d63b0d2
Merge branch 'master' into pause-upgrade2
weekface May 22, 2019
c16cc2a
Merge branch 'master' into pause-upgrade2
weekface May 23, 2019
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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ docker-push: docker
docker: build
docker build --tag "${DOCKER_REGISTRY}/pingcap/tidb-operator:latest" images/tidb-operator

build: controller-manager scheduler discovery
build: controller-manager scheduler discovery webhook

controller-manager:
$(GO) -ldflags '$(LDFLAGS)' -o images/tidb-operator/bin/tidb-controller-manager cmd/controller-manager/main.go
Expand All @@ -40,6 +40,9 @@ scheduler:
discovery:
$(GO) -ldflags '$(LDFLAGS)' -o images/tidb-operator/bin/tidb-discovery cmd/discovery/main.go

webhook:
$(GO) -ldflags '$(LDFLAGS)' -o images/tidb-operator/bin/tidb-webhook cmd/webhook/main.go

e2e-setup:
# ginkgo doesn't work with retool for Go 1.11
@GO111MODULE=on CGO_ENABLED=0 go get github.com/onsi/ginkgo@v1.6.0
Expand Down
84 changes: 84 additions & 0 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2018 PingCAP, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2018 PingCAP, Inc.
// Copyright 2019 PingCAP, Inc.

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that k8s does not provide such a admission controller。

Copy link
Contributor

@weekface weekface May 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webhook is not a nice component name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


import (
"os"
"os/signal"
"syscall"

"github.com/golang/glog"
"github.com/pingcap/tidb-operator/pkg/webhook"
"github.com/pingcap/tidb-operator/pkg/webhook/util"
)

func main() {

cli, kubeCli, err := util.GetNewClient()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfg, err := rest.InClusterConfig()
if err != nil {
glog.Fatalf("failed to get config: %v", err)
}
cli, err := versioned.NewForConfig(cfg)
if err != nil {
glog.Fatalf("failed to create Clientset: %v", err)
}
kubeCli, err := kubernetes.NewForConfig(cfg)
if err != nil {
glog.Fatalf("failed to get kubernetes Clientset: %v", err)
}

if err != nil {
glog.Fatalf("failed to get client: %v", err)
}

ns := os.Getenv("NAMESPACE")
if ns == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use strings.TrimSpace(ns)== ""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use strings.TrimSpace(ns)== ""

glog.Fatalf("fail to get namespace in environment")
}

svc := os.Getenv("SERVICENAME")
if svc == "" {
glog.Fatalf("fail to get servicename in environment")
}

// create cert file
cert, err := util.SetupServerCert(ns, svc)
if err != nil {
glog.Fatalf("fail to setup server cert: %v", err)
}
webhookServer := webhook.NewWebHookServer(kubeCli, cli, cert)

// before start webhook server, create validating-webhook-configuration
err = webhookServer.RegisterWebhook(ns, svc)
if err != nil {
glog.Fatalf("fail to create validaing webhook configuration: %v", err)
}

sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)

signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

go func() {
<-sigs

// FIXME Consider whether delete the configuration when the service is shutdown.
if err := webhookServer.UnregisterWebhook(); err != nil {
glog.Errorf("fail to delete validating configuration %v", err)
}

// Graceful shutdown the server
if err := webhookServer.Shutdown(); err != nil {
glog.Errorf("fail to shutdown server %v", err)
}

done <- true
}()

if err := webhookServer.Run(); err != nil {
glog.Errorf("stop http server %v", err)
}

<-done

glog.Infof("webhook server terminate safely.")
}
1 change: 1 addition & 0 deletions images/tidb-operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ RUN apk add tzdata --no-cache
ADD bin/tidb-controller-manager /usr/local/bin/tidb-controller-manager
ADD bin/tidb-scheduler /usr/local/bin/tidb-scheduler
ADD bin/tidb-discovery /usr/local/bin/tidb-discovery
ADD bin/tidb-webhook /usr/local/bin/tidb-webhook
18 changes: 18 additions & 0 deletions manifests/webhook-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: admission-webhook-example-rbac
subjects:
- kind: ServiceAccount
namespace: pingcap
name: admission-webhook-example-sa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example ?

roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
---
kind: ServiceAccount
apiVersion: v1
metadata:
namespace: pingcap
name: admission-webhook-example-sa
44 changes: 44 additions & 0 deletions manifests/webhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: v1
kind: Service
metadata:
name: admission-webhook-example-svc
namespace: pingcap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave the namespace field to allow user specify it from the command line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, seems namespace is required by cluster role binding. So you can keep it here, but please change it to tidb-admin the default namespace in our documentations.

labels:
app: admission-webhook-example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why name it example?

spec:
ports:
- port: 443
targetPort: 443
selector:
app: admission-webhook-example
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: admission-webhook-example-deployment
namespace: pingcap
labels:
app: admission-webhook-example
spec:
replicas: 1
selector:
matchLabels:
app: admission-webhook-example
template:
metadata:
namespace: pingcap
labels:
app: admission-webhook-example
spec:
serviceAccount: admission-webhook-example-sa
containers:
- name: admission-webhook-example
image: hub.pingcap.net/yinliang/pingcap/tidb-operator:latest
shuijing198799 marked this conversation as resolved.
Show resolved Hide resolved
imagePullPolicy: Always
command:
- /usr/local/bin/tidb-webhook
env:
- name: NAMESPACE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use downward API to get namespace dynamically.

value: pingcap
- name: SERVICENAME
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/SERVICENAME/SERVICE_NAME/

value: admission-webhook-example-svc
2 changes: 2 additions & 0 deletions pkg/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
AnnPVCDeferDeleting = "tidb.pingcap.com/pvc-defer-deleting"
// AnnPVCPodScheduling is pod scheduling annotation key, it represents whether the pod is scheduling
AnnPVCPodScheduling = "tidb.pingcap.com/pod-scheduling"
// AnnTiDBPartition is pod annotation which TiDB pod chould upgrade to
AnnTiDBPartition string = "tidb.pingcap.com/tidb-partition"

// PDLabelVal is PD label value
PDLabelVal string = "pd"
Expand Down
2 changes: 2 additions & 0 deletions pkg/tkctl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb-operator/pkg/tkctl/cmd/get"
"github.com/pingcap/tidb-operator/pkg/tkctl/cmd/info"
"github.com/pingcap/tidb-operator/pkg/tkctl/cmd/list"
"github.com/pingcap/tidb-operator/pkg/tkctl/cmd/upinfo"
"github.com/pingcap/tidb-operator/pkg/tkctl/cmd/use"
"github.com/pingcap/tidb-operator/pkg/tkctl/config"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -69,6 +70,7 @@ func NewTkcCommand(streams genericclioptions.IOStreams) *cobra.Command {
info.NewCmdInfo(tkcContext, streams),
use.NewCmdUse(tkcContext, streams),
version.NewCmdVersion(tkcContext, streams.Out),
upinfo.NewCmdUpInfo(tkcContext, streams),
},
},
{
Expand Down
Loading