Skip to content

Commit 8276d57

Browse files
committed
modify reconciler to use new Delta() compare
Updates the ACK runtime and type system to use the new `pkg/compare.Delta` comparison functionality. The `AWSResourceDescriptor.Diff()` and `AWSResourceDescriptor.Equal()` methods were removed and replaced with a single `AWSResourceDescriptor.Delta()` method that returns a `*pkg/compare.Delta` struct containing the difference between two objects under comparison. A corresponding patch to the github.com/aws-controllers-k8s/code-generator repository adds the generation of the `newResourceDelta()` resource package-local function that recurses into an object and compares the fields in the objects to each other. Included in this patch is an update to the `mocks` Makefile target which now builds mocks for `k8s.io/apimachinery` interfaces that we use in a new unit test of the update code path in the reconciler. In order to adhere to best practices of only using exported functions in Go module testing, I ended up exporting the `pkg/runtime.reconciler.sync()` method as a `Sync()` method on the `AWSResourceReconciler` interface. The unit test features a whole lot of mock setups and definitely could use some refactoring to reduce the number of setup mocks needed. IMPORTANT! This is a BREAKING change to the runtime interfaces. Once merged, we will need to cut a new Git release to signal to consumers that this is a backwards-incompatible change and if they attempt to regenerate their controllers with the new code and their controllers rely on the older interfaces that uses a "diffReporter" struct, they will generate broken code.
1 parent 091c1fd commit 8276d57

16 files changed

+825
-68
lines changed

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
SHELL := /bin/bash # Use bash syntax
22

3-
# Set up variables
3+
GOPATH ?= "$(HOME)/go"
44
GO111MODULE=on
5+
K8S_APIMACHINERY_VERSION = $(shell go list -m -f '{{ .Version }}' k8s.io/apimachinery)
6+
K8S_APIMACHINERY_DIR = "$(GOPATH)/pkg/mod/k8s.io/apimachinery@$(K8S_APIMACHINERY_VERSION)"
57

68
.PHONY: all test clean-mocks mocks
79

@@ -20,6 +22,15 @@ mocks: install-mockery ## Build mocks
2022
@echo -n "building mocks for pkg/types ... "
2123
@bin/mockery --quiet --all --tags=codegen --case=underscore --output=mocks/pkg/types --dir=pkg/types
2224
@echo "ok."
25+
@echo -n "building mocks for k8s.io/apimachinery/pkg/apis/meta/v1 ... "
26+
@bin/mockery --quiet --name=Object --case=underscore --output=mocks/apimachinery/pkg/apis/meta/v1 --dir="$(K8S_APIMACHINERY_DIR)/pkg/apis/meta/v1"
27+
@echo "ok."
28+
@echo -n "building mocks for k8s.io/apimachinery/runtime ... "
29+
@bin/mockery --quiet --name=Object --case=underscore --output=mocks/apimachinery/pkg/runtime --dir="$(K8S_APIMACHINERY_DIR)/pkg/runtime"
30+
@echo "ok."
31+
@echo -n "building mocks for k8s.io/apimachinery/runtime/schema ... "
32+
@bin/mockery --quiet --name=ObjectKind --case=underscore --output=mocks/apimachinery/pkg/runtime/schema --dir="$(K8S_APIMACHINERY_DIR)/pkg/runtime/schema"
33+
@echo "ok."
2334

2435
help: ## Show this help.
2536
@grep -F -h "##" $(MAKEFILE_LIST) | grep -F -v grep | sed -e 's/\\$$//' \

mocks/apimachinery/pkg/apis/meta/v1/object.go

Lines changed: 333 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)