Feat/kloudlite edge clusters#367
Conversation
This feature is useful while self-hosting the platform, as it saves initial hassle of setting up sendgrid and everything prior to installing chart itself.
Reviewer's Guide by SourceryThis pull request introduces significant changes across multiple services and packages within the Kloudlite API, focusing on implementing edge cluster functionality, improving error handling, and refactoring various components. Key changes include the addition of platform edge cluster management, updates to gRPC services, and modifications to existing domain logic and data structures. File-Level Changes
Tips
|
There was a problem hiding this comment.
Hey @nxtcoder17 - I've reviewed your changes - here's some feedback:
Overall Comments:
- This is a significant and well-structured refactoring that improves the overall architecture. Please ensure that all new components and their interactions are well-documented, and consider updating any existing architecture diagrams to reflect these changes.
- The removal of container registry related code seems intentional, but it would be good to confirm that this functionality has been moved elsewhere or is no longer needed to avoid any unintended loss of features.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟡 Security: 1 issue found
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
| func (r *Repo) AllocatePlatformEdgeCluster(ctx context.Context, region string, account string) (*entities.PlatformEdgeCluster, error) { | ||
| m, err := r.AllocatedClusters.GroupByAndCount(ctx, repos.Filter{fc.ClusterAllocationClusterRegion: region}, fc.ClusterAllocationClusterName, repos.GroupByAndCountOptions{ | ||
| Limit: 1, | ||
| Sort: repos.SortDirectionAsc, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if len(m) > 1 { | ||
| return nil, errors.New("more than one cluster available") | ||
| } | ||
|
|
||
| var clusterName string | ||
|
|
||
| switch len(m) { | ||
| case 0: | ||
| { | ||
| x, err := r.EdgeClusters.FindOne(ctx, repos.Filter{fc.PlatformEdgeClusterRegion: region}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if x == nil { | ||
| return nil, mo_errors.ErrNoClustersInRegion | ||
| } | ||
|
|
||
| clusterName = x.Name | ||
|
|
||
| if _, err := r.AllocatedClusters.Create(ctx, &entities.ClusterAllocation{ | ||
| To: account, | ||
| Cluster: entities.ClusterAllocationClusterRef{ | ||
| Name: clusterName, | ||
| Region: region, | ||
| OwnedByAccount: x.OwnedByAccount, | ||
| PublicDNSHost: x.PublicDNSHostname, | ||
| }, | ||
| }); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| case 1: | ||
| { | ||
| for k := range m { | ||
| clusterName = k | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pec, err := r.EdgeClusters.FindOne(ctx, repos.Filter{ | ||
| fc.PlatformEdgeClusterName: clusterName, | ||
| fc.PlatformEdgeClusterRegion: region, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if pec == nil { | ||
| return nil, mo_errors.ErrNoClustersInRegion | ||
| } | ||
|
|
||
| return pec, nil |
There was a problem hiding this comment.
suggestion (performance): Consider improving error handling and performance in AllocatePlatformEdgeCluster
The current implementation uses GroupByAndCount for allocation, which may not scale well with a large number of clusters. Consider implementing a more efficient allocation strategy. Additionally, error handling could be more granular to differentiate between different types of failures (e.g., no clusters available vs. database errors).
func (r *Repo) AllocatePlatformEdgeCluster(ctx context.Context, region, account string) (*entities.PlatformEdgeCluster, error) {
cluster, err := r.findLeastAllocatedCluster(ctx, region)
if err != nil {
return nil, fmt.Errorf("finding least allocated cluster: %w", err)
}
if err := r.allocateCluster(ctx, cluster, account); err != nil {
return nil, fmt.Errorf("allocating cluster: %w", err)
}
return cluster, nil
}
4a323f5 to
6802a6b
Compare
1385f3e to
d5c1324
Compare
Summary by Sourcery
Introduce Kloudlite edge clusters and enhance the platform with new gRPC services for managing edge clusters and ensuring global VPN connections. Refactor the codebase for better modularity and improve logging and configuration handling. Update build and CI processes to accommodate new features and ensure robust testing.
New Features:
Enhancements:
Build:
CI:
Documentation:
Tests: