mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-19 09:51:55 +08:00
fix typo, get annotations from cert.
This commit is contained in:
parent
5411b9cb92
commit
46dccb176e
@ -2,9 +2,13 @@ package deployer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/x509"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
k8sMetaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
k8sMetaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
@ -65,6 +69,14 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context) error {
|
|||||||
if secretDataKeyForKey == "" {
|
if secretDataKeyForKey == "" {
|
||||||
namespace = "tls.key"
|
namespace = "tls.key"
|
||||||
}
|
}
|
||||||
|
block, _ := pem.Decode([]byte(d.option.Certificate.Certificate))
|
||||||
|
if block == nil {
|
||||||
|
return fmt.Errorf("failed to parse certificate PEM")
|
||||||
|
}
|
||||||
|
cert, err := x509.ParseCertificate(block.Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse certificate: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
secretPayload := corev1.Secret{
|
secretPayload := corev1.Secret{
|
||||||
TypeMeta: k8sMetaV1.TypeMeta{
|
TypeMeta: k8sMetaV1.TypeMeta{
|
||||||
@ -74,9 +86,10 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context) error {
|
|||||||
ObjectMeta: k8sMetaV1.ObjectMeta{
|
ObjectMeta: k8sMetaV1.ObjectMeta{
|
||||||
Name: secretName,
|
Name: secretName,
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"certimage/alt-names": d.option.Domain,
|
"certimate/domains": d.option.Domain,
|
||||||
"certimage/common-name": d.option.Domain,
|
"certimate/alt-names": strings.Join(cert.DNSNames, ","),
|
||||||
"certimage/issuer-name": d.option.DeployConfig.Id,
|
"certimate/common-name": cert.Subject.CommonName,
|
||||||
|
"certimate/issuer-organization": strings.Join(cert.Issuer.Organization, ","),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: corev1.SecretType("kubernetes.io/tls"),
|
Type: corev1.SecretType("kubernetes.io/tls"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user