-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UDT PR 7 / N] Implement routing for UDT (#8070)
# Description This change adds support routing decisions based on UDT registrations. The logic in UCP that deals with request routing will now check for resource types and resource provider locations, with a fallback to the previous logic for compatibility. This is powered by a new configuration setting in UCP's configuration, that will be configured to the URL of dynamic-rp. Note that there's nothing in dynamic-rp yet to serve these requests. This will be done in a follow-up. ## Type of change - This pull request adds or changes features of Radius and has an approved issue (issue link required). Part of: #6688 ## Contributor checklist Please verify that the PR meets the following requirements, where applicable: - [ ] An overview of proposed schema changes is included in a linked GitHub issue. - [ ] A design document PR is created in the [design-notes repository](https://github.com/radius-project/design-notes/), if new APIs are being introduced. - [ ] If applicable, design document has been reviewed and approved by Radius maintainers/approvers. - [ ] A PR for the [samples repository](https://github.com/radius-project/samples) is created, if existing samples are affected by the changes in this PR. - [ ] A PR for the [documentation repository](https://github.com/radius-project/docs) is created, if the changes in this PR affect the documentation or any user facing updates are made. - [ ] A PR for the [recipes repository](https://github.com/radius-project/recipes) is created, if existing recipes are affected by the changes in this PR. Signed-off-by: Ryan Nowak <[email protected]>
- Loading branch information
Showing
21 changed files
with
975 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2023 The Radius Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package datamodel | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/radius-project/radius/pkg/ucp/resources" | ||
) | ||
|
||
// ResourceProviderIDFromResourceID converts an inbound resource id to the resource ID | ||
// of the resource provider. | ||
func ResourceProviderIDFromResourceID(id resources.ID) (resources.ID, error) { | ||
// Ex: | ||
// /planes/radius/local/providers/Applications.Test/testResources/foo | ||
// => /planes/radius/local/providers/System.Resources/resourceProviders/Applications.Test | ||
return resources.ParseResource( | ||
id.PlaneScope() + | ||
resources.SegmentSeparator + resources.ProvidersSegment + | ||
resources.SegmentSeparator + ResourceProviderResourceType + | ||
resources.SegmentSeparator + id.ProviderNamespace()) | ||
} | ||
|
||
// ResourceTypeIDFromResourceID converts an inbound resource id to the resource ID | ||
// of the resource type. | ||
func ResourceTypeIDFromResourceID(id resources.ID) (resources.ID, error) { | ||
// Ex: | ||
// /planes/radius/local/providers/Applications.Test/testResources/foo | ||
// => /planes/radius/local/providers/System.Resources/resourceProviders/Applications.Test/resourceTypes/testResources | ||
|
||
// Ex: Applications.Test/testResources | ||
fullyQualifiedResourceType := id.Type() | ||
|
||
// Ex: testResources | ||
unqualifiedResourceType := strings.TrimPrefix(fullyQualifiedResourceType, id.ProviderNamespace()+"/") | ||
|
||
return resources.ParseResource( | ||
id.PlaneScope() + | ||
resources.SegmentSeparator + resources.ProvidersSegment + | ||
resources.SegmentSeparator + ResourceProviderResourceType + | ||
resources.SegmentSeparator + id.ProviderNamespace() + | ||
resources.SegmentSeparator + ResourceTypeResourceUnqualifiedResourceType + | ||
resources.SegmentSeparator + unqualifiedResourceType) | ||
} | ||
|
||
// ResourceProviderLocationIDFromResourceID converts an inbound resource id to the resource ID | ||
// of the resource provider's location. | ||
func ResourceProviderLocationIDFromResourceID(id resources.ID, location string) (resources.ID, error) { | ||
// Ex: | ||
// /planes/radius/local/providers/Applications.Test/testResources/foo + east | ||
// => /planes/radius/local/providers/System.Resources/resourceProviders/Applications.Test/locations/east | ||
base, err := ResourceProviderIDFromResourceID(id) | ||
if err != nil { | ||
return resources.ID{}, err | ||
} | ||
|
||
return base.Append(resources.TypeSegment{Type: LocationUnqualifiedResourceType, Name: location}), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2023 The Radius Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package datamodel | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/radius-project/radius/pkg/ucp/resources" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_ResourceProviderIDFromResourceID(t *testing.T) { | ||
id := resources.MustParse("/planes/radius/local/resourceGroups/test-group/providers/Applications.Test/testResources/foo") | ||
|
||
result, err := ResourceProviderIDFromResourceID(id) | ||
require.NoError(t, err) | ||
|
||
expected := resources.MustParse("/planes/radius/local/providers/System.Resources/resourceProviders/Applications.Test") | ||
require.Equal(t, expected, result) | ||
} | ||
|
||
func Test_ResourceTypeIDFromResourceID(t *testing.T) { | ||
id := resources.MustParse("/planes/radius/local/resourceGroups/test-group/providers/Applications.Test/testResources/foo") | ||
|
||
result, err := ResourceTypeIDFromResourceID(id) | ||
require.NoError(t, err) | ||
|
||
expected := resources.MustParse("/planes/radius/local/providers/System.Resources/resourceProviders/Applications.Test/resourceTypes/testResources") | ||
require.Equal(t, expected, result) | ||
} | ||
|
||
func Test_ResourceProviderLocationIDFromResourceID(t *testing.T) { | ||
id := resources.MustParse("/planes/radius/local/resourceGroups/test-group/providers/Applications.Test/testResources/foo") | ||
|
||
result, err := ResourceProviderLocationIDFromResourceID(id, "east") | ||
require.NoError(t, err) | ||
|
||
expected := resources.MustParse("/planes/radius/local/providers/System.Resources/resourceProviders/Applications.Test/locations/east") | ||
require.Equal(t, expected, result) | ||
} |
Oops, something went wrong.