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

refactor pool-coordinator-cert controller #1364

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions pkg/controller/poolcoordinator/cert/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ func loadCertAndKeyFromSecret(clientSet client.Interface, certConf CertConfig) (
if err != nil {
return nil, nil, errors.Wrapf(err, "couldn't parse the kubeconfig file in the %s secret", secretName)
}
authInfo := kubeConfig.AuthInfos[certConf.CommonName]

authInfo := kubeconfig.GetAuthInfoFromKubeConfig(kubeConfig)
if authInfo == nil {
return nil, nil, errors.Errorf("auth info is not found in secret(%s)", secretName)
}
certBytes = authInfo.ClientCertificateData
keyBytes = authInfo.ClientKeyData
} else {
Expand Down Expand Up @@ -293,7 +295,7 @@ func GetPrivateKeyFromTLSCert(cert *tls.Certificate) (keyPEM []byte, err error)
return keyutil.MarshalPrivateKeyToPEM(cert.PrivateKey)
}

// get certificate & private key (in PEM format) from certmanager
// GetCertAndKeyFromCertMgr will get certificate & private key (in PEM format) from certmanager
func GetCertAndKeyFromCertMgr(certManager certificate.Manager, stopCh <-chan struct{}) (key []byte, cert []byte, err error) {
// waiting for the certificate is generated
certManager.Start()
Expand Down Expand Up @@ -327,7 +329,7 @@ func GetCertAndKeyFromCertMgr(certManager certificate.Manager, stopCh <-chan str
return
}

// write cert&key pair generated from certManager into a secret
// WriteCertIntoSecret will write cert&key pair generated from certManager into a secret
func WriteCertIntoSecret(clientSet client.Interface, certName, secretName string, certManager certificate.Manager, stopCh <-chan struct{}) error {

keyPEM, certPEM, err := GetCertAndKeyFromCertMgr(certManager, stopCh)
Expand All @@ -354,7 +356,7 @@ func WriteCertIntoSecret(clientSet client.Interface, certName, secretName string
return nil
}

// write cert&key into secret
// WriteCertAndKeyIntoSecret is used for writing cert&key into secret
// Notice: if cert OR key is nil, it will be ignored
func WriteCertAndKeyIntoSecret(clientSet client.Interface, certName, secretName string, cert *x509.Certificate, key crypto.Signer) error {
// write certificate data into secret
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/poolcoordinator/cert/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ contexts:
- context:
cluster: cluster
user: openyurt:pool-coordinator:monitoring
name: openyurt:pool-coordinator:monitoring@cluster
name: openyurt:pool-coordinator:monitoring@cluster
current-context: openyurt:pool-coordinator:monitoring@cluster
kind: Config
users:
Expand Down
Loading