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 0b966ec commit fe39896
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion controller/konnect/ops/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func _setControlPlaneGroupMembersReferenceResolvedCondition(
reason consts.ConditionReason,
msg string,
) {
if cpGroup.Spec.ClusterType == nil || *cpGroup.Spec.ClusterType != sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup {
if cpGroup.Spec.ClusterType == nil || *cpGroup.Spec.ClusterType != sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlane {
return
}
k8sutils.SetCondition(
Expand Down
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
23 changes: 19 additions & 4 deletions controller/konnect/ops/ops_controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ func setGroupMembers(
id string,
sdkGroups sdkops.ControlPlaneGroupSDK,
) error {
// REVIEW: should we add MembersReferenceResolved condition for CP groups with 0 members?
if len(cp.Spec.Members) == 0 ||
cp.Spec.ClusterType == nil ||
if cp.Spec.ClusterType == nil ||
*cp.Spec.ClusterType != sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup {
return nil
}
Expand Down Expand Up @@ -214,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 @@ -232,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 fe39896

Please sign in to comment.