Skip to content

Commit 7e4aeaf

Browse files
committed
feat: Create applylib for use by instance reconciler
* Applylib is inspired from: * kubectl pkg/cmd/apply/applyset.go * kubebuilder-declarative-pattern/applylib * Creating a simpler, self-contained version of the library that is purpose built for controllers. * Handle pruning and uses server-side apply * RGD controller changes * fix linter warnings for func defn lines being too long * Inject restMapper to be passed to instance controllers * Instance controller changes * When patching instance status, use retry-on-conflict loop * Since we apply all resolved resources, Join() errors across resources (apply/update errors) * Add changes to get restMapper and pass it on to applylib * Instance reconciler changes * Refactor reconcileInstance to use Applylib * Makefile * Add target to setup/install envtest * Setup envtest, kubebuilder assets for running e2e tests locally * Remove pkg/controller/instance/delta since we dont compute delta locally. We defer it to the server. * With SSA, we need to be careful about setting field manager * different reconciler paths use different managers * Introduce source-rgd labels to differenciate b/w parent rgd that creates an instance and the source rgd that defines the instance CRD * This is useful when we have an RGD creating and instance of another RG. Today we have a bug where the parent and the child reconcilers overwrite the labels. * (next steps) lifecycle support in applylib * redo externalRef as lifecycle hints * decorate lifecycle hint (create or update, no delete) ----------------------- Addressing review comments: * Move applyset/applylib -> pkg/applylib * Add more docs * Add a reference to the applyset KEP in comments * Add docs.go and interface docs * Improvements: * remove caching a json marshalled copy of obj * Remove name/namespace in PruneObject and instead derive it from object. Also change object type from runtime.Object to unstructured. * use fieldmanager config param to remove kro hardcoding in applyset * Aggregate pruneErrors and applyErrors into single Errors() * add recordPruneObject helper * switched from waitGroup to errgroup when collecting objects to prune across namespaces * take logr as a config in ApplySet. Added more logging in applyset. * use superset of namespaces and GKs we compute before apply for pruning * Add simple tests in the applyset pkg * use namespace-scoped resource interface when pruning * use force=True when applying in setManaged() * Removed un-necessary deepcopy in updateParentLabelsAndAnnotations * Add Unit tests to verify pruning and apply logic * Fix bugs in pruning logic that missed old namespaces and GKs * Remove callbacks and make code more procedural * Make pruning sequential by default * Refactors: * add RestMapper to the client-set * use Unstrucutred in ApplyableObject instead of interface and forcing it to be unstructured in code * minor restruction in processLoad() method * Refactor code that was using errors.Join and an array * Use ContainsFinalizer * Converting unstructured to PartialObjectMetadata for parent in applyset. * Cleanups: * Fix typos in comments, prints etc * Remove obseleted comments * Make the exported resources strutter less, applyset.ApplySet -> applyset.Set, NewApplySet -> New etc. * Fix captilaization for var names. Uid -> UID, ... * use consts for labelManager strings * remove pure formatting changes in unrelated files to minimize PR changeset Split out: * Remove pkg/metadata/finalizer.go changes and create a separate PR kubernetes-sigs#625 * move envtest makefile changes to kubernetes-sigs#636 * removing labeller changes and moving them to kubernetes-sigs#631 * Fix regression when removing labeller changes: `dynamic-controller Error syncing item, requeuing with rate limit {"item": {"NamespacedKey":"chainsaw-special-quail/test-instance","GVR":{"Group":"kro.run","Version":"v1alpha1","Resource":"checkinstancecreationsimpledeployments"}}, "error": "failed to setup instance: failed to set finalizer: error getting finalizers: .metadata.finalizers accessor error: [] is of the type []string, expected []interface{}"}`
1 parent ea3db3a commit 7e4aeaf

File tree

27 files changed

+2319
-2300
lines changed

27 files changed

+2319
-2300
lines changed

ATTRIBUTION.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ License version 2.0, we include the full text of the package's License below.
3232
* `github.com/stretchr/testify`
3333
* `go.uber.org/zap`
3434
* `golang.org/x/exp`
35+
* `golang.org/x/sync`
3536
* `golang.org/x/time`
3637
* `google.golang.org/genproto/googleapis/api`
3738
* `k8s.io/api`
@@ -1453,6 +1454,38 @@ THE SOFTWARE.
14531454

14541455

14551456

1457+
### golang.org/x/sync
1458+
1459+
License Identifier: BSD-3-Clause
1460+
1461+
Copyright 2009 The Go Authors.
1462+
1463+
Redistribution and use in source and binary forms, with or without
1464+
modification, are permitted provided that the following conditions are
1465+
met:
1466+
1467+
* Redistributions of source code must retain the above copyright
1468+
notice, this list of conditions and the following disclaimer.
1469+
* Redistributions in binary form must reproduce the above
1470+
copyright notice, this list of conditions and the following disclaimer
1471+
in the documentation and/or other materials provided with the
1472+
distribution.
1473+
* Neither the name of Google LLC nor the names of its
1474+
contributors may be used to endorse or promote products derived from
1475+
this software without specific prior written permission.
1476+
1477+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1478+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1479+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1480+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1481+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1482+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1483+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1484+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1485+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1486+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1487+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1488+
14561489
### golang.org/x/time
14571490

14581491
License Identifier: BSD-3-Clause
@@ -4027,4 +4060,56 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40274060
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40284061
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40294062

4063+
### sigs.k8s.io/yaml
4064+
4065+
License Identifier: Apache-2.0
4066+
4067+
Subdependencies:
4068+
* `github.com/google/go-cmp`
4069+
* `go.yaml.in/yaml/v2`
4070+
* `go.yaml.in/yaml/v3`
4071+
* `sigs.k8s.io/randfill`
4072+
4073+
#### github.com/google/go-cmp
4074+
4075+
License Identifier: BSD-3-Clause
4076+
4077+
Copyright (c) 2017 The Go Authors. All rights reserved.
4078+
4079+
Redistribution and use in source and binary forms, with or without
4080+
modification, are permitted provided that the following conditions are
4081+
met:
4082+
4083+
* Redistributions of source code must retain the above copyright
4084+
notice, this list of conditions and the following disclaimer.
4085+
* Redistributions in binary form must reproduce the above
4086+
copyright notice, this list of conditions and the following disclaimer
4087+
in the documentation and/or other materials provided with the
4088+
distribution.
4089+
* Neither the name of Google Inc. nor the names of its
4090+
contributors may be used to endorse or promote products derived from
4091+
this software without specific prior written permission.
4092+
4093+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4094+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4095+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4096+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4097+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4098+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4099+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4100+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4101+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4102+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4103+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4104+
4105+
#### go.yaml.in/yaml/v2
4106+
4107+
License Identifier: Apache-2.0
4108+
4109+
#### go.yaml.in/yaml/v3
40304110

4111+
License Identifier: Apache-2.0
4112+
4113+
#### sigs.k8s.io/randfill
4114+
4115+
License Identifier: Apache-2.0

0 commit comments

Comments
 (0)