Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Feat/kloudlite edge clusters#367

Merged
nxtcoder17 merged 17 commits into
release-v1.0.7from
feat/kloudlite-edge-clusters
Sep 17, 2024
Merged

Feat/kloudlite edge clusters#367
nxtcoder17 merged 17 commits into
release-v1.0.7from
feat/kloudlite-edge-clusters

Conversation

@nxtcoder17
Copy link
Copy Markdown
Member

@nxtcoder17 nxtcoder17 commented Sep 17, 2024

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:

  • Introduce support for Kloudlite edge clusters, allowing for the allocation and management of edge clusters within the platform.
  • Add new gRPC services for managing platform edge clusters, including listing, allocating, and retrieving allocated clusters.
  • Implement a new feature to ensure global VPN connections for clusters, enhancing network connectivity and security.

Enhancements:

  • Refactor the internal structure of the project to better organize domain logic and improve modularity.
  • Enhance logging capabilities across various components to provide more detailed and structured logs.
  • Improve the handling of environment variables and configuration settings for better flexibility and control.

Build:

  • Update Taskfile to include new build tasks for generating protobuf files and constants.
  • Modify build scripts to support different architectures and improve build process efficiency.

CI:

  • Add new CI tasks for building and testing the newly introduced gRPC services and protobuf files.

Documentation:

  • Update documentation to reflect the new features and changes in the API, including the management of edge clusters and VPN connections.

Tests:

  • Add unit tests for the new platform edge cluster allocation logic to ensure correctness and reliability.
  • Implement tests for the new gRPC services to validate their functionality and integration.

@nxtcoder17 nxtcoder17 self-assigned this Sep 17, 2024
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Sep 17, 2024

Reviewer's Guide by Sourcery

This 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

Change Details Files
Implemented platform edge cluster management
  • Added new entities and repositories for PlatformEdgeCluster and ClusterAllocation
  • Created new gRPC services for platform edge operations
  • Implemented logic for allocating and managing edge clusters
apps/message-office/internal/domain/platform-edge/repo.go
apps/message-office/internal/entities/platform-edge-cluster.go
apps/message-office/internal/entities/allocation.go
apps/message-office/protobufs/platform-edge/platform-edge.pb.go
apps/message-office/protobufs/platform-edge/platform-edge_grpc.pb.go
Refactored and updated gRPC services
  • Updated Infra gRPC service with new methods
  • Implemented new MessageOfficeService adapter
  • Added ClusterToken gRPC service
apps/infra/protobufs/infra/infra.pb.go
apps/infra/protobufs/infra/infra_grpc.pb.go
apps/infra/internal/app/adapters/message-office-svc.go
apps/message-office/protobufs/cluster-token/cluster-token.pb.go
apps/message-office/protobufs/cluster-token/cluster-token_grpc.pb.go
Enhanced error handling and logging
  • Implemented new error types and constants
  • Added gRPC error parsing and creation utilities
  • Updated logging format and added request logging for gRPC
apps/message-office/errors/errors.go
pkg/grpc/errors.go
pkg/grpc/logger.go
pkg/logging/slog-logger.go
Refactored domain logic and interfaces
  • Created new domain interfaces for environments and platform edge
  • Updated existing domain implementations
  • Added new service interfaces for IAM and Infra
apps/console/internal/domain/environments/domain.go
apps/console/internal/domain/types/types.go
apps/console/internal/domain/ports/iam-service.go
apps/console/internal/domain/ports/infra-service.go
Updated entity structures and constants
  • Added new fields to existing entities
  • Generated new field constants
  • Created new entities for edge clusters
apps/console/internal/entities/environment.go
apps/console/internal/entities/field-constants/generated_constants.go
apps/console/internal/entities/kloudlite-edge-cluster.go
apps/message-office/internal/entities/field-constants/generated_constants.go

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +29 to +90
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}

@nxtcoder17 nxtcoder17 force-pushed the feat/kloudlite-edge-clusters branch from 4a323f5 to 6802a6b Compare September 17, 2024 12:47
@nxtcoder17 nxtcoder17 force-pushed the feat/kloudlite-edge-clusters branch from 1385f3e to d5c1324 Compare September 17, 2024 12:57
@nxtcoder17 nxtcoder17 merged commit 9e0d718 into release-v1.0.7 Sep 17, 2024
@nxtcoder17 nxtcoder17 deleted the feat/kloudlite-edge-clusters branch September 17, 2024 13:04
@kloudlite kloudlite deleted a comment from sourcery-ai Bot Sep 17, 2024
@kloudlite kloudlite deleted a comment from sourcery-ai Bot Sep 17, 2024
abdheshnayak pushed a commit that referenced this pull request Nov 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant