Skip to content

Commit c9975ee

Browse files
committed
wip
1 parent 849932f commit c9975ee

24 files changed

+103
-136
lines changed

controller/konnect/ops/ops.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,15 +795,20 @@ func getMatchingEntryFromListResponseData[
795795
](
796796
data []T,
797797
entity entity,
798-
) (string, error) {
799-
var id string
798+
) (T, string, error) {
799+
var (
800+
id string
801+
ret T
802+
)
800803
for _, entry := range data {
801804
entryID := entry.GetID()
802805
switch entryID := any(entryID).(type) {
803806
case string:
804807
if entryID != "" {
805808
id = entryID
809+
ret = entry
806810
break
811+
807812
}
808813
case *string:
809814
if entryID != nil && *entryID != "" {
@@ -814,12 +819,12 @@ func getMatchingEntryFromListResponseData[
814819
}
815820

816821
if id == "" {
817-
return "", EntityWithMatchingUIDNotFoundError{
822+
return ret, "", EntityWithMatchingUIDNotFoundError{
818823
Entity: entity,
819824
}
820825
}
821826

822-
return id, nil
827+
return ret, id, nil
823828
}
824829

825830
// ClearInstanceFromError clears the instance field from the error.

controller/konnect/ops/ops_controlplane.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,19 @@ func getControlPlaneForUID(
285285
return "", fmt.Errorf("failed listing %s: %w", cp.GetTypeName(), ErrNilResponse)
286286
}
287287

288-
id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.ListControlPlanesResponse.Data), cp)
288+
entry, id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.ListControlPlanesResponse.Data), cp)
289289
if err != nil {
290290
return "", err
291291
}
292292

293+
old := cp.DeepCopy()
294+
if fillKonnectGatewayControlPlaneStatusFromResponse(cp, entry.Config) {
295+
_, err = patch.ApplyStatusPatchIfNotEmpty(ctx, cl, ctrllog.FromContext(ctx), cp, old)
296+
if err != nil {
297+
return id, err
298+
}
299+
}
300+
293301
if err := setGroupMembers(ctx, cl, cp, id, sdkGroups); err != nil {
294302
// If we failed to set group membership, we should return a specific error with a reason
295303
// so the downstream can handle it properly.

controller/konnect/ops/ops_credentialacl.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ func getKongCredentialACLForUID(
204204
}
205205
x := sliceToEntityWithIDPtrSlice(resp.Object.Data)
206206

207-
return getMatchingEntryFromListResponseData(x, cred)
207+
_, id, err := getMatchingEntryFromListResponseData(x, cred)
208+
return id, err
208209
}
209210

210211
func credentialACLMatch(

controller/konnect/ops/ops_credentialapikey.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ func getKongCredentialAPIKeyForUID(
201201
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
202202
}
203203

204-
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
204+
_, id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
205+
return id, err
205206
}
206207

207208
func credentialAPIKeyMatch(

controller/konnect/ops/ops_credentialbasicauth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ func getKongCredentialBasicAuthForUID(
200200
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
201201
}
202202

203-
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
203+
_, id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
204+
return id, err
204205
}
205206

206207
func credentialBasicAuthMatch(

controller/konnect/ops/ops_credentialhmac.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ func getKongCredentialHMACForUID(
205205
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
206206
}
207207

208-
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
208+
_, id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
209+
return id, err
209210
}
210211

211212
func credentialHMACMatch(

controller/konnect/ops/ops_credentialjwt.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ func getKongCredentialJWTForUID(
204204
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
205205
}
206206

207-
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
207+
_, id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
208+
return id, err
208209
}
209210

210211
func credentialJWTMatch(

controller/konnect/ops/ops_kongcacertificate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ func getKongCACertificateForUID(
239239
return "", fmt.Errorf("failed listing %s: %w", cert.GetTypeName(), ErrNilResponse)
240240
}
241241

242-
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cert)
242+
_, id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cert)
243+
return id, err
243244
}
244245

245246
func caCertificateMatch(

controller/konnect/ops/ops_kongcertificate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ func getKongCertificateForUID(
289289
return "", fmt.Errorf("failed listing %s: %w", cert.GetTypeName(), ErrNilResponse)
290290
}
291291

292-
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cert)
292+
_, id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cert)
293+
return id, err
293294
}
294295

295296
func certificateMatch(

controller/konnect/ops/ops_kongconsumer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,5 +460,6 @@ func getKongConsumerForUID(
460460
return "", fmt.Errorf("failed listing %s: %w", consumer.GetTypeName(), ErrNilResponse)
461461
}
462462

463-
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), consumer)
463+
_, id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), consumer)
464+
return id, err
464465
}

0 commit comments

Comments
 (0)