diff --git a/README.md b/README.md
index f4afed8..dc6b35d 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,9 @@ transformation in your kustomize projects.
Table of Contents
- Rationale
- - Usage Example
+ - Usage Example
+
+
- Use of generators
- Keeping or deleting generated resources
- Extensions
@@ -133,12 +135,14 @@ kind: PatchTransformer
metadata:
name: fn-change-repo-and-branch
annotations:
+ # This will remove the internal annotations the transformer adds.
+ config.kaweezle.com/cleanup: "true"
config.kubernetes.io/function: |
exec:
path: krmfnbuiltin
# Can also be:
# container:
- # image: ghcr.io/kaweezle/krmfnbuiltin:v0.4.0
+ # image: ghcr.io/kaweezle/krmfnbuiltin:v0.4.1
patch: |-
- op: replace
path: /spec/source/repoURL
@@ -174,6 +178,40 @@ source:
You now can commit the 10 modified manifests in your branch and deploy the
applications.
+### Internal annotations cleanup
+
+Some kustomize transformers add annotations to enable for instance reference
+reconciliation at the end of the build. These annotations have the prefix
+`internal.config.kubernetes.io`. When performing a `kustomize build`, kustomize
+removes them at the end of the process. When we are using the transformations in
+the context of a KRM function with `kustomize fn run`, the build cleanup is not
+performed. In consequence, the annotations would be added to the resource file
+touched by the transformation. For instance:
+
+```diff
+--- original.argocd.yaml
++++ transformed.argocd.yaml
+@@ -5,6 +5,9 @@
+ namespace: argocd
+ annotations:
+ autocloud/local: "true"
++ internal.config.kubernetes.io/previousKinds: Application
++ internal.config.kubernetes.io/previousNames: argo-cd
++ internal.config.kubernetes.io/previousNamespaces: argocd
+ spec:
+ destination:
+ namespace: argocd
+```
+
+To avoid that, you can insert the following annotation:
+
+```yaml
+config.kaweezle.com/cleanup: "true"
+```
+
+It will inform krmfnbuiltin that you are not using the transformer in the
+context of a bulid and that the internal annotations need to be removed.
+
## Use of generators
`krmfnbuiltin` provides all the Kustomize
@@ -1092,7 +1130,7 @@ curl -sLS https://raw.githubusercontent.com/kaweezle/krmfnbuiltin/main/get.sh |
If you don't want to pipe into shell, you can do:
```console
-> KRMFNBUILTIN_VERSION="v0.4.0"
+> KRMFNBUILTIN_VERSION="v0.4.1"
> curl -sLo /usr/local/bin/krmfnbuiltin https://github.com/kaweezle/krmfnbuiltin/releases/download/${KRMFNBUILTIN_VERSION}/krmfnbuiltin_${KRMFNBUILTIN_VERSION}_linux_amd64
```
@@ -1121,7 +1159,7 @@ summarize:
```Dockerfile
FROM argoproj/argocd:latest
-ARG KRMFNBUILTIN_VERSION=v0.4.0
+ARG KRMFNBUILTIN_VERSION=v0.4.1
# Switch to root for the ability to perform install
USER root
diff --git a/main.go b/main.go
index 409e01f..f825fc9 100644
--- a/main.go
+++ b/main.go
@@ -62,15 +62,19 @@ func main() {
return errors.WrapPrefixf(err, "Transforming resources")
}
- for _, r := range rm.Resources() {
- utils.RemoveBuildAnnotations(r)
+ configAnnotations := config.GetAnnotations()
+
+ if _, ok := configAnnotations[utils.FunctionAnnotationCleanup]; ok {
+ for _, r := range rm.Resources() {
+ utils.RemoveBuildAnnotations(r)
+ }
}
rl.Items = rm.ToRNodeSlice()
// If the annotation `config.kaweezle.com/prune-local` is present in a
// transformer makes all the local resources disappear.
- if _, ok := config.GetAnnotations()[utils.FunctionAnnotationPruneLocal]; ok {
+ if _, ok := configAnnotations[utils.FunctionAnnotationPruneLocal]; ok {
err = rl.Filter(utils.UnLocal)
if err != nil {
return errors.WrapPrefixf(err, "while pruning `config.kaweezle.com/local-config` resources")
@@ -110,7 +114,7 @@ func main() {
cmd := command.Build(processor, command.StandaloneDisabled, false)
command.AddGenerateDockerfile(cmd)
- cmd.Version = "v0.4.0" // <---VERSION--->
+ cmd.Version = "v0.4.1" // <---VERSION--->
if err := cmd.Execute(); err != nil {
os.Exit(1)
diff --git a/pkg/utils/constants.go b/pkg/utils/constants.go
index 7f006f9..1f380f2 100644
--- a/pkg/utils/constants.go
+++ b/pkg/utils/constants.go
@@ -29,6 +29,9 @@ const (
// local configuration resource (local-config)
FunctionAnnotationInjectLocal = LocalConfigurationAnnotationDomain + "/inject-local"
+ // if set, Remove any transformation leftover annotations
+ FunctionAnnotationCleanup = LocalConfigurationAnnotationDomain + "/cleanup"
+
// if set, the transformation will remove all the resources marked as local-config
FunctionAnnotationPruneLocal = LocalConfigurationAnnotationDomain + "/prune-local"
// Saving path for injected resource
diff --git a/tests/patch/functions/patch-transformer.yaml b/tests/patch/functions/patch-transformer.yaml
index 9c656f0..cf9e343 100644
--- a/tests/patch/functions/patch-transformer.yaml
+++ b/tests/patch/functions/patch-transformer.yaml
@@ -3,6 +3,7 @@ kind: PatchTransformer
metadata:
name: not-important-to-example
annotations:
+ config.kaweezle.com/cleanup: "true"
config.kubernetes.io/function: |
exec:
path: ../../krmfnbuiltin