Skip to content

Commit

Permalink
refactor pool-coordinator-cert controller
Browse files Browse the repository at this point in the history
  • Loading branch information
rambohe-ch committed Apr 11, 2023
1 parent 172d551 commit f27e19d
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 148 deletions.
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

0 comments on commit f27e19d

Please sign in to comment.