|
1 | 1 | package certrotation |
2 | 2 |
|
3 | | -import ( |
4 | | - "github.com/google/go-cmp/cmp" |
5 | | - "github.com/openshift/api/annotations" |
6 | | - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
7 | | - "k8s.io/klog/v2" |
8 | | -) |
| 3 | +import "github.com/openshift/library-go/pkg/operator/tlsartifact" |
| 4 | + |
| 5 | +// AdditionalAnnotations is an alias for tlsartifact.AdditionalAnnotations. |
| 6 | +// Deprecated: Use tlsartifact.AdditionalAnnotations directly. |
| 7 | +type AdditionalAnnotations = tlsartifact.AdditionalAnnotations |
9 | 8 |
|
10 | 9 | const ( |
11 | 10 | // CertificateNotBeforeAnnotation contains the certificate expiration date in RFC3339 format. |
12 | | - CertificateNotBeforeAnnotation = "auth.openshift.io/certificate-not-before" |
| 11 | + // Deprecated: Use tlsartifact.CertificateNotBeforeAnnotation directly. |
| 12 | + CertificateNotBeforeAnnotation = tlsartifact.CertificateNotBeforeAnnotation |
13 | 13 | // CertificateNotAfterAnnotation contains the certificate expiration date in RFC3339 format. |
14 | | - CertificateNotAfterAnnotation = "auth.openshift.io/certificate-not-after" |
| 14 | + // Deprecated: Use tlsartifact.CertificateNotAfterAnnotation directly. |
| 15 | + CertificateNotAfterAnnotation = tlsartifact.CertificateNotAfterAnnotation |
15 | 16 | // CertificateIssuer contains the common name of the certificate that signed another certificate. |
16 | | - CertificateIssuer = "auth.openshift.io/certificate-issuer" |
| 17 | + // Deprecated: Use tlsartifact.CertificateIssuer directly. |
| 18 | + CertificateIssuer = tlsartifact.CertificateIssuer |
17 | 19 | // CertificateHostnames contains the hostnames used by a signer. |
18 | | - CertificateHostnames = "auth.openshift.io/certificate-hostnames" |
| 20 | + // Deprecated: Use tlsartifact.CertificateHostnames directly. |
| 21 | + CertificateHostnames = tlsartifact.CertificateHostnames |
19 | 22 | // CertificateTestNameAnnotation is an e2e test name which verifies that TLS artifact is created and used correctly |
20 | | - CertificateTestNameAnnotation string = "certificates.openshift.io/test-name" |
| 23 | + // Deprecated: Use tlsartifact.CertificateTestNameAnnotation directly. |
| 24 | + CertificateTestNameAnnotation = tlsartifact.CertificateTestNameAnnotation |
21 | 25 | // CertificateAutoRegenerateAfterOfflineExpiryAnnotation contains a link to PR adding this annotation which verifies |
22 | 26 | // that TLS artifact is correctly regenerated after it has expired |
23 | | - CertificateAutoRegenerateAfterOfflineExpiryAnnotation string = "certificates.openshift.io/auto-regenerate-after-offline-expiry" |
| 27 | + // Deprecated: Use tlsartifact.CertificateAutoRegenerateAfterOfflineExpiryAnnotation directly. |
| 28 | + CertificateAutoRegenerateAfterOfflineExpiryAnnotation = tlsartifact.CertificateAutoRegenerateAfterOfflineExpiryAnnotation |
24 | 29 | // CertificateRefreshPeriodAnnotation is the interval at which the certificate should be refreshed. |
25 | | - CertificateRefreshPeriodAnnotation string = "certificates.openshift.io/refresh-period" |
| 30 | + // Deprecated: Use tlsartifact.CertificateRefreshPeriodAnnotation directly. |
| 31 | + CertificateRefreshPeriodAnnotation = tlsartifact.CertificateRefreshPeriodAnnotation |
26 | 32 | ) |
27 | 33 |
|
28 | | -type AdditionalAnnotations struct { |
29 | | - // JiraComponent annotates tls artifacts so that owner could be easily found |
30 | | - JiraComponent string |
31 | | - // Description is a human-readable one sentence description of certificate purpose |
32 | | - Description string |
33 | | - // TestName is an e2e test name which verifies that TLS artifact is created and used correctly |
34 | | - TestName string |
35 | | - // AutoRegenerateAfterOfflineExpiry contains a link to PR which adds this annotation on the TLS artifact |
36 | | - AutoRegenerateAfterOfflineExpiry string |
37 | | - // NotBefore contains certificate the certificate creation date in RFC3339 format. |
38 | | - NotBefore string |
39 | | - // NotAfter contains certificate the certificate validity date in RFC3339 format. |
40 | | - NotAfter string |
41 | | - // RefreshPeriod contains the interval at which the certificate should be refreshed. |
42 | | - RefreshPeriod string |
43 | | -} |
44 | | - |
45 | | -func (a AdditionalAnnotations) EnsureTLSMetadataUpdate(meta *metav1.ObjectMeta) bool { |
46 | | - modified := false |
47 | | - if meta.Annotations == nil { |
48 | | - meta.Annotations = make(map[string]string) |
49 | | - } |
50 | | - if len(a.JiraComponent) > 0 && meta.Annotations[annotations.OpenShiftComponent] != a.JiraComponent { |
51 | | - diff := cmp.Diff(meta.Annotations[annotations.OpenShiftComponent], a.JiraComponent) |
52 | | - klog.V(2).Infof("Updating %q annotation for %s/%s, diff: %s", annotations.OpenShiftComponent, meta.Namespace, meta.Name, diff) |
53 | | - meta.Annotations[annotations.OpenShiftComponent] = a.JiraComponent |
54 | | - modified = true |
55 | | - } |
56 | | - if len(a.Description) > 0 && meta.Annotations[annotations.OpenShiftDescription] != a.Description { |
57 | | - diff := cmp.Diff(meta.Annotations[annotations.OpenShiftDescription], a.Description) |
58 | | - klog.V(2).Infof("Updating %q annotation for %s/%s, diff: %s", annotations.OpenShiftDescription, meta.Namespace, meta.Name, diff) |
59 | | - meta.Annotations[annotations.OpenShiftDescription] = a.Description |
60 | | - modified = true |
61 | | - } |
62 | | - if len(a.TestName) > 0 && meta.Annotations[CertificateTestNameAnnotation] != a.TestName { |
63 | | - diff := cmp.Diff(meta.Annotations[CertificateTestNameAnnotation], a.TestName) |
64 | | - klog.V(2).Infof("Updating %q annotation for %s/%s, diff: %s", CertificateTestNameAnnotation, meta.Name, meta.Namespace, diff) |
65 | | - meta.Annotations[CertificateTestNameAnnotation] = a.TestName |
66 | | - modified = true |
67 | | - } |
68 | | - if len(a.AutoRegenerateAfterOfflineExpiry) > 0 && meta.Annotations[CertificateAutoRegenerateAfterOfflineExpiryAnnotation] != a.AutoRegenerateAfterOfflineExpiry { |
69 | | - diff := cmp.Diff(meta.Annotations[CertificateAutoRegenerateAfterOfflineExpiryAnnotation], a.AutoRegenerateAfterOfflineExpiry) |
70 | | - klog.V(2).Infof("Updating %q annotation for %s/%s, diff: %s", CertificateAutoRegenerateAfterOfflineExpiryAnnotation, meta.Namespace, meta.Name, diff) |
71 | | - meta.Annotations[CertificateAutoRegenerateAfterOfflineExpiryAnnotation] = a.AutoRegenerateAfterOfflineExpiry |
72 | | - modified = true |
73 | | - } |
74 | | - if len(a.NotBefore) > 0 && meta.Annotations[CertificateNotBeforeAnnotation] != a.NotBefore { |
75 | | - diff := cmp.Diff(meta.Annotations[CertificateNotBeforeAnnotation], a.NotBefore) |
76 | | - klog.V(2).Infof("Updating %q annotation for %s/%s, diff: %s", CertificateNotBeforeAnnotation, meta.Name, meta.Namespace, diff) |
77 | | - meta.Annotations[CertificateNotBeforeAnnotation] = a.NotBefore |
78 | | - modified = true |
79 | | - } |
80 | | - if len(a.NotAfter) > 0 && meta.Annotations[CertificateNotAfterAnnotation] != a.NotAfter { |
81 | | - diff := cmp.Diff(meta.Annotations[CertificateNotAfterAnnotation], a.NotAfter) |
82 | | - klog.V(2).Infof("Updating %q annotation for %s/%s, diff: %s", CertificateNotAfterAnnotation, meta.Name, meta.Namespace, diff) |
83 | | - meta.Annotations[CertificateNotAfterAnnotation] = a.NotAfter |
84 | | - modified = true |
85 | | - } |
86 | | - if len(a.RefreshPeriod) > 0 && meta.Annotations[CertificateRefreshPeriodAnnotation] != a.RefreshPeriod { |
87 | | - diff := cmp.Diff(meta.Annotations[CertificateRefreshPeriodAnnotation], a.RefreshPeriod) |
88 | | - klog.V(2).Infof("Updating %q annotation for %s/%s, diff: %s", CertificateRefreshPeriodAnnotation, meta.Name, meta.Namespace, diff) |
89 | | - meta.Annotations[CertificateRefreshPeriodAnnotation] = a.RefreshPeriod |
90 | | - modified = true |
91 | | - } |
92 | | - return modified |
93 | | -} |
94 | | - |
95 | | -func NewTLSArtifactObjectMeta(name, namespace string, annotations AdditionalAnnotations) metav1.ObjectMeta { |
96 | | - meta := metav1.ObjectMeta{ |
97 | | - Namespace: namespace, |
98 | | - Name: name, |
99 | | - } |
100 | | - _ = annotations.EnsureTLSMetadataUpdate(&meta) |
101 | | - return meta |
102 | | -} |
| 34 | +// NewTLSArtifactObjectMeta creates a new ObjectMeta with TLS artifact annotations. |
| 35 | +// Deprecated: Use tlsartifact.NewTLSArtifactObjectMeta directly. |
| 36 | +var NewTLSArtifactObjectMeta = tlsartifact.NewTLSArtifactObjectMeta |
0 commit comments