Description
Bug Report
What did you do?
- Create a
StatefulSet
in kubernetes which contains more than one container in thespec.template.spec.containers
- During reconciliation, remove a container so that the desired
StatefulSet
no longer has it and there are no other changes
What did you expect to see?
The removal of the container from the StatefulSets
spec.template.spec.containers
is detected as a mismatch and the changes are applied to kubernetes.
What did you see instead? Under which circumstances?
When the GenericKubernetesResourceMatcher.match(R desired, R actualResource, boolean considerMetadata)
method is called, it does a resource comparison from desired to actual. It then looks at the operations and if there are any non-add operations, it considers the actual and desired not matching. If there are only add
operations (which would be the case since something is being removed from the desired), it would still consider them matching. As a result, it returns the last line return Result.computed(true, desired);
so the operator thinks that actual and desired match and does not update kuberenetes.
Environment
Kubernetes cluster type:
docker-desktop and GKE
$ Mention java-operator-sdk version from pom.xml file
io.javaoperatorsdk:operator-framework-junit-5:4.1.0
$ java -version
openjdk version "18" 2022-03-22
OpenJDK Runtime Environment (build 18+36-2087)
OpenJDK 64-Bit Server VM (build 18+36-2087, mixed mode, sharing)
$ kubectl version
Client Version: v1.26.1
Kustomize Version: v4.5.7
Server Version: v1.24.1
Possible Solution
- There needs to be a better way to detect when things have changed while ignoring fields that are added by the cluster. Perhaps the operator SDK could add a hash value as a label that is compared instead.
OR
- There could be a list of fields to ignore during comparison provided to the match method