Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fluxcd/kustomize-controller
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.13.3
Choose a base ref
...
head repository: fluxcd/kustomize-controller
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.14.0
Choose a head ref
  • 13 commits
  • 30 files changed
  • 3 contributors

Commits on Aug 13, 2021

  1. Tests for replacement transformer

    Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
    somtochiama committed Aug 13, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    renovate-bot Mend Renovate
    Copy the full SHA
    659e660 View commit details
  2. Merge pull request #406 from SomtochiAma/add-kustomize-replacement

    Add kustomize replacement transformer test
    stefanprodan authored Aug 13, 2021
    Copy the full SHA
    ebbf7bc View commit details

Commits on Aug 16, 2021

  1. Add kustomize transformer tests

    Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
    somtochiama committed Aug 16, 2021
    Copy the full SHA
    b1071bf View commit details
  2. Merge pull request #408 from SomtochiAma/add-kustomize-replacement

    Add tests for various kustomize transformers.
    stefanprodan authored Aug 16, 2021
    Copy the full SHA
    34582cb View commit details

Commits on Aug 18, 2021

  1. Skip garbage collection of objects with owner references

    Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
    stefanprodan committed Aug 18, 2021
    Copy the full SHA
    a49bbf9 View commit details

Commits on Aug 19, 2021

  1. Add GC owner reference tests

    Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
    stefanprodan committed Aug 19, 2021
    Copy the full SHA
    16c451b View commit details

Commits on Aug 25, 2021

  1. Improve trimString function

    Previously, the function iterated until the length limit was hit, which
    is relatively slow and increases with the length of the limit. The new
    implementation is easier to reason about and operates in constant time,
    leading to better performance.
    
    Signed-off-by: James Alseth <james@jalseth.me>
    jalseth committed Aug 25, 2021
    Copy the full SHA
    6f32e53 View commit details
  2. Merge pull request #412 from jalseth/main

    Improve trimString function
    stefanprodan authored Aug 25, 2021
    Copy the full SHA
    1032b6b View commit details

Commits on Aug 26, 2021

  1. Merge pull request #411 from fluxcd/skip-gc-for-ownerReference

    Skip garbage collection of objects with owner references
    stefanprodan authored Aug 26, 2021
    Copy the full SHA
    c637838 View commit details
  2. Update controller to kustomize v4.3.0

    Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
    stefanprodan committed Aug 26, 2021
    Copy the full SHA
    80d712e View commit details
  3. Merge pull request #416 from fluxcd/kustomize-v4.3.0

    Update controller to kustomize v4.3.0
    stefanprodan authored Aug 26, 2021
    Copy the full SHA
    96890d3 View commit details
  4. Release v0.14.0

    Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
    stefanprodan committed Aug 26, 2021
    Copy the full SHA
    053f68b View commit details
  5. Merge pull request #417 from fluxcd/release-v0.14.0

    Release v0.14.0
    stefanprodan authored Aug 26, 2021
    Copy the full SHA
    ea052f8 View commit details
Showing with 893 additions and 23 deletions.
  1. +20 −0 CHANGELOG.md
  2. +4 −9 api/v1beta1/kustomization_types.go
  3. +1 −1 config/manager/kustomization.yaml
  4. +158 −1 controllers/kustomization_controller_gc_test.go
  5. +376 −0 controllers/kustomization_controller_transformers_test.go
  6. +25 −2 controllers/kustomization_gc.go
  7. +3 −1 controllers/suite_test.go
  8. +9 −0 controllers/testdata/file-transformer/annotation-transformer.yaml
  9. +7 −0 controllers/testdata/file-transformer/configmap-generator.yaml
  10. +19 −0 controllers/testdata/file-transformer/deployment.yaml
  11. +9 −0 controllers/testdata/file-transformer/imagetag-transformer.yaml
  12. +21 −0 controllers/testdata/file-transformer/kustomization.yaml
  13. +15 −0 controllers/testdata/file-transformer/label-transformer.yaml
  14. +8 −0 controllers/testdata/file-transformer/namespace-transformer.yaml
  15. +5 −0 controllers/testdata/file-transformer/patch-transformer.yaml
  16. +6 −0 controllers/testdata/file-transformer/patch.yaml
  17. +13 −0 controllers/testdata/file-transformer/patchStrategicMerge-transformer.yaml
  18. +10 −0 controllers/testdata/file-transformer/patchjson6902-transformer.yaml
  19. +8 −0 controllers/testdata/file-transformer/prefixsuffix-transformer.yaml
  20. +10 −0 controllers/testdata/file-transformer/quota.yaml
  21. +15 −0 controllers/testdata/file-transformer/replacement-transformer.yaml
  22. +20 −0 controllers/testdata/file-transformer/replicas-transformer.yaml
  23. +7 −0 controllers/testdata/file-transformer/secret-generator.yaml
  24. +19 −0 controllers/testdata/transformers/deployment.yaml
  25. +77 −0 controllers/testdata/transformers/kustomization.yaml
  26. +6 −0 controllers/testdata/transformers/patch.yaml
  27. +10 −0 controllers/testdata/transformers/quota.yaml
  28. +3 −0 docs/spec/v1beta1/kustomization.md
  29. +5 −5 go.mod
  30. +4 −4 go.sum
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,26 @@

All notable changes to this project are documented in this file.

## 0.14.0

**Release date:** 2021-08-26

This prerelease comes with improvements to garbage collection.
When pruning is enabled, the controller will skip the deletion of objects with
[ownerReference.BlockOwnerDeletion=true](https://v1-18.docs.kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#controlling-how-the-garbage-collector-deletes-dependents),
as they are subject to Kubernetes GC.

The controller dependencies has been updated to match
kustomize [v4.3.0](https://github.com/kubernetes-sigs/kustomize/releases/tag/kustomize%2Fv4.3.0).

Improvements:
* Update controller to kustomize v4.3.0
[#416](https://github.com/fluxcd/kustomize-controller/pull/416)
* Skip garbage collection of objects with owner references
[#411](https://github.com/fluxcd/kustomize-controller/pull/411)
* Add tests for various kustomize transformers
[#408](https://github.com/fluxcd/kustomize-controller/pull/408)

## 0.13.3

**Release date:** 2021-08-05
13 changes: 4 additions & 9 deletions api/v1beta1/kustomization_types.go
Original file line number Diff line number Diff line change
@@ -358,14 +358,9 @@ func init() {
}

func trimString(str string, limit int) string {
result := str
chars := 0
for i := range str {
if chars >= limit {
result = str[:i] + "..."
break
}
chars++
if len(str) <= limit {
return str
}
return result

return str[0:limit] + "..."
}
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@ resources:
images:
- name: fluxcd/kustomize-controller
newName: fluxcd/kustomize-controller
newTag: v0.13.3
newTag: v0.14.0
159 changes: 158 additions & 1 deletion controllers/kustomization_controller_gc_test.go
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ var _ = Describe("KustomizationReconciler", func() {
Expect(k8sClient.Delete(context.Background(), namespace)).To(Succeed())
})

It("garbage collects deleted manifests", func() {
It("collects deleted manifests", func() {
configMapManifest := func(name string) string {
return fmt.Sprintf(`---
apiVersion: v1
@@ -176,6 +176,163 @@ data:
Expect(apierrors.IsNotFound(err)).To(BeTrue())
})

It("skips objects with blockOwnerDeletion=true", func() {
configMapManifest := func(name string) string {
return fmt.Sprintf(`---
apiVersion: v1
kind: ConfigMap
metadata:
name: %[1]s
data:
value: %[1]s
`, name)
}
manifest := testserver.File{Name: "configmap.yaml", Body: configMapManifest("first")}
artifact, err := artifactServer.ArtifactFromFiles([]testserver.File{manifest})
Expect(err).ToNot(HaveOccurred())
artifactURL, err := artifactServer.URLForFile(artifact)
Expect(err).ToNot(HaveOccurred())

gitRepo.Status.Artifact.URL = artifactURL
gitRepo.Status.Artifact.Revision = "first"

Expect(k8sClient.Create(context.Background(), gitRepo)).To(Succeed())
Expect(k8sClient.Status().Update(context.Background(), gitRepo)).To(Succeed())
Expect(k8sClient.Create(context.Background(), kustomization)).To(Succeed())

var got kustomizev1.Kustomization
Eventually(func() bool {
_ = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(kustomization), &got)
c := apimeta.FindStatusCondition(got.Status.Conditions, meta.ReadyCondition)
return c != nil && c.Reason == meta.ReconciliationSucceededReason
}, timeout, time.Second).Should(BeTrue())

var configMap corev1.ConfigMap
Expect(k8sClient.Get(context.Background(), client.ObjectKey{Name: "first", Namespace: namespace.Name}, &configMap)).To(Succeed())

owner := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace.Name,
},
}
Expect(k8sClient.Create(context.Background(), owner)).To(Succeed())

sa := &corev1.ServiceAccount{}
objName := types.NamespacedName{Name: "test", Namespace: namespace.Name}
Expect(k8sClient.Get(context.Background(), objName, sa)).To(Succeed())

blockOwnerDeletion := true
owned := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace.Name,
Labels: configMap.GetLabels(),
Annotations: configMap.GetAnnotations(),
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Kind: "ServiceAccount",
Name: sa.Name,
UID: sa.UID,
Controller: &blockOwnerDeletion,
BlockOwnerDeletion: &blockOwnerDeletion,
},
},
},
}
Expect(k8sClient.Create(context.Background(), owned)).To(Succeed())

Expect(k8sClient.Delete(context.Background(), kustomization)).To(Succeed())
Eventually(func() bool {
err = k8sClient.Get(context.Background(), client.ObjectKey{Name: kustomization.Name, Namespace: namespace.Name}, kustomization)
return apierrors.IsNotFound(err)
}, timeout, time.Second).Should(BeTrue())

cf := &corev1.ConfigMap{}
Expect(k8sClient.Get(context.Background(), objName, cf)).To(Succeed())
})

It("deletes objects with blockOwnerDeletion=false", func() {
configMapManifest := func(name string) string {
return fmt.Sprintf(`---
apiVersion: v1
kind: ConfigMap
metadata:
name: %[1]s
data:
value: %[1]s
`, name)
}
manifest := testserver.File{Name: "configmap.yaml", Body: configMapManifest("first")}
artifact, err := artifactServer.ArtifactFromFiles([]testserver.File{manifest})
Expect(err).ToNot(HaveOccurred())
artifactURL, err := artifactServer.URLForFile(artifact)
Expect(err).ToNot(HaveOccurred())

gitRepo.Status.Artifact.URL = artifactURL
gitRepo.Status.Artifact.Revision = "first"

Expect(k8sClient.Create(context.Background(), gitRepo)).To(Succeed())
Expect(k8sClient.Status().Update(context.Background(), gitRepo)).To(Succeed())
Expect(k8sClient.Create(context.Background(), kustomization)).To(Succeed())

var got kustomizev1.Kustomization
Eventually(func() bool {
_ = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(kustomization), &got)
c := apimeta.FindStatusCondition(got.Status.Conditions, meta.ReadyCondition)
return c != nil && c.Reason == meta.ReconciliationSucceededReason
}, timeout, time.Second).Should(BeTrue())

var configMap corev1.ConfigMap
Expect(k8sClient.Get(context.Background(), client.ObjectKey{Name: "first", Namespace: namespace.Name}, &configMap)).To(Succeed())

owner := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace.Name,
},
}
Expect(k8sClient.Create(context.Background(), owner)).To(Succeed())

sa := &corev1.ServiceAccount{}
objName := types.NamespacedName{Name: "test", Namespace: namespace.Name}
Expect(k8sClient.Get(context.Background(), objName, sa)).To(Succeed())

blockOwnerDeletion := false
owned := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace.Name,
Labels: configMap.GetLabels(),
Annotations: configMap.GetAnnotations(),
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Kind: "ServiceAccount",
Name: sa.Name,
UID: sa.UID,
Controller: &blockOwnerDeletion,
BlockOwnerDeletion: &blockOwnerDeletion,
},
},
},
}
Expect(k8sClient.Create(context.Background(), owned)).To(Succeed())

Expect(k8sClient.Delete(context.Background(), kustomization)).To(Succeed())
Eventually(func() bool {
err = k8sClient.Get(context.Background(), client.ObjectKey{Name: kustomization.Name, Namespace: namespace.Name}, kustomization)
return apierrors.IsNotFound(err)
}, timeout, time.Second).Should(BeTrue())

cf := &corev1.ConfigMap{}
err = k8sClient.Get(context.Background(), objName, cf)
Expect(apierrors.IsNotFound(err)).To(BeTrue())
})

It("skips deleted manifests labeled with prune disabled", func() {
configMapManifest := func(name string, skip string) string {
return fmt.Sprintf(`---
Loading