From 0dae200cb51be268652fecb6758d2ef3c94b79f2 Mon Sep 17 00:00:00 2001 From: Jashandeep Sohi Date: Mon, 16 Dec 2024 11:34:46 -0800 Subject: [PATCH] k8s: update base svc pkg to avoid merge bug downstream --- k8s/base/svc-frontend/Kptfile | 4 +-- k8s/base/svc-frontend/README.md | 4 +-- k8s/base/svc-frontend/fn-replacements.yaml | 24 +++--------------- k8s/base/svc-frontend/kustomization.yaml | 14 ++++------- .../remove-kpt-internal-annotations/Kptfile | 20 +++++++++++++++ .../remove-kpt-internal-annotations/README.md | 25 +++++++++++++++++++ .../kustomization.yaml | 13 ++++++++++ k8s/base/svc-frontend/svc.yaml | 6 ++--- 8 files changed, 73 insertions(+), 37 deletions(-) create mode 100644 k8s/base/svc-frontend/remove-kpt-internal-annotations/Kptfile create mode 100644 k8s/base/svc-frontend/remove-kpt-internal-annotations/README.md create mode 100644 k8s/base/svc-frontend/remove-kpt-internal-annotations/kustomization.yaml diff --git a/k8s/base/svc-frontend/Kptfile b/k8s/base/svc-frontend/Kptfile index 0e938f3..8952986 100644 --- a/k8s/base/svc-frontend/Kptfile +++ b/k8s/base/svc-frontend/Kptfile @@ -10,14 +10,14 @@ upstream: repo: https://github.com/LCOGT/kpt-pkg-catalog directory: /service ref: main - updateStrategy: resource-merge + updateStrategy: force-delete-replace upstreamLock: type: git git: repo: https://github.com/LCOGT/kpt-pkg-catalog directory: /service ref: main - commit: ddad41bfb8f928aa4367d86e7da6677200fe4f26 + commit: c58213d7a52130c977fdff0a51f4bd4fb5ca73a3 pipeline: mutators: - image: gcr.io/kpt-fn/apply-replacements:v0.1.1 diff --git a/k8s/base/svc-frontend/README.md b/k8s/base/svc-frontend/README.md index bfc4bab..8251832 100644 --- a/k8s/base/svc-frontend/README.md +++ b/k8s/base/svc-frontend/README.md @@ -2,8 +2,8 @@ ## Description -This package provides a bare-bones `v1.Service` that you can build upon -and use in other packages. +This package provides a bare-bones [`v1.Service`](https://kubernetes.io/docs/concepts/services-networking/service/) +that you can build upon and use in other packages. ## Usage diff --git a/k8s/base/svc-frontend/fn-replacements.yaml b/k8s/base/svc-frontend/fn-replacements.yaml index c5af4d0..48e31f3 100644 --- a/k8s/base/svc-frontend/fn-replacements.yaml +++ b/k8s/base/svc-frontend/fn-replacements.yaml @@ -1,29 +1,11 @@ apiVersion: fn.kpt.dev/v1alpha1 kind: ApplyReplacements -metadata: # kpt-merge: /svc-example - name: svc-frontend +metadata: # kpt-merge: /svc + name: svc annotations: config.kubernetes.io/local-config: "true" - internal.kpt.dev/upstream-identifier: 'fn.kpt.dev|ApplyReplacements|default|svc-example' + internal.kpt.dev/upstream-identifier: 'fn.kpt.dev|ApplyReplacements|default|svc' replacements: - - source: - kind: Service - fieldPath: metadata.name - targets: - - select: - kind: Kustomization - fieldPaths: - - metadata.name - options: - delimiter: "svc-" - index: 1 - - select: - kind: ApplyReplacements - fieldPaths: - - metadata.name - options: - delimiter: "svc-" - index: 1 - source: kind: Service fieldPath: spec.selector.[app.kubernetes.io/component] diff --git a/k8s/base/svc-frontend/kustomization.yaml b/k8s/base/svc-frontend/kustomization.yaml index f0fbcb6..8cc3245 100644 --- a/k8s/base/svc-frontend/kustomization.yaml +++ b/k8s/base/svc-frontend/kustomization.yaml @@ -1,15 +1,11 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization -metadata: # kpt-merge: /svc-example - name: svc-frontend +metadata: # kpt-merge: /svc + name: svc annotations: config.kubernetes.io/local-config: "true" - internal.kpt.dev/upstream-identifier: 'kustomize.config.k8s.io|Kustomization|default|svc-example' + internal.kpt.dev/upstream-identifier: 'kustomize.config.k8s.io|Kustomization|default|svc' resources: - ./svc.yaml -patches: - - target: - annotationSelector: internal.kpt.dev/upstream-identifier - patch: |- - - op: remove - path: /metadata/annotations/internal.kpt.dev~1upstream-identifier +components: + - ./remove-kpt-internal-annotations/ diff --git a/k8s/base/svc-frontend/remove-kpt-internal-annotations/Kptfile b/k8s/base/svc-frontend/remove-kpt-internal-annotations/Kptfile new file mode 100644 index 0000000..3876daa --- /dev/null +++ b/k8s/base/svc-frontend/remove-kpt-internal-annotations/Kptfile @@ -0,0 +1,20 @@ +apiVersion: kpt.dev/v1 +kind: Kptfile +metadata: + name: remove-kpt-internal-annotations + annotations: + config.kubernetes.io/local-config: "true" +upstream: + type: git + git: + repo: https://github.com/LCOGT/kpt-pkg-catalog + directory: /remove-kpt-internal-annotations + ref: main + updateStrategy: resource-merge +upstreamLock: + type: git + git: + repo: https://github.com/LCOGT/kpt-pkg-catalog + directory: /remove-kpt-internal-annotations + ref: main + commit: c58213d7a52130c977fdff0a51f4bd4fb5ca73a3 diff --git a/k8s/base/svc-frontend/remove-kpt-internal-annotations/README.md b/k8s/base/svc-frontend/remove-kpt-internal-annotations/README.md new file mode 100644 index 0000000..4ffea9f --- /dev/null +++ b/k8s/base/svc-frontend/remove-kpt-internal-annotations/README.md @@ -0,0 +1,25 @@ +# remove-kpt-internal-annotations + +## Description + +This package provides a [Kustomize `Component`](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/1802-kustomize-components) +that can be used to remove `internal.kpt.dev/upstream-identifier` annotations from all rendered KRM objects. + +## Usage + +Clone this package: + +```shell +kpt pkg get https://github.com/LCOGT/kpt-pkg-catalog/remove-kpt-internal-annotations +``` + +And then reference it from another Kustomization: + + +```yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +components: + - ./remove-kpt-internal-annotations/ +``` diff --git a/k8s/base/svc-frontend/remove-kpt-internal-annotations/kustomization.yaml b/k8s/base/svc-frontend/remove-kpt-internal-annotations/kustomization.yaml new file mode 100644 index 0000000..f11ff1a --- /dev/null +++ b/k8s/base/svc-frontend/remove-kpt-internal-annotations/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component +metadata: # kpt-merge: /remove-kpt-internal-annotations + name: remove-kpt-internal-annotations + annotations: + config.kubernetes.io/local-config: "true" + internal.kpt.dev/upstream-identifier: 'kustomize.config.k8s.io|Component|default|remove-kpt-internal-annotations' +patches: + - target: + annotationSelector: internal.kpt.dev/upstream-identifier + patch: |- + - op: remove + path: /metadata/annotations/internal.kpt.dev~1upstream-identifier diff --git a/k8s/base/svc-frontend/svc.yaml b/k8s/base/svc-frontend/svc.yaml index ce6df34..b65deea 100644 --- a/k8s/base/svc-frontend/svc.yaml +++ b/k8s/base/svc-frontend/svc.yaml @@ -3,10 +3,10 @@ apiVersion: v1 kind: Service metadata: # kpt-merge: /example name: frontend - annotations: - internal.kpt.dev/upstream-identifier: '|Service|default|frontend' labels: app.kubernetes.io/component: frontend + annotations: + internal.kpt.dev/upstream-identifier: '|Service|default|example' spec: type: ClusterIP selector: @@ -14,4 +14,4 @@ spec: ports: - name: frontend port: 8080 - targetPort: frontend + targetPort: "frontend"