Move IssuerKind to ./pkg/util
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
This commit is contained in:
parent
ab838197fc
commit
294d8ae93d
@ -20,6 +20,7 @@ go_library(
|
||||
"//pkg/issuer:go_default_library",
|
||||
"//pkg/logs:go_default_library",
|
||||
"//pkg/metrics:go_default_library",
|
||||
"//pkg/util:go_default_library",
|
||||
"//pkg/util/pki:go_default_library",
|
||||
"//vendor/github.com/go-logr/logr:go_default_library",
|
||||
"//vendor/github.com/kr/pretty:go_default_library",
|
||||
|
||||
@ -12,6 +12,7 @@ go_library(
|
||||
"//pkg/controller/certificaterequests:go_default_library",
|
||||
"//pkg/issuer:go_default_library",
|
||||
"//pkg/logs:go_default_library",
|
||||
"//pkg/util:go_default_library",
|
||||
"//pkg/util/kube:go_default_library",
|
||||
"//pkg/util/pki:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
|
||||
@ -31,6 +31,7 @@ import (
|
||||
"github.com/jetstack/cert-manager/pkg/controller/certificaterequests"
|
||||
"github.com/jetstack/cert-manager/pkg/issuer"
|
||||
logf "github.com/jetstack/cert-manager/pkg/logs"
|
||||
"github.com/jetstack/cert-manager/pkg/util"
|
||||
"github.com/jetstack/cert-manager/pkg/util/kube"
|
||||
"github.com/jetstack/cert-manager/pkg/util/pki"
|
||||
)
|
||||
@ -83,7 +84,7 @@ func (c *CA) Sign(ctx context.Context, cr *v1alpha1.CertificateRequest) (*issuer
|
||||
if k8sErrors.IsNotFound(err) {
|
||||
apiutil.SetCertificateRequestCondition(cr, v1alpha1.CertificateRequestConditionReady,
|
||||
v1alpha1.ConditionFalse, v1alpha1.CertificateRequestReasonPending,
|
||||
fmt.Sprintf("Referenced %s not found", certificaterequests.IssuerKind(cr)))
|
||||
fmt.Sprintf("Referenced %s not found", util.IssuerKind(cr.Spec.IssuerRef)))
|
||||
|
||||
c.recorder.Event(cr, corev1.EventTypeWarning, v1alpha1.CertificateRequestReasonPending, err.Error())
|
||||
|
||||
@ -114,7 +115,7 @@ func (c *CA) Sign(ctx context.Context, cr *v1alpha1.CertificateRequest) (*issuer
|
||||
if err != nil {
|
||||
apiutil.SetCertificateRequestCondition(cr, v1alpha1.CertificateRequestConditionReady,
|
||||
v1alpha1.ConditionFalse, v1alpha1.CertificateRequestReasonPending,
|
||||
fmt.Sprintf("Referenced %s not found", certificaterequests.IssuerKind(cr)))
|
||||
fmt.Sprintf("Referenced %s not found", util.IssuerKind(cr.Spec.IssuerRef)))
|
||||
|
||||
log.Error(err, "error generating certificate template")
|
||||
c.recorder.Eventf(cr, corev1.EventTypeWarning, "ErrorSigning", "Error generating certificate template: %v", err)
|
||||
|
||||
@ -32,6 +32,7 @@ import (
|
||||
"github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
|
||||
"github.com/jetstack/cert-manager/pkg/apis/certmanager/validation"
|
||||
logf "github.com/jetstack/cert-manager/pkg/logs"
|
||||
"github.com/jetstack/cert-manager/pkg/util"
|
||||
"github.com/jetstack/cert-manager/pkg/util/pki"
|
||||
)
|
||||
|
||||
@ -68,7 +69,7 @@ func (c *Controller) Sync(ctx context.Context, cr *v1alpha1.CertificateRequest)
|
||||
if k8sErrors.IsNotFound(err) {
|
||||
apiutil.SetCertificateRequestCondition(crCopy, v1alpha1.CertificateRequestConditionReady,
|
||||
v1alpha1.ConditionFalse, v1alpha1.CertificateRequestReasonPending,
|
||||
fmt.Sprintf("Referenced %s not found", IssuerKind(crCopy)))
|
||||
fmt.Sprintf("Referenced %s not found", util.IssuerKind(crCopy.Spec.IssuerRef)))
|
||||
|
||||
c.recorder.Eventf(crCopy, corev1.EventTypeWarning, v1alpha1.CertificateRequestReasonPending, err.Error())
|
||||
|
||||
@ -92,7 +93,7 @@ func (c *Controller) Sync(ctx context.Context, cr *v1alpha1.CertificateRequest)
|
||||
if err != nil {
|
||||
apiutil.SetCertificateRequestCondition(crCopy, v1alpha1.CertificateRequestConditionReady,
|
||||
v1alpha1.ConditionFalse, v1alpha1.CertificateRequestReasonPending,
|
||||
fmt.Sprintf("Referenced %s not found", IssuerKind(crCopy)))
|
||||
fmt.Sprintf("Referenced %s not found", util.IssuerKind(crCopy.Spec.IssuerRef)))
|
||||
|
||||
c.recorder.Eventf(crCopy, corev1.EventTypeWarning, v1alpha1.CertificateRequestReasonPending, err.Error())
|
||||
log.Error(err, "failed to obtain referenced issuer type")
|
||||
@ -192,11 +193,3 @@ func (c *Controller) updateCertificateRequestStatus(ctx context.Context, old, ne
|
||||
// for CRDs (https://github.com/kubernetes/kubernetes/issues/38113)
|
||||
return c.cmClient.CertmanagerV1alpha1().CertificateRequests(new.Namespace).Update(new)
|
||||
}
|
||||
|
||||
// issuerKind returns the kind of issuer for a certificaterequest
|
||||
func IssuerKind(cr *v1alpha1.CertificateRequest) string {
|
||||
if cr.Spec.IssuerRef.Kind == "" {
|
||||
return v1alpha1.IssuerKind
|
||||
}
|
||||
return cr.Spec.IssuerRef.Kind
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ import (
|
||||
logf "github.com/jetstack/cert-manager/pkg/logs"
|
||||
"github.com/jetstack/cert-manager/pkg/metrics"
|
||||
"github.com/jetstack/cert-manager/pkg/scheduler"
|
||||
"github.com/jetstack/cert-manager/pkg/util"
|
||||
"github.com/jetstack/cert-manager/pkg/util/errors"
|
||||
"github.com/jetstack/cert-manager/pkg/util/kube"
|
||||
"github.com/jetstack/cert-manager/pkg/util/pki"
|
||||
@ -894,7 +895,7 @@ func setSecretValues(ctx context.Context, crt *cmapi.Certificate, s *corev1.Secr
|
||||
|
||||
s.Annotations[cmapi.CertificateNameKey] = crt.Name
|
||||
s.Annotations[cmapi.IssuerNameAnnotationKey] = crt.Spec.IssuerRef.Name
|
||||
s.Annotations[cmapi.IssuerKindAnnotationKey] = issuerKind(crt.Spec.IssuerRef)
|
||||
s.Annotations[cmapi.IssuerKindAnnotationKey] = util.IssuerKind(crt.Spec.IssuerRef)
|
||||
|
||||
// if the certificate data is empty, clear the subject related annotations
|
||||
if len(data.cert) == 0 {
|
||||
|
||||
@ -294,7 +294,7 @@ func certificateMatchesSpec(crt *v1alpha1.Certificate, key crypto.Signer, cert *
|
||||
}
|
||||
|
||||
// validate that the issuer kind is correct
|
||||
if issuerKind(crt.Spec.IssuerRef) != secret.Annotations[v1alpha1.IssuerKindAnnotationKey] {
|
||||
if util.IssuerKind(crt.Spec.IssuerRef) != secret.Annotations[v1alpha1.IssuerKindAnnotationKey] {
|
||||
errs = append(errs, fmt.Sprintf("Issuer kind of the certificate is not up to date: %q", secret.Annotations[v1alpha1.IssuerKindAnnotationKey]))
|
||||
}
|
||||
|
||||
@ -329,14 +329,6 @@ func scheduleRenewal(ctx context.Context, lister corelisters.SecretLister, calc
|
||||
log.WithValues("duration_until_renewal", renewIn.String()).Info("certificate scheduled for renewal")
|
||||
}
|
||||
|
||||
// issuerKind returns the kind of issuer for a certificate
|
||||
func issuerKind(ref v1alpha1.ObjectReference) string {
|
||||
if ref.Kind == "" {
|
||||
return v1alpha1.IssuerKind
|
||||
}
|
||||
return ref.Kind
|
||||
}
|
||||
|
||||
func ownerRef(crt *v1alpha1.Certificate) metav1.OwnerReference {
|
||||
controller := true
|
||||
return metav1.OwnerReference{
|
||||
@ -450,7 +442,7 @@ func (c *controller) updateSecret(ctx context.Context, crt *v1alpha1.Certificate
|
||||
// not just when a new certificate is issued
|
||||
if x509Cert != nil {
|
||||
secret.Annotations[v1alpha1.IssuerNameAnnotationKey] = crt.Spec.IssuerRef.Name
|
||||
secret.Annotations[v1alpha1.IssuerKindAnnotationKey] = issuerKind(crt.Spec.IssuerRef)
|
||||
secret.Annotations[v1alpha1.IssuerKindAnnotationKey] = util.IssuerKind(crt.Spec.IssuerRef)
|
||||
secret.Annotations[v1alpha1.CommonNameAnnotationKey] = x509Cert.Subject.CommonName
|
||||
secret.Annotations[v1alpha1.AltNamesAnnotationKey] = strings.Join(x509Cert.DNSNames, ",")
|
||||
secret.Annotations[v1alpha1.IPSANAnnotationKey] = strings.Join(pki.IPAddressesToString(x509Cert.IPAddresses), ",")
|
||||
|
||||
@ -5,6 +5,7 @@ go_library(
|
||||
srcs = [
|
||||
"context.go",
|
||||
"ingress.go",
|
||||
"issuer.go",
|
||||
"useragent.go",
|
||||
"util.go",
|
||||
"version.go",
|
||||
@ -16,6 +17,7 @@ go_library(
|
||||
"AppGitCommit": "{STABLE_APP_GIT_COMMIT}",
|
||||
"AppGitState": "{STABLE_APP_GIT_STATE}",
|
||||
},
|
||||
deps = ["//pkg/apis/certmanager/v1alpha1:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
|
||||
29
pkg/util/issuer.go
Normal file
29
pkg/util/issuer.go
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright 2019 The Jetstack cert-manager contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
|
||||
)
|
||||
|
||||
// issuerKind returns the kind of issuer for a certificate
|
||||
func IssuerKind(ref v1alpha1.ObjectReference) string {
|
||||
if ref.Kind == "" {
|
||||
return v1alpha1.IssuerKind
|
||||
}
|
||||
return ref.Kind
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user