Skip to content

Commit

Permalink
Merge pull request #1609 from fluxcd/patch-reconcile-req
Browse files Browse the repository at this point in the history
Request reconcile using patch instead of update
  • Loading branch information
hiddeco authored Aug 4, 2021
2 parents 3570fab + 9607b07 commit 4f4f0d7
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/flux/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (a alertAdapter) asClientObject() client.Object {
return a.Alert
}

func (a alertAdapter) deepCopyClientObject() client.Object {
return a.Alert.DeepCopy()
}

// notificationv1.Alert

type alertListAdapter struct {
Expand Down
4 changes: 4 additions & 0 deletions cmd/flux/alert_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (a alertProviderAdapter) asClientObject() client.Object {
return a.Provider
}

func (a alertProviderAdapter) deepCopyClientObject() client.Object {
return a.Provider.DeepCopy()
}

// notificationv1.Provider

type alertProviderListAdapter struct {
Expand Down
4 changes: 4 additions & 0 deletions cmd/flux/helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (h helmReleaseAdapter) asClientObject() client.Object {
return h.HelmRelease
}

func (h helmReleaseAdapter) deepCopyClientObject() client.Object {
return h.HelmRelease.DeepCopy()
}

// helmv2.HelmReleaseList

type helmReleaseListAdapter struct {
Expand Down
8 changes: 8 additions & 0 deletions cmd/flux/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (a imageRepositoryAdapter) asClientObject() client.Object {
return a.ImageRepository
}

func (a imageRepositoryAdapter) deepCopyClientObject() client.Object {
return a.ImageRepository.DeepCopy()
}

// imagev1.ImageRepositoryList

type imageRepositoryListAdapter struct {
Expand Down Expand Up @@ -100,6 +104,10 @@ func (a imageUpdateAutomationAdapter) asClientObject() client.Object {
return a.ImageUpdateAutomation
}

func (a imageUpdateAutomationAdapter) deepCopyClientObject() client.Object {
return a.ImageUpdateAutomation.DeepCopy()
}

// autov1.ImageUpdateAutomationList

type imageUpdateAutomationListAdapter struct {
Expand Down
4 changes: 4 additions & 0 deletions cmd/flux/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (a kustomizationAdapter) asClientObject() client.Object {
return a.Kustomization
}

func (a kustomizationAdapter) deepCopyClientObject() client.Object {
return a.Kustomization.DeepCopy()
}

// kustomizev1.KustomizationList

type kustomizationListAdapter struct {
Expand Down
7 changes: 7 additions & 0 deletions cmd/flux/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ type adapter interface {
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
// controller runtime distinguishes between methods dealing with
// objects and lists.
Expand Down
4 changes: 4 additions & 0 deletions cmd/flux/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (a receiverAdapter) asClientObject() client.Object {
return a.Receiver
}

func (a receiverAdapter) deepCopyClientObject() client.Object {
return a.Receiver.DeepCopy()
}

// notificationv1.Receiver

type receiverListAdapter struct {
Expand Down
4 changes: 3 additions & 1 deletion cmd/flux/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type reconcileCommand struct {

type reconcilable interface {
adapter // to be able to load from the cluster
copyable // to be able to calculate patches
suspendable // to tell if it's suspended

// these are implemented by anything embedding metav1.ObjectMeta
Expand Down Expand Up @@ -142,6 +143,7 @@ func requestReconciliation(ctx context.Context, kubeClient client.Client,
if err := kubeClient.Get(ctx, namespacedName, obj.asClientObject()); err != nil {
return err
}
patch := client.MergeFrom(obj.deepCopyClientObject())
if ann := obj.GetAnnotations(); ann == nil {
obj.SetAnnotations(map[string]string{
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
Expand All @@ -150,7 +152,7 @@ func requestReconciliation(ctx context.Context, kubeClient client.Client,
ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano)
obj.SetAnnotations(ann)
}
return kubeClient.Update(ctx, obj.asClientObject())
return kubeClient.Patch(ctx, obj.asClientObject(), patch)
})
}

Expand Down
16 changes: 16 additions & 0 deletions cmd/flux/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (a bucketAdapter) asClientObject() client.Object {
return a.Bucket
}

func (a bucketAdapter) deepCopyClientObject() client.Object {
return a.Bucket.DeepCopy()
}

// sourcev1.BucketList

type bucketListAdapter struct {
Expand Down Expand Up @@ -70,6 +74,10 @@ func (a helmChartAdapter) asClientObject() client.Object {
return a.HelmChart
}

func (a helmChartAdapter) deepCopyClientObject() client.Object {
return a.HelmChart.DeepCopy()
}

// sourcev1.HelmChartList

type helmChartListAdapter struct {
Expand Down Expand Up @@ -99,6 +107,10 @@ func (a gitRepositoryAdapter) asClientObject() client.Object {
return a.GitRepository
}

func (a gitRepositoryAdapter) deepCopyClientObject() client.Object {
return a.GitRepository.DeepCopy()
}

// sourcev1.GitRepositoryList

type gitRepositoryListAdapter struct {
Expand Down Expand Up @@ -128,6 +140,10 @@ func (a helmRepositoryAdapter) asClientObject() client.Object {
return a.HelmRepository
}

func (a helmRepositoryAdapter) deepCopyClientObject() client.Object {
return a.HelmRepository.DeepCopy()
}

// sourcev1.HelmRepositoryList

type helmRepositoryListAdapter struct {
Expand Down

0 comments on commit 4f4f0d7

Please sign in to comment.