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

[FEAT] supports intercepting app on a local cluster#372

Merged
nxtcoder17 merged 1 commit into
release-v1.0.8from
feat/intercept-on-local-cluster
Sep 27, 2024
Merged

[FEAT] supports intercepting app on a local cluster#372
nxtcoder17 merged 1 commit into
release-v1.0.8from
feat/intercept-on-local-cluster

Conversation

@nxtcoder17
Copy link
Copy Markdown
Member

@nxtcoder17 nxtcoder17 commented Sep 27, 2024

Summary by Sourcery

Introduce functionality to intercept applications on a local cluster, including updates to the domain interface and GraphQL resolvers to support this feature.

New Features:

  • Add support for intercepting applications on a local cluster by implementing the InterceptAppOnLocalCluster function in the domain layer.

Enhancements:

  • Extend the GraphQL mutation resolver to handle intercepting applications on a local cluster through the CoreInterceptAppOnLocalCluster function.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Sep 27, 2024

Reviewer's Guide by Sourcery

This pull request implements a new feature to support intercepting an app on a local cluster. The changes primarily involve adding a new method InterceptAppOnLocalCluster to the domain interface and its implementation, along with the necessary modifications to the GraphQL resolver and field constants.

Sequence Diagram

sequenceDiagram
    participant Client
    participant GraphQL
    participant Domain
    participant AppRepo
    Client->>GraphQL: CoreInterceptAppOnLocalCluster
    GraphQL->>Domain: InterceptAppOnLocalCluster
    Domain->>Domain: canMutateResourcesInEnvironment
    Domain->>AppRepo: Patch
    AppRepo-->>Domain: Updated App
    Domain->>Domain: applyApp
    Domain-->>GraphQL: Result
    GraphQL-->>Client: Result
Loading

File-Level Changes

Change Details Files
Added new method to intercept app on local cluster
  • Implemented InterceptAppOnLocalCluster method in domain
  • Added error handling and permission checking
  • Created patch for app repository with intercept details
  • Applied updated app configuration
apps/console/internal/domain/app.go
apps/console/internal/domain/api.go
Updated GraphQL resolver to support local cluster interception
  • Added CoreInterceptAppOnLocalCluster resolver method
  • Implemented conversion of port mappings from GraphQL input to domain type
apps/console/internal/app/graph/schema.resolvers.go
Added new field constants for intercept IP address
  • Added AppSpecInterceptToIPAddr constant
  • Added ExternalAppSpecInterceptToIPAddr constant
apps/console/internal/entities/field-constants/generated_constants.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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:

  • Consider adding a brief comment for the new InterceptAppOnLocalCluster function to explain its purpose and how it differs from the regular InterceptApp function.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 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 thread apps/console/internal/domain/app.go Outdated
}

// InterceptApp implements Domain.
func (d *domain) InterceptAppOnLocalCluster(ctx ResourceContext, appName string, clusterName string, serviceIP string, intercept bool, portMappings []crdsv1.AppInterceptPortMappings) (bool, error) {
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: Consider using a struct for function parameters

The function has a long parameter list. Consider creating a struct to encapsulate these parameters, which could improve readability and make it easier to extend the function in the future.

type InterceptAppParams struct {
    Ctx           ResourceContext
    AppName       string
    ClusterName   string
    ServiceIP     string
    Intercept     bool
    PortMappings  []crdsv1.AppInterceptPortMappings
}

func (d *domain) InterceptAppOnLocalCluster(params InterceptAppParams) (bool, error) {

return true, nil
}

// InterceptApp implements Domain.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the InterceptApp functions into a single, more flexible function with options.

The introduction of InterceptAppOnLocalCluster unnecessarily duplicates logic from InterceptApp. To reduce complexity and improve maintainability, consider refactoring these functions into a single, more flexible function. Here's a suggested approach:

func (d *domain) InterceptApp(ctx ResourceContext, appName string, intercept bool, options InterceptOptions) (bool, error) {
    if err := d.canMutateResourcesInEnvironment(ctx); err != nil {
        return false, errors.NewE(err)
    }

    patch := repos.Document{
        fc.AppSpecInterceptEnabled: intercept,
    }

    if options.ToDevice != "" {
        patch[fc.AppSpecInterceptToDevice] = options.ToDevice
    }
    if options.ToIPAddr != "" {
        patch[fc.AppSpecInterceptToIPAddr] = options.ToIPAddr
    }
    if options.PortMappings != nil {
        patch[fc.AppSpecInterceptPortMappings] = options.PortMappings
    }

    uApp, err := d.appRepo.Patch(ctx, ctx.DBFilters().Add(fields.MetadataName, appName), patch)
    if err != nil {
        return false, errors.NewE(err)
    }
    if err := d.applyApp(ctx, uApp); err != nil {
        return false, errors.NewE(err)
    }
    return true, nil
}

type InterceptOptions struct {
    ToDevice     string
    ToIPAddr     string
    PortMappings []crdsv1.AppInterceptPortMappings
}

This refactoring combines both functions into a single, more flexible InterceptApp function. It uses an InterceptOptions struct to handle different intercept scenarios, including local cluster specifics. This approach reduces code duplication while maintaining the ability to handle different intercept types. You can then use this function for both regular and local cluster intercepts:

// For regular intercept
options := InterceptOptions{ToDevice: deviceName}
success, err := d.InterceptApp(ctx, appName, true, options)

// For local cluster intercept
options := InterceptOptions{ToDevice: clusterName, ToIPAddr: serviceIP, PortMappings: portMappings}
success, err := d.InterceptApp(ctx, appName, true, options)

This refactoring simplifies the codebase, reduces duplication, and improves maintainability while preserving all functionality and allowing for future extensions.

@nxtcoder17 nxtcoder17 self-assigned this Sep 27, 2024
@nxtcoder17 nxtcoder17 force-pushed the feat/intercept-on-local-cluster branch from cdfc1d0 to c1d981d Compare September 27, 2024 06:22
@nxtcoder17 nxtcoder17 merged commit a686822 into release-v1.0.8 Sep 27, 2024
@nxtcoder17 nxtcoder17 deleted the feat/intercept-on-local-cluster branch September 27, 2024 06:28
abdheshnayak pushed a commit that referenced this pull request Nov 5, 2024
[FEAT] supports intercepting app on a local cluster
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