Skip to content

Commit 56ef18c

Browse files
authored
Add missing annotations (#1289)
Fix perpetual diffs introduced in PR #1253
1 parent 45568d1 commit 56ef18c

File tree

2 files changed

+109
-78
lines changed

2 files changed

+109
-78
lines changed
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package kubernetes
2+
3+
import (
4+
apps "k8s.io/api/apps/v1beta1"
5+
cert "k8s.io/api/certificates/v1beta1"
6+
api "k8s.io/api/core/v1"
7+
discovery "k8s.io/api/discovery/v1beta1"
8+
networking "k8s.io/api/networking/v1beta1"
9+
rbac "k8s.io/api/rbac/v1beta1"
10+
)
11+
12+
// knownLabelAnnotations is a map of known internal labels and
13+
// annotations that we want to strip out to avoid unneccessary diffs.
14+
// See: https://kubernetes.io/docs/reference/labels-annotations-taints
15+
var knownLabelsAnnotations = map[string]string{
16+
// core
17+
api.LabelHostname: "",
18+
api.LabelZoneFailureDomain: "",
19+
api.LabelZoneRegion: "",
20+
api.LabelZoneFailureDomainStable: "",
21+
api.LabelZoneRegionStable: "",
22+
api.LabelInstanceType: "",
23+
api.LabelInstanceTypeStable: "",
24+
api.LabelOSStable: "",
25+
api.LabelArchStable: "",
26+
api.LabelWindowsBuild: "",
27+
api.LabelNamespaceSuffixKubelet: "",
28+
api.LabelNamespaceSuffixNode: "",
29+
api.LabelNamespaceNodeRestriction: "",
30+
api.IsHeadlessService: "",
31+
api.BetaStorageClassAnnotation: "",
32+
api.MountOptionAnnotation: "",
33+
api.ResourceDefaultNamespacePrefix: "",
34+
api.ServiceAccountNameKey: "",
35+
api.ServiceAccountUIDKey: "",
36+
api.PodPresetOptOutAnnotationKey: "",
37+
api.MirrorPodAnnotationKey: "",
38+
api.TolerationsAnnotationKey: "",
39+
api.TaintsAnnotationKey: "",
40+
api.SeccompPodAnnotationKey: "",
41+
api.SeccompContainerAnnotationKeyPrefix: "",
42+
api.AppArmorBetaContainerAnnotationKeyPrefix: "",
43+
api.AppArmorBetaDefaultProfileAnnotationKey: "",
44+
api.AppArmorBetaAllowedProfilesAnnotationKey: "",
45+
api.PreferAvoidPodsAnnotationKey: "",
46+
api.NonConvertibleAnnotationPrefix: "",
47+
api.AnnotationLoadBalancerSourceRangesKey: "",
48+
api.EndpointsLastChangeTriggerTime: "",
49+
api.MigratedPluginsAnnotationKey: "",
50+
api.TaintNodeNotReady: "",
51+
api.TaintNodeUnreachable: "",
52+
api.TaintNodeUnschedulable: "",
53+
api.TaintNodeMemoryPressure: "",
54+
api.TaintNodeDiskPressure: "",
55+
api.TaintNodeNetworkUnavailable: "",
56+
api.TaintNodePIDPressure: "",
57+
58+
// networking
59+
networking.AnnotationIsDefaultIngressClass: "",
60+
61+
// discovery
62+
discovery.LabelServiceName: "",
63+
discovery.LabelManagedBy: "",
64+
discovery.LabelSkipMirror: "",
65+
66+
// certificates
67+
cert.KubeAPIServerClientSignerName: "",
68+
cert.KubeAPIServerClientKubeletSignerName: "",
69+
cert.KubeletServingSignerName: "",
70+
cert.LegacyUnknownSignerName: "",
71+
72+
// apps
73+
apps.StatefulSetPodNameLabel: "",
74+
75+
// RBAC
76+
rbac.AutoUpdateAnnotationKey: "",
77+
78+
// NOTE the annotations below are baked into the internal
79+
// controller package so we can't import their consts here
80+
81+
// deployment
82+
"deployment.kubernetes.io/revision": "",
83+
"deployment.kubernetes.io/revision-history": "",
84+
"deployment.kubernetes.io/desired-replicas": "",
85+
"deployment.kubernetes.io/max-replicas": "",
86+
87+
// persistentvolume
88+
"pv.kubernetes.io/bind-completed": "",
89+
"pv.kubernetes.io/bound-by-controller": "",
90+
"volume.kubernetes.io/selected-node": "",
91+
"kubernetes.io/no-provisioner": "",
92+
"pv.kubernetes.io/provisioned-by": "",
93+
"pv.kubernetes.io/migrated-to": "",
94+
"volume.beta.kubernetes.io/storage-provisioner": "",
95+
"volume.kubernetes.io/storage-resizer": "",
96+
97+
// GKE ingress
98+
"ingress.kubernetes.io/backends": "",
99+
"ingress.kubernetes.io/https-forwarding-rule": "",
100+
"ingress.kubernetes.io/https-target-proxy": "",
101+
"ingress.kubernetes.io/forwarding-rule": "",
102+
"ingress.kubernetes.io/target-proxy": "",
103+
"ingress.kubernetes.io/ssl-cert": "",
104+
"ingress.kubernetes.io/url-map": "",
105+
106+
"deprecated.daemonset.template.generation": "",
107+
}

kubernetes/structures.go

+2-78
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,12 @@ import (
66
"strings"
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9-
apps "k8s.io/api/apps/v1beta1"
10-
cert "k8s.io/api/certificates/v1beta1"
119
api "k8s.io/api/core/v1"
12-
discovery "k8s.io/api/discovery/v1beta1"
13-
networking "k8s.io/api/networking/v1beta1"
14-
rbac "k8s.io/api/rbac/v1beta1"
1510

1611
"k8s.io/apimachinery/pkg/api/resource"
1712
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1813
)
1914

20-
// https://kubernetes.io/docs/reference/labels-annotations-taints
21-
var builtInLabels = map[string]string{
22-
//Core Api
23-
api.LabelHostname: "",
24-
api.LabelZoneFailureDomain: "",
25-
api.LabelZoneRegion: "",
26-
api.LabelZoneFailureDomainStable: "",
27-
api.LabelZoneRegionStable: "",
28-
api.LabelInstanceType: "",
29-
api.LabelInstanceTypeStable: "",
30-
api.LabelOSStable: "",
31-
api.LabelArchStable: "",
32-
api.LabelWindowsBuild: "",
33-
api.LabelNamespaceSuffixKubelet: "",
34-
api.LabelNamespaceSuffixNode: "",
35-
api.LabelNamespaceNodeRestriction: "",
36-
api.IsHeadlessService: "",
37-
api.BetaStorageClassAnnotation: "",
38-
api.MountOptionAnnotation: "",
39-
api.ResourceDefaultNamespacePrefix: "",
40-
api.ServiceAccountNameKey: "",
41-
api.ServiceAccountUIDKey: "",
42-
api.PodPresetOptOutAnnotationKey: "",
43-
api.MirrorPodAnnotationKey: "",
44-
api.TolerationsAnnotationKey: "",
45-
api.TaintsAnnotationKey: "",
46-
api.SeccompPodAnnotationKey: "",
47-
api.SeccompContainerAnnotationKeyPrefix: "",
48-
api.AppArmorBetaContainerAnnotationKeyPrefix: "",
49-
api.AppArmorBetaDefaultProfileAnnotationKey: "",
50-
api.AppArmorBetaAllowedProfilesAnnotationKey: "",
51-
api.PreferAvoidPodsAnnotationKey: "",
52-
api.NonConvertibleAnnotationPrefix: "",
53-
api.AnnotationLoadBalancerSourceRangesKey: "",
54-
api.EndpointsLastChangeTriggerTime: "",
55-
api.MigratedPluginsAnnotationKey: "",
56-
api.TaintNodeNotReady: "",
57-
api.TaintNodeUnreachable: "",
58-
api.TaintNodeUnschedulable: "",
59-
api.TaintNodeMemoryPressure: "",
60-
api.TaintNodeDiskPressure: "",
61-
api.TaintNodeNetworkUnavailable: "",
62-
api.TaintNodePIDPressure: "",
63-
64-
//Networking
65-
networking.AnnotationIsDefaultIngressClass: "",
66-
67-
//Discovery
68-
discovery.LabelServiceName: "",
69-
discovery.LabelManagedBy: "",
70-
discovery.LabelSkipMirror: "",
71-
72-
//Certificate
73-
cert.KubeAPIServerClientSignerName: "",
74-
cert.KubeAPIServerClientKubeletSignerName: "",
75-
cert.KubeletServingSignerName: "",
76-
cert.LegacyUnknownSignerName: "",
77-
78-
//Apps
79-
apps.StatefulSetPodNameLabel: "",
80-
81-
//RBAC
82-
rbac.AutoUpdateAnnotationKey: "",
83-
}
84-
8515
func idParts(id string) (string, string, error) {
8616
parts := strings.Split(id, "/")
8717
if len(parts) != 2 {
@@ -225,16 +155,10 @@ func isKeyInMap(key string, d map[string]interface{}) bool {
225155
return false
226156
}
227157

228-
func isInternalKey(annotationKey string) bool {
229-
if _, ok := builtInLabels[annotationKey]; ok {
230-
return true
231-
}
232-
233-
// Specific to DaemonSet annotations, generated & controlled by the server.
234-
if strings.Contains(annotationKey, "deprecated.daemonset.template.generation") {
158+
func isInternalKey(key string) bool {
159+
if _, ok := knownLabelsAnnotations[key]; ok {
235160
return true
236161
}
237-
238162
return false
239163
}
240164

0 commit comments

Comments
 (0)