Skip to content

Commit

Permalink
add setGroupMembers in getControlPlaneByUID
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Oct 30, 2024
1 parent ad1f42c commit ed01d88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func Create[
var id string
switch ent := any(e).(type) {
case *konnectv1alpha1.KonnectGatewayControlPlane:
id, err = getControlPlaneForUID(ctx, sdk.GetControlPlaneSDK(), ent)
id, err = getControlPlaneForUID(ctx, sdk.GetControlPlaneSDK(), sdk.GetControlPlaneGroupSDK(), cl, ent)
case *configurationv1alpha1.KongService:
id, err = getKongServiceForUID(ctx, sdk.GetServicesSDK(), ent)
case *configurationv1alpha1.KongRoute:
Expand Down
19 changes: 18 additions & 1 deletion controller/konnect/ops/ops_controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ func (m membersByID) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
func getControlPlaneForUID(
ctx context.Context,
sdk sdkops.ControlPlaneSDK,
sdkGroups sdkops.ControlPlaneGroupSDK,
cl client.Client,
cp *konnectv1alpha1.KonnectGatewayControlPlane,
) (string, error) {
reqList := sdkkonnectops.ListControlPlanesRequest{
Expand All @@ -230,5 +232,20 @@ func getControlPlaneForUID(
return "", fmt.Errorf("failed listing %s: %w", cp.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.ListControlPlanesResponse.Data), cp)
id, err := getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.ListControlPlanesResponse.Data), cp)
if err != nil {
return "", err
}

if err := setGroupMembers(ctx, cl, cp, id, sdkGroups); err != nil {
// If we failed to set group membership, we should return a specific error with a reason
// so the downstream can handle it properly.
return id, KonnectEntityCreatedButRelationsFailedError{
KonnectID: id,
Err: err,
Reason: konnectv1alpha1.KonnectGatewayControlPlaneProgrammedReasonFailedToSetControlPlaneGroupMembers,
}
}

return id, nil
}

0 comments on commit ed01d88

Please sign in to comment.