Skip to content

Commit

Permalink
refactor: using kubernetes tls secret key names
Browse files Browse the repository at this point in the history
  • Loading branch information
prometherion committed May 5, 2022
1 parent 0119789 commit cb4289d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions controllers/secret/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func (r CAReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl
key, _ = ca.CAPrivateKeyPem()

instance.Data = map[string][]byte{
certSecretKey: crt.Bytes(),
privateKeySecretKey: key.Bytes(),
corev1.TLSCertKey: crt.Bytes(),
corev1.TLSPrivateKeyKey: key.Bytes(),
}

group := new(errgroup.Group)
Expand Down
2 changes: 1 addition & 1 deletion controllers/secret/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func getCertificateAuthority(ctx context.Context, client client.Client, namespac
return nil, MissingCaError{}
}

ca, err = cert.NewCertificateAuthorityFromBytes(instance.Data[certSecretKey], instance.Data[privateKeySecretKey])
ca, err = cert.NewCertificateAuthorityFromBytes(instance.Data[corev1.TLSCertKey], instance.Data[corev1.TLSPrivateKeyKey])
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions controllers/secret/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r TLSReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctr
}

var shouldCreate bool
for _, key := range []string{certSecretKey, privateKeySecretKey} {
for _, key := range []string{corev1.TLSCertKey, corev1.TLSPrivateKeyKey} {
if _, ok := instance.Data[key]; !ok {
shouldCreate = true
break
Expand All @@ -85,13 +85,13 @@ func (r TLSReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctr
return reconcile.Result{}, err
}
instance.Data = map[string][]byte{
certSecretKey: crt.Bytes(),
privateKeySecretKey: key.Bytes(),
corev1.TLSCertKey: crt.Bytes(),
corev1.TLSPrivateKeyKey: key.Bytes(),
}
} else {
var c *x509.Certificate
var b *pem.Block
b, _ = pem.Decode(instance.Data[certSecretKey])
b, _ = pem.Decode(instance.Data[corev1.TLSCertKey])
c, err = x509.ParseCertificate(b.Bytes)
if err != nil {
r.Log.Error(err, "cannot parse Capsule TLS")
Expand Down

0 comments on commit cb4289d

Please sign in to comment.