Skip to content

Commit

Permalink
feat(konnect): fallback to create on not found error when upserting t…
Browse files Browse the repository at this point in the history
…he SNI
  • Loading branch information
pmalek committed Sep 30, 2024
1 parent 21074cb commit fe61cec
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions controller/konnect/ops/ops_kongsni.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func createSNI(
sdk SNIsSDK,
sni *configurationv1alpha1.KongSNI,
) error {

cpID := sni.GetControlPlaneID()
if cpID == "" {
return fmt.Errorf("can't create %T %s without a Konnect ControlPlane ID", sni, client.ObjectKeyFromObject(sni))
Expand Down Expand Up @@ -70,9 +69,34 @@ func updateSNI(
SNIWithoutParents: kongSNIToSNIWithoutParents(sni),
})

if errWrapped := wrapErrIfKonnectOpFailed(err, UpdateOp, sni); errWrapped != nil {
SetKonnectEntityProgrammedConditionFalse(sni, "FailedToUpdate", errWrapped.Error())
return errWrapped
// TODO: handle already exists
// Can't adopt it as it will cause conflicts between the controller
// that created that entity and already manages it, hm
if errWrap := wrapErrIfKonnectOpFailed(err, UpdateOp, sni); errWrap != nil {
// SNI update operation returns an SDKError instead of a NotFoundError.
var sdkError *sdkkonnecterrs.SDKError
if errors.As(errWrap, &sdkError) {
switch sdkError.StatusCode {
case 404:
if err := createSNI(ctx, sdk, sni); err != nil {
return FailedKonnectOpError[configurationv1alpha1.KongSNI]{
Op: UpdateOp,
Err: err,
}
}
// Create succeeded, createSNI sets the status so no need to do this here.

return nil
default:
return FailedKonnectOpError[configurationv1alpha1.KongSNI]{
Op: UpdateOp,
Err: sdkError,
}
}
}

SetKonnectEntityProgrammedConditionFalse(sni, "FailedToUpdate", errWrap.Error())
return errWrap
}

SetKonnectEntityProgrammedCondition(sni)
Expand Down

0 comments on commit fe61cec

Please sign in to comment.