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

feat: GraphQL support for suspend/resume environment#362

Merged
nxtcoder17 merged 1 commit into
release-v1.0.7from
feat/suspend-env
Aug 28, 2024
Merged

feat: GraphQL support for suspend/resume environment#362
nxtcoder17 merged 1 commit into
release-v1.0.7from
feat/suspend-env

Conversation

@nxtcoder17
Copy link
Copy Markdown
Member

@nxtcoder17 nxtcoder17 commented Aug 28, 2024

Resolves kloudlite/kloudlite#280

Summary by Sourcery

Introduce GraphQL support for suspending and resuming environments by adding a 'suspend' field to the EnvironmentSpec. Improve error handling in the DNS server and enhance service binding message handling. Refactor gRPC server code to remove unnecessary logging.

New Features:

  • Add GraphQL support for suspending and resuming environments by introducing a new 'suspend' field in the EnvironmentSpec.

Bug Fixes:

  • Fix error handling in DNS server to properly log errors only when they are not related to missing service bindings or invalid DNS queries.

Enhancements:

  • Improve the OnServiceBindingDeleteMessage function to handle cases where the service binding is not found or has an empty hostname.
  • Enhance the OnServiceBindingUpdateMessage function to handle cases where the service IP is nil.
  • Refactor the gRPC server to remove logging of new connections for cleaner code.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Aug 28, 2024

Reviewer's Guide by Sourcery

This pull request adds GraphQL support for suspending and resuming environments in the Kloudlite console application. The changes include updates to the GraphQL schema, resolver implementations, and related domain logic.

File-Level Changes

Change Details Files
Added 'suspend' field to EnvironmentSpec in GraphQL schema
  • Added 'suspend' field of type Boolean to GithubComKloudliteOperatorApisCrdsV1EnvironmentSpec struct
  • Updated GraphQL schema to include 'suspend' field in EnvironmentSpec type
  • Modified environment resolver to handle the new 'suspend' field
apps/console/internal/app/graph/model/models_gen.go
apps/console/internal/app/graph/generated/generated.go
apps/console/internal/app/graph/environment.resolvers.go
Implemented domain logic for updating environment suspension state
  • Added 'suspend' field to environment update logic in UpdateEnvironment function
  • Created new field constant for EnvironmentSpecSuspend
apps/console/internal/domain/environment.go
apps/console/internal/entities/field-constants/generated_constants.go
Enhanced DNS server implementation
  • Improved error handling in DNS resolver
  • Added new error types for invalid DNS queries and missing service bindings
apps/console/internal/app/dns-server.go
Implemented service binding deletion logic
  • Added implementation for OnServiceBindingDeleteMessage function
  • Updated OnServiceBindingUpdateMessage to check for nil ServiceIP
apps/console/internal/domain/service-binding.go
Minor code improvements and bug fixes
  • Updated error package import in dns-server.go
  • Removed commented out debug logging in GRPC server
  • Fixed potential nil pointer dereference in environment resolver
apps/console/internal/app/dns-server.go
pkg/grpc/server.go
apps/console/internal/app/graph/environment.resolvers.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 and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 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.

return errors.Newf("no service binding found")
}

if svcb.Spec.Hostname == "" {
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 (bug_risk): Consider adding a nil check for svcb.Spec before accessing Hostname

To prevent potential nil pointer dereferences, it's advisable to check if svcb.Spec is not nil before accessing its fields.

Suggested change
if svcb.Spec.Hostname == "" {
if svcb.Spec == nil || svcb.Spec.Hostname == "" {
return nil
}

sp := strings.SplitN(strings.ToLower(question.Name), fmt.Sprintf(".%s", h.kloudliteDNSSuffix), 2)
if len(sp) < 2 {
return nil, fmt.Errorf("failed to split into 2 over .%s", h.kloudliteDNSSuffix)
return nil, errInvalidDNSQuery
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 including context in the error message for easier debugging

While using a predefined error is good, including some context (like the problematic domain) in the error message could aid in debugging complex issues.

Suggested change
return nil, errInvalidDNSQuery
return nil, fmt.Errorf("%w: invalid query for domain %q", errInvalidDNSQuery, question.Name)

@nxtcoder17 nxtcoder17 self-assigned this Aug 28, 2024
@nxtcoder17 nxtcoder17 merged commit cdbfc51 into release-v1.0.7 Aug 28, 2024
@nxtcoder17 nxtcoder17 deleted the feat/suspend-env branch August 28, 2024 11:39
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.

[api] graphql APIs to allow (un)suspending an environment

1 participant