Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Fetch the resource before updating it
Browse files Browse the repository at this point in the history
Signed-off-by: Burak Sekili <[email protected]>
  • Loading branch information
buraksekili committed Jul 12, 2023
1 parent 2877569 commit 8550716
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions controllers/apidefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,20 @@ func (r *ApiDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
upstreamRequestStruct.Spec.CollectLoopingTarget()

// If this is not set, means it is a new object, set it first
if desired.Status.ApiID == "" {
return r.create(ctx, upstreamRequestStruct)
switch desired.Status.ApiID {
case "":
err = r.create(ctx, upstreamRequestStruct)
default:
err = r.update(ctx, upstreamRequestStruct)
}
if err != nil {
return err
}

_ = r.Client.Get(ctx, client.ObjectKeyFromObject(desired), desired) // nolint:errcheck

return r.update(ctx, upstreamRequestStruct)
desired.Spec = upstreamRequestStruct.Spec
return nil
})

var transactionInfo *tykv1alpha1.TransactionInfo
Expand Down Expand Up @@ -461,11 +470,6 @@ func (r *ApiDefinitionReconciler) create(ctx context.Context, desired *tykv1alph
status.ApiID = *desired.Spec.APIID
status.LatestTykSpecHash = calculateHash(apiOnTyk)
status.LatestCRDSpecHash = calculateHash(desired.Spec)
status.LatestTransaction = tykv1alpha1.TransactionInfo{
Time: metav1.Now(),
Status: tykv1alpha1.Successful,
Error: "",
}
},
)
if err != nil {
Expand Down Expand Up @@ -539,11 +543,6 @@ func (r *ApiDefinitionReconciler) update(ctx context.Context, desired *tykv1alph
func(status *tykv1alpha1.ApiDefinitionStatus) {
status.LatestTykSpecHash = calculateHash(apiOnTyk)
status.LatestCRDSpecHash = calculateHash(desired.Spec)
status.LatestTransaction = tykv1alpha1.TransactionInfo{
Time: metav1.Now(),
Status: tykv1alpha1.Successful,
Error: "",
}
},
)
if err != nil {
Expand Down

0 comments on commit 8550716

Please sign in to comment.