-
Notifications
You must be signed in to change notification settings - Fork 500
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
change cert generate method and add pd and kv webhook #406
Conversation
shuijing198799
commented
Apr 18, 2019
- auto generator ca key crt file
- add kv and pd webhook
@weekface @xiaojingchen PTLA |
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.
LGTM
@onlymellb PTAL the cert generate method |
func SetupServerCert(namespaceName, serviceName string) *CertContext { | ||
certDir, err := ioutil.TempDir("", "test-e2e-server-cert") | ||
if err != nil { | ||
glog.Errorf("Failed to create a temp dir for cert generation %v", err) |
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.
You should return an error.
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.
all done
} | ||
signingCert, err := cert.NewSelfSignedCACert(cert.Config{CommonName: "e2e-server-cert-ca"}, signingKey) | ||
if err != nil { | ||
glog.Errorf("Failed to create CA cert for apiserver %v", err) |
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.
ditto
} | ||
caCertFile, err := ioutil.TempFile(certDir, "ca.crt") | ||
if err != nil { | ||
glog.Errorf("Failed to create a temp file for ca cert generation %v", err) |
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.
and all these should return a error.
tests/pkg/webhook/pods.go
Outdated
glog.Infof("savely delete pod namespace %s name %s content %s", nameSpace, name, string(content)) | ||
} | ||
|
||
} else if pod.Labels["app.kubernetes.io/component"] == "pd" { |
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.
} else if pod.Labels["app.kubernetes.io/component"] == "pd" { | |
} else if pod.Labels[label.ComponentLabelKey] == "pd" { |
tests/pkg/webhook/pods.go
Outdated
} | ||
|
||
if info.IsOwner { | ||
glog.Errorf("tidb is ddl owner, can't be deleted namespace %s name %s", nameSpace, name) | ||
} else if pod.Labels["app.kubernetes.io/component"] == "tikv" { |
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.
ditto
tests/pkg/webhook/pods.go
Outdated
podIP := tc.Status.PD.Leader.ClientURL | ||
for _, store := range tc.Status.TiKV.Stores { | ||
if store.PodName == name { | ||
storeID = store.ID |
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.
storeID = store.ID | |
storeID = store.ID | |
break |
tests/cmd/e2e/main.go
Outdated
@@ -40,7 +40,10 @@ func main() { | |||
|
|||
cli, kubeCli := client.NewCliOrDie() | |||
|
|||
context := apimachinery.SetupServerCert(os.Getenv("NAMESPACE"), "webhook-service") | |||
context, err := apimachinery.SetupServerCert(os.Getenv("NAMESPACE"), "webhook-service") |
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.
merge this function into StartValidatingAdmissionWebhookServerOrDie
.
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.
done
} | ||
caCertFile, err := ioutil.TempFile(certDir, "ca.crt") | ||
if err != nil { | ||
glog.Errorf("Failed to create a temp file for ca cert generation %v", err) | ||
return nil, err | ||
} | ||
if err := ioutil.WriteFile(caCertFile.Name(), cert.EncodeCertPEM(signingCert), 0644); err != nil { | ||
glog.Errorf("Failed to write CA cert %v", err) |
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.
return error here.
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.
this should be fixed also
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.
done
/run-e2e-tests |
tests/pkg/webhook/pods.go
Outdated
|
||
} | ||
|
||
if kvLeaders, err = getAllKVLeaders(tc, httpClient); err != nil { |
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.
the getAllKVLeaders
should be called outside admitPods, best in the init phase of the webhook server.
tests/pkg/webhook/pods.go
Outdated
ret = make(map[string]int) | ||
podIP := tc.Status.PD.Leader.ClientURL | ||
for _, store := range tc.Status.TiKV.Stores { | ||
url := fmt.Sprintf("%s/pd/api/v1/store/%s", podIP, store.ID) |
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.
why not use GetStore
:
tidb-operator/pkg/controller/pd_control.go
Line 292 in ebd499e
func (pc *pdClient) GetStore(storeID uint64) (*StoreInfo, error) { |
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.
get store have no pod name。
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.
what does it mean?
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.
use GetStore
is better,it only needs storeID
and less codes
… to record the number
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.
LGTM
@@ -89,6 +96,37 @@ func (tdc *defaultTiDBControl) ResignDDLOwner(tc *v1alpha1.TidbCluster, ordinal | |||
return false, err2 | |||
} | |||
|
|||
func (tdc *defaultTiDBControl) GetInfo(tc *v1alpha1.TidbCluster, ordinal int32) (*dbInfo, error) { |
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.
Open an issue to remember to add unit tests to cover this method.
if err != nil { | ||
reviewResponse.Allowed = false |
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.
Why delete this line? reviewResponse.Allowed
default is true.
tests/pkg/webhook/pods.go
Outdated
if err != nil { | ||
reviewResponse.Allowed = false |
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.
ditto
if err != nil { | ||
glog.Errorf("fail to read response %v", err) | ||
glog.Errorf("fail to convert string to int while deleting TiDB err %v", err) | ||
return &reviewResponse |
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.
ditto
if err != nil { | ||
glog.Errorf("unmarshal failed,namespace %s name %s error:%v", nameSpace, name, err) | ||
glog.Errorf("fail to get tidb info error:%v", err) |
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.
ditto
tests/pkg/webhook/pods.go
Outdated
if err != nil { | ||
glog.Errorf("fail to read response %v", err) | ||
return &reviewResponse |
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.
ditto
err = json.Unmarshal(content, leader) | ||
if err != nil { | ||
glog.Errorf("unmarshal failed,namespace %s name %s error:%v", nameSpace, name, err) | ||
glog.Errorf("fail to get pd leader %v", err) |
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.
ditto
storeID, err = strconv.ParseUint(store.ID, 10, 64) | ||
if err != nil { | ||
glog.Errorf("fail to convert string to int while deleting PD err %v", err) | ||
return &reviewResponse |
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.
ditto
glog.Errorf("fail to read response %v", err) | ||
// Fail to get store in stores | ||
if storeID == 0 { | ||
glog.Errorf("fail to find store in TIKV.Stores podname %s", name) |
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.
ditto
if err != nil { | ||
glog.Errorf("unmarshal failed,namespace %s name %s error:%v", nameSpace, name, err) | ||
glog.Errorf("fail to read storeID %d response %v", storeID, err) |
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.
ditto
/run-e2e-tests |
/run-e2e-tests |
/run-e2e-tests |
3 similar comments
/run-e2e-tests |
/run-e2e-tests |
/run-e2e-tests |