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

change cert generate method and add pd and kv webhook #406

Merged
merged 11 commits into from
Apr 29, 2019

Conversation

shuijing198799
Copy link
Contributor

  1. auto generator ca key crt file
  2. add kv and pd webhook

@shuijing198799
Copy link
Contributor Author

@weekface @xiaojingchen PTLA

Copy link
Contributor

@xiaojingchen xiaojingchen left a comment

Choose a reason for hiding this comment

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

LGTM

@xiaojingchen
Copy link
Contributor

@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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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)
Copy link
Contributor

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.

glog.Infof("savely delete pod namespace %s name %s content %s", nameSpace, name, string(content))
}

} else if pod.Labels["app.kubernetes.io/component"] == "pd" {
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
} else if pod.Labels["app.kubernetes.io/component"] == "pd" {
} else if pod.Labels[label.ComponentLabelKey] == "pd" {

}

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" {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

podIP := tc.Status.PD.Leader.ClientURL
for _, store := range tc.Status.TiKV.Stores {
if store.PodName == name {
storeID = store.ID
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
storeID = store.ID
storeID = store.ID
break

@@ -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")
Copy link
Contributor

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.

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

}
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

return error here.

Copy link
Contributor

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

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

@shuijing198799
Copy link
Contributor Author

/run-e2e-tests


}

if kvLeaders, err = getAllKVLeaders(tc, httpClient); err != nil {
Copy link
Contributor

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.

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

why not use GetStore:

func (pc *pdClient) GetStore(storeID uint64) (*StoreInfo, error) {

Copy link
Contributor Author

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。

Copy link
Contributor

Choose a reason for hiding this comment

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

what does it mean?

Copy link
Contributor

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

@weekface weekface added the test/stability stability tests label Apr 24, 2019
Copy link
Contributor

@xiaojingchen xiaojingchen left a 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) {
Copy link
Contributor

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
Copy link
Contributor

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.

if err != nil {
reviewResponse.Allowed = false
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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)
return &reviewResponse
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@shuijing198799
Copy link
Contributor Author

/run-e2e-tests

@shuijing198799
Copy link
Contributor Author

/run-e2e-tests

@shuijing198799
Copy link
Contributor Author

/run-e2e-tests

3 similar comments
@shuijing198799
Copy link
Contributor Author

/run-e2e-tests

@shuijing198799
Copy link
Contributor Author

/run-e2e-tests

@shuijing198799
Copy link
Contributor Author

/run-e2e-tests

@weekface weekface merged commit 0bfd6dc into pingcap:master Apr 29, 2019
yahonda pushed a commit that referenced this pull request Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test/stability stability tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants