Request reconcile using patch instead of update
This should prevent the generation of the object getting bumped, as observed on a GKE K8s 1.18 cluster using the logic before this commit. We only want to generation to increase when there are actual changes to the `spec` of a resource, as some controllers use the `generation` value to make assumptions about what they should do during a reconciliation. Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
@@ -37,6 +37,10 @@ func (a alertAdapter) asClientObject() client.Object {
|
|||||||
return a.Alert
|
return a.Alert
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a alertAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.Alert.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// notificationv1.Alert
|
// notificationv1.Alert
|
||||||
|
|
||||||
type alertListAdapter struct {
|
type alertListAdapter struct {
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ func (a alertProviderAdapter) asClientObject() client.Object {
|
|||||||
return a.Provider
|
return a.Provider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a alertProviderAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.Provider.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// notificationv1.Provider
|
// notificationv1.Provider
|
||||||
|
|
||||||
type alertProviderListAdapter struct {
|
type alertProviderListAdapter struct {
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ func (h helmReleaseAdapter) asClientObject() client.Object {
|
|||||||
return h.HelmRelease
|
return h.HelmRelease
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h helmReleaseAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return h.HelmRelease.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// helmv2.HelmReleaseList
|
// helmv2.HelmReleaseList
|
||||||
|
|
||||||
type helmReleaseListAdapter struct {
|
type helmReleaseListAdapter struct {
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ func (a imageRepositoryAdapter) asClientObject() client.Object {
|
|||||||
return a.ImageRepository
|
return a.ImageRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a imageRepositoryAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.ImageRepository.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// imagev1.ImageRepositoryList
|
// imagev1.ImageRepositoryList
|
||||||
|
|
||||||
type imageRepositoryListAdapter struct {
|
type imageRepositoryListAdapter struct {
|
||||||
@@ -100,6 +104,10 @@ func (a imageUpdateAutomationAdapter) asClientObject() client.Object {
|
|||||||
return a.ImageUpdateAutomation
|
return a.ImageUpdateAutomation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a imageUpdateAutomationAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.ImageUpdateAutomation.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// autov1.ImageUpdateAutomationList
|
// autov1.ImageUpdateAutomationList
|
||||||
|
|
||||||
type imageUpdateAutomationListAdapter struct {
|
type imageUpdateAutomationListAdapter struct {
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ func (a kustomizationAdapter) asClientObject() client.Object {
|
|||||||
return a.Kustomization
|
return a.Kustomization
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a kustomizationAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.Kustomization.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// kustomizev1.KustomizationList
|
// kustomizev1.KustomizationList
|
||||||
|
|
||||||
type kustomizationListAdapter struct {
|
type kustomizationListAdapter struct {
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ type adapter interface {
|
|||||||
asClientObject() client.Object
|
asClientObject() client.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copyable is an interface for a wrapper or alias from which we can
|
||||||
|
// get a deep copied client.Object, required when you e.g. want to
|
||||||
|
// calculate a patch.
|
||||||
|
type copyable interface {
|
||||||
|
deepCopyClientObject() client.Object
|
||||||
|
}
|
||||||
|
|
||||||
// listAdapater is the analogue to adapter, but for lists; the
|
// listAdapater is the analogue to adapter, but for lists; the
|
||||||
// controller runtime distinguishes between methods dealing with
|
// controller runtime distinguishes between methods dealing with
|
||||||
// objects and lists.
|
// objects and lists.
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ func (a receiverAdapter) asClientObject() client.Object {
|
|||||||
return a.Receiver
|
return a.Receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a receiverAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.Receiver.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// notificationv1.Receiver
|
// notificationv1.Receiver
|
||||||
|
|
||||||
type receiverListAdapter struct {
|
type receiverListAdapter struct {
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ type reconcileCommand struct {
|
|||||||
|
|
||||||
type reconcilable interface {
|
type reconcilable interface {
|
||||||
adapter // to be able to load from the cluster
|
adapter // to be able to load from the cluster
|
||||||
|
copyable // to be able to calculate patches
|
||||||
suspendable // to tell if it's suspended
|
suspendable // to tell if it's suspended
|
||||||
|
|
||||||
// these are implemented by anything embedding metav1.ObjectMeta
|
// these are implemented by anything embedding metav1.ObjectMeta
|
||||||
@@ -142,6 +143,7 @@ func requestReconciliation(ctx context.Context, kubeClient client.Client,
|
|||||||
if err := kubeClient.Get(ctx, namespacedName, obj.asClientObject()); err != nil {
|
if err := kubeClient.Get(ctx, namespacedName, obj.asClientObject()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
patch := client.MergeFrom(obj.deepCopyClientObject())
|
||||||
if ann := obj.GetAnnotations(); ann == nil {
|
if ann := obj.GetAnnotations(); ann == nil {
|
||||||
obj.SetAnnotations(map[string]string{
|
obj.SetAnnotations(map[string]string{
|
||||||
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
|
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
|
||||||
@@ -150,7 +152,7 @@ func requestReconciliation(ctx context.Context, kubeClient client.Client,
|
|||||||
ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano)
|
ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano)
|
||||||
obj.SetAnnotations(ann)
|
obj.SetAnnotations(ann)
|
||||||
}
|
}
|
||||||
return kubeClient.Update(ctx, obj.asClientObject())
|
return kubeClient.Patch(ctx, obj.asClientObject(), patch)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ func (a bucketAdapter) asClientObject() client.Object {
|
|||||||
return a.Bucket
|
return a.Bucket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a bucketAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.Bucket.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// sourcev1.BucketList
|
// sourcev1.BucketList
|
||||||
|
|
||||||
type bucketListAdapter struct {
|
type bucketListAdapter struct {
|
||||||
@@ -70,6 +74,10 @@ func (a helmChartAdapter) asClientObject() client.Object {
|
|||||||
return a.HelmChart
|
return a.HelmChart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a helmChartAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.HelmChart.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// sourcev1.HelmChartList
|
// sourcev1.HelmChartList
|
||||||
|
|
||||||
type helmChartListAdapter struct {
|
type helmChartListAdapter struct {
|
||||||
@@ -99,6 +107,10 @@ func (a gitRepositoryAdapter) asClientObject() client.Object {
|
|||||||
return a.GitRepository
|
return a.GitRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a gitRepositoryAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.GitRepository.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// sourcev1.GitRepositoryList
|
// sourcev1.GitRepositoryList
|
||||||
|
|
||||||
type gitRepositoryListAdapter struct {
|
type gitRepositoryListAdapter struct {
|
||||||
@@ -128,6 +140,10 @@ func (a helmRepositoryAdapter) asClientObject() client.Object {
|
|||||||
return a.HelmRepository
|
return a.HelmRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a helmRepositoryAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.HelmRepository.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
// sourcev1.HelmRepositoryList
|
// sourcev1.HelmRepositoryList
|
||||||
|
|
||||||
type helmRepositoryListAdapter struct {
|
type helmRepositoryListAdapter struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user