Skip to content

Commit ce90982

Browse files
authored
Revert "Filter well known labels and annotations (#1253)" (#1298)
* Revert "Filter well known labels and annotations (#1253)" This reverts commit e5b56a9. * Allow app.kubernetes.io to be user specified
1 parent bf46291 commit ce90982

39 files changed

+95
-241
lines changed

kubernetes/known_labels_annotations.go

Lines changed: 0 additions & 109 deletions
This file was deleted.

kubernetes/resource_kubernetes_pod_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,34 +1183,6 @@ func TestAccKubernetesPod_topologySpreadConstraint(t *testing.T) {
11831183
})
11841184
}
11851185

1186-
func TestAccKubernetesPod_filterAnnotations(t *testing.T) {
1187-
name := acctest.RandomWithPrefix("tf-acc-test")
1188-
resourceName := "kubernetes_pod.test"
1189-
1190-
resource.Test(t, resource.TestCase{
1191-
PreCheck: func() { testAccPreCheck(t) },
1192-
ProviderFactories: testAccProviderFactories,
1193-
CheckDestroy: testAccCheckKubernetesPodDestroy,
1194-
Steps: []resource.TestStep{
1195-
{
1196-
Config: testAccKubernetesPodConfigFilterAnnotations(name, busyboxImageVersion),
1197-
Check: resource.ComposeAggregateTestCheckFunc(
1198-
resource.TestCheckResourceAttr(resourceName, "metadata.0.annotations.%", "1"),
1199-
resource.TestCheckResourceAttr(resourceName, "metadata.0.annotations.kubernetes.io/ingress.class", "gce-multi-cluster"),
1200-
resource.TestCheckResourceAttr(resourceName, "metadata.0.labels.%", "1"),
1201-
resource.TestCheckResourceAttr(resourceName, "metadata.0.labels.kubernetes.io/ingress.class", "gce-multi-cluster"),
1202-
),
1203-
},
1204-
{
1205-
ResourceName: resourceName,
1206-
ImportState: true,
1207-
ImportStateVerify: true,
1208-
ImportStateVerifyIgnore: []string{"metadata.0.resource_version"},
1209-
},
1210-
},
1211-
})
1212-
}
1213-
12141186
func testAccCheckKubernetesPodDestroy(s *terraform.State) error {
12151187
conn, err := testAccProvider.Meta().(KubeClientsets).MainClientset()
12161188

@@ -2649,26 +2621,3 @@ func testAccKubernetesPodTopologySpreadConstraintConfig(podName, imageName strin
26492621
}
26502622
`, podName, imageName)
26512623
}
2652-
2653-
func testAccKubernetesPodConfigFilterAnnotations(name, imageName string) string {
2654-
return fmt.Sprintf(`resource "kubernetes_pod" "test" {
2655-
metadata {
2656-
name = "%s"
2657-
2658-
labels = {
2659-
"kubernetes.io/ingress.class" = "gce-multi-cluster"
2660-
}
2661-
2662-
annotations = {
2663-
"kubernetes.io/ingress.class" = "gce-multi-cluster"
2664-
}
2665-
}
2666-
spec {
2667-
container {
2668-
image = "%s"
2669-
name = "containername"
2670-
}
2671-
}
2672-
}
2673-
`, name, imageName)
2674-
}

kubernetes/structures.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package kubernetes
33
import (
44
"encoding/base64"
55
"fmt"
6+
"net/url"
67
"strings"
78

89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
api "k8s.io/api/core/v1"
10-
1111
"k8s.io/apimachinery/pkg/api/resource"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
)
@@ -155,8 +155,24 @@ func isKeyInMap(key string, d map[string]interface{}) bool {
155155
return false
156156
}
157157

158-
func isInternalKey(key string) bool {
159-
if _, ok := knownLabelsAnnotations[key]; ok {
158+
func isInternalKey(annotationKey string) bool {
159+
u, err := url.Parse("//" + annotationKey)
160+
if err != nil {
161+
return false
162+
}
163+
164+
// allow user specified application specific keys
165+
if u.Hostname() == "app.kubernetes.io" {
166+
return false
167+
}
168+
169+
// internal *.kubernetes.io keys
170+
if strings.HasSuffix(u.Hostname(), "kubernetes.io") {
171+
return true
172+
}
173+
174+
// Specific to DaemonSet annotations, generated & controlled by the server.
175+
if strings.Contains(annotationKey, "deprecated.daemonset.template.generation") {
160176
return true
161177
}
162178
return false

kubernetes/structures_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ func TestIsInternalKey(t *testing.T) {
1414
{"anyKey", false},
1515
{"any.hostname.io", false},
1616
{"any.hostname.com/with/path", false},
17-
{"any.kubernetes.io", false},
18-
{"kubernetes.io", false},
19-
{"pv.kubernetes.io/any/path", false},
20-
{"pv.kubernetes.io/any/path", false},
21-
{"kubernetes.io/hostname", true},
22-
{"statefulset.kubernetes.io/pod-name", true},
17+
{"app.kubernetes.io", false},
18+
{"kubernetes.io", true},
19+
{"kubectl.kubernetes.io", true},
20+
{"pv.kubernetes.io/any/path", true},
2321
}
24-
for i, tc := range testCases {
25-
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
22+
for _, tc := range testCases {
23+
t.Run(fmt.Sprintf("%s", tc.Key), func(t *testing.T) {
2624
isInternal := isInternalKey(tc.Key)
2725
if tc.Expected && isInternal != tc.Expected {
2826
t.Fatalf("Expected %q to be internal", tc.Key)

website/docs/d/namespace.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ The following arguments are supported:
3838

3939
* `annotations` - (Optional) An unstructured key value map stored with the namespace that may be used to store arbitrary metadata.
4040

41-
~> By default, the provider ignores any annotations whose key names are in the [Well-Known Labels, Annotations and Taints](https://kubernetes.io/docs/reference/labels-annotations-taints). This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/annotations)
41+
~> By default, the provider ignores any annotations whose key names end with *kubernetes.io*. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/annotations)
4242

4343
* `generation` - A sequence number representing a specific generation of the desired state.
4444
* `labels` - (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) namespaces. May match selectors of replication controllers and services.
4545

46-
~> By default, the provider ignores any labels whose key names are in the [Well-Known Labels, Annotations and Taints](https://kubernetes.io/docs/reference/labels-annotations-taints). This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/labels)
46+
~> By default, the provider ignores any labels whose key names end with *kubernetes.io*. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/labels)
4747

4848
* `resource_version` - An opaque value that represents the internal version of this namespace that can be used by clients to determine when namespaces have changed. Read more about [concurrency control and consistency](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency).
4949
* `uid` - The unique in time and space value for this namespace. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/identifiers#uids)

website/docs/r/api_service.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ The following arguments are supported:
4747

4848
* `annotations` - (Optional) An unstructured key value map stored with the API service that may be used to store arbitrary metadata.
4949

50-
~> By default, the provider ignores any annotations whose key names are in the [Well-Known Labels, Annotations and Taints](https://kubernetes.io/docs/reference/labels-annotations-taints). This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/annotations)
50+
~> By default, the provider ignores any annotations whose key names end with *kubernetes.io*. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/annotations)
5151

5252
* `generate_name` - (Optional) Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#idempotency)
5353
* `labels` - (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) the API service.
5454

55-
~> By default, the provider ignores any labels whose key names are in the [Well-Known Labels, Annotations and Taints](https://kubernetes.io/docs/reference/labels-annotations-taints). This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/labels)
55+
~> By default, the provider ignores any labels whose key names end with *kubernetes.io*. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/labels)
5656

5757
* `name` - (Optional) Name of the API service, must be unique. Cannot be updated. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/identifiers#names)
5858

website/docs/r/certificate_signing_request.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ The following arguments are supported:
6464

6565
* `annotations` - (Optional) An unstructured key value map stored with the certificate signing request that may be used to store arbitrary metadata.
6666

67-
~> By default, the provider ignores any annotations whose key names are in the [Well-Known Labels, Annotations and Taints](https://kubernetes.io/docs/reference/labels-annotations-taints). This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/annotations)
67+
~> By default, the provider ignores any annotations whose key names end with *kubernetes.io*. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/annotations)
6868

6969
* `generate_name` - (Optional) Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#idempotency)
7070
* `labels` - (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) the certificate signing request. May match selectors of replication controllers and services.
7171

72-
~> By default, the provider ignores any labels whose key names are in the [Well-Known Labels, Annotations and Taints](https://kubernetes.io/docs/reference/labels-annotations-taints). This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/labels)
72+
~> By default, the provider ignores any labels whose key names end with *kubernetes.io*. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/labels)
7373

7474
* `name` - (Optional) Name of the certificate signing request, must be unique. Cannot be updated. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/identifiers#names)
7575

0 commit comments

Comments
 (0)