-
Notifications
You must be signed in to change notification settings - Fork 502
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
Changes from 1 commit
d61af18
9a3b917
841cf41
26acae3
847c00e
b94ef93
2e2d8da
635d3b1
178115e
3fa15d8
fe4387e
f64fa78
3ebdec4
01dbd25
35f3dd4
3100024
2f7de79
d9f7a4c
97c220e
97aed78
d43eb93
d63b0d2
c16cc2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||||||||||||||||||||||||
// Copyright 2018 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 | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that k8s does not provide such a admission controller。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems right There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tidb-operator/cmd/controller-manager/main.go Lines 89 to 101 in 617546b
|
||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||
glog.Fatalf("failed to get client: %v", err) | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
ns := os.Getenv("NAMESPACE") | ||||||||||||||||||||||||||||
if ns == "" { | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||||||||||||||||||||||||||||
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.") | ||||||||||||||||||||||||||||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
roleRef: | ||
kind: ClusterRole | ||
name: cluster-admin | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
kind: ServiceAccount | ||
apiVersion: v1 | ||
metadata: | ||
namespace: pingcap | ||
name: admission-webhook-example-sa |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, seems |
||
labels: | ||
app: admission-webhook-example | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why name it |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use downward API to get namespace dynamically. |
||
value: pingcap | ||
- name: SERVICENAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/SERVICENAME/SERVICE_NAME/ |
||
value: admission-webhook-example-svc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.