Skip to content

feat(tools): add pulumi app to start a complete testing platform #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Feb 13, 2025

  • wip
  • feat: add k8s-stack pulumi app

@gfyrag gfyrag requested a review from a team as a code owner February 13, 2025 17:01
Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

The pull request updates the Kubernetes stack tools by adding new Pulumi-based infrastructure components and modifying configuration management. A new ignore rule in the .gitignore file excludes Pulumi-generated YAML files. A new main.go file initializes a Kubernetes stack with configurable telemetry options, while two new files in the pkg directory add component definitions: one for managing a PostgreSQL instance via a Helm chart and another for creating a ledger stack resource that integrates ledger and PostgreSQL components with namespace creation. No exported or public declarations were modified.

Changes

File(s) Change Summary
tools/k8s-stack/.gitignore Added an entry to exclude all files matching Pulumi.*.yaml from Git tracking.
tools/k8s-stack/main.go Introduces a Pulumi application to initialize a Kubernetes stack with configuration parsing, optional OpenTelemetry tracing/metrics, and helper functions.
tools/k8s-stack/pkg/{postgres.go, stack.go} Adds new Pulumi resource components: PostgresComponent to manage a PostgreSQL instance via a Helm chart and StackComponent to deploy a ledger stack with namespace creation and resource integration.

Sequence Diagram(s)

sequenceDiagram
    participant Main as main.go
    participant Pulumi as Pulumi Engine
    participant Stack as StackComponent (NewStack)
    participant PG as PostgresComponent (NewPostgresComponent)

    Main ->> Pulumi: Execute Pulumi program
    Pulumi ->> Main: Invoke main()
    Main ->> Main: Retrieve configuration & optional telemetry setup
    Main ->> Stack: Call NewStack with stack configuration
    Stack ->> Stack: Generate/validate Kubernetes namespace
    Stack ->> PG: Call NewPostgresComponent with namespace details
    PG -->> Stack: Return Postgres outputs (username, password, etc.)
    Stack -->> Main: Return deployed stack outputs (including ledger URL)
    Main ->> Pulumi: Export outputs for the infrastructure stack
Loading

Poem

I'm a nimble rabbit, coding with delight,
Hopping through stacks from morning till night.
Pulumi powers my journey so bright,
With PostgreSQL charts taking flight.
Carrots and code—oh, what a sight!
Happy hops in a world of tech light.
🥕💻 Hop on, the stack is just right!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gfyrag gfyrag force-pushed the feat/tools-k8s-platform branch 2 times, most recently from 89c7458 to febd1c0 Compare February 13, 2025 17:03
@gfyrag gfyrag force-pushed the feat/tools-k8s-platform branch from febd1c0 to 84b3451 Compare February 13, 2025 17:03
@gfyrag gfyrag force-pushed the feat/tools-k8s-platform branch from 84b3451 to c8583ff Compare February 13, 2025 17:04
@gfyrag gfyrag enabled auto-merge February 13, 2025 17:05
@gfyrag gfyrag added this pull request to the merge queue Feb 13, 2025
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.57%. Comparing base (f7cf431) to head (c8583ff).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #683      +/-   ##
==========================================
- Coverage   81.63%   81.57%   -0.06%     
==========================================
  Files         131      131              
  Lines        7061     7071      +10     
==========================================
+ Hits         5764     5768       +4     
- Misses        994      998       +4     
- Partials      303      305       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tools/k8s-stack/pkg/postgres.go (1)

30-31: Avoid storing credentials in plain text

Hardcoding database credentials can pose security risks. Consider using Pulumi config secrets, environment variables, or a credentials management approach for better security and maintainability.

tools/k8s-stack/main.go (1)

73-74: Handle parse errors for durations

time.ParseDuration silently defaults to zero on invalid inputs. Consider handling err or logging warnings to avoid unexpected behavior or silently misconfiguring time-based settings.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3821958 and c8583ff.

⛔ Files ignored due to path filters (3)
  • tools/k8s-stack/Pulumi.yaml is excluded by !**/*.yaml
  • tools/k8s-stack/go.mod is excluded by !**/*.mod
  • tools/k8s-stack/go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (4)
  • tools/k8s-stack/.gitignore (1 hunks)
  • tools/k8s-stack/main.go (1 hunks)
  • tools/k8s-stack/pkg/postgres.go (1 hunks)
  • tools/k8s-stack/pkg/stack.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tools/k8s-stack/.gitignore
🧰 Additional context used
🪛 golangci-lint (1.62.2)
tools/k8s-stack/pkg/stack.go

75-75: ineffectual assignment to err

(ineffassign)

Comment on lines +75 to +104
cmp.Ledger, err = pulumi_ledger.NewComponent(ctx, "ledger", &pulumi_ledger.ComponentArgs{
Timeout: pulumi.Int(30),
Debug: args.Debug,
Tag: args.Ledger.Version,
ImagePullPolicy: pulumi.String("Always"),
Postgres: pulumi_ledger.PostgresArgs{
URI: pulumi.Sprintf(
"postgres://%s:%s@%s:%d/postgres?sslmode=disable",
cmp.Postgres.Username,
cmp.Postgres.Password,
cmp.Postgres.Host,
cmp.Postgres.Port,
),
MaxIdleConns: pulumix.Val(pointer.For(100)),
MaxOpenConns: pulumix.Val(pointer.For(100)),
ConnMaxIdleTime: pulumix.Val(pointer.For(time.Minute)),
},
ExperimentalFeatures: pulumi.Bool(true),
Namespace: pulumix.Apply(namespace.Metadata.Name().ToOutput(ctx.Context()).Untyped().(pulumi.StringPtrOutput), func(ns *string) string {
return *ns
}),
GracePeriod: args.Ledger.GracePeriod,
Upgrade: args.Ledger.Upgrade,
Otel: args.Ledger.Otel,
},
append(resourceOptions, pulumi.DependsOn([]pulumi.Resource{
cmp.Postgres,
}))...,
)

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle overshadowed error after Ledger creation

The err assigned by pulumi_ledger.NewComponent is never checked because at line 105 you're introducing a new err variable in the if err := ... block, overshadowing the previous one. This can silently ignore critical errors if the ledger creation fails.

Consider applying this fix to properly handle errors:

 cmp.Ledger, err = pulumi_ledger.NewComponent(ctx, "ledger", &pulumi_ledger.ComponentArgs{
     // existing ledger args...
 })
+if err != nil {
+    return nil, fmt.Errorf("creating ledger component: %w", err)
+}

 if err := ctx.RegisterResourceOutputs(cmp, pulumi.Map{}); err != nil {
     return nil, fmt.Errorf("registering outputs: %w", err)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cmp.Ledger, err = pulumi_ledger.NewComponent(ctx, "ledger", &pulumi_ledger.ComponentArgs{
Timeout: pulumi.Int(30),
Debug: args.Debug,
Tag: args.Ledger.Version,
ImagePullPolicy: pulumi.String("Always"),
Postgres: pulumi_ledger.PostgresArgs{
URI: pulumi.Sprintf(
"postgres://%s:%s@%s:%d/postgres?sslmode=disable",
cmp.Postgres.Username,
cmp.Postgres.Password,
cmp.Postgres.Host,
cmp.Postgres.Port,
),
MaxIdleConns: pulumix.Val(pointer.For(100)),
MaxOpenConns: pulumix.Val(pointer.For(100)),
ConnMaxIdleTime: pulumix.Val(pointer.For(time.Minute)),
},
ExperimentalFeatures: pulumi.Bool(true),
Namespace: pulumix.Apply(namespace.Metadata.Name().ToOutput(ctx.Context()).Untyped().(pulumi.StringPtrOutput), func(ns *string) string {
return *ns
}),
GracePeriod: args.Ledger.GracePeriod,
Upgrade: args.Ledger.Upgrade,
Otel: args.Ledger.Otel,
},
append(resourceOptions, pulumi.DependsOn([]pulumi.Resource{
cmp.Postgres,
}))...,
)
cmp.Ledger, err = pulumi_ledger.NewComponent(ctx, "ledger", &pulumi_ledger.ComponentArgs{
Timeout: pulumi.Int(30),
Debug: args.Debug,
Tag: args.Ledger.Version,
ImagePullPolicy: pulumi.String("Always"),
Postgres: pulumi_ledger.PostgresArgs{
URI: pulumi.Sprintf(
"postgres://%s:%s@%s:%d/postgres?sslmode=disable",
cmp.Postgres.Username,
cmp.Postgres.Password,
cmp.Postgres.Host,
cmp.Postgres.Port,
),
MaxIdleConns: pulumix.Val(pointer.For(100)),
MaxOpenConns: pulumix.Val(pointer.For(100)),
ConnMaxIdleTime: pulumix.Val(pointer.For(time.Minute)),
},
ExperimentalFeatures: pulumi.Bool(true),
Namespace: pulumix.Apply(namespace.Metadata.Name().ToOutput(ctx.Context()).Untyped().(pulumi.StringPtrOutput), func(ns *string) string {
return *ns
}),
GracePeriod: args.Ledger.GracePeriod,
Upgrade: args.Ledger.Upgrade,
Otel: args.Ledger.Otel,
},
append(resourceOptions, pulumi.DependsOn([]pulumi.Resource{
cmp.Postgres,
}))...,
)
if err != nil {
return nil, fmt.Errorf("creating ledger component: %w", err)
}
if err := ctx.RegisterResourceOutputs(cmp, pulumi.Map{}); err != nil {
return nil, fmt.Errorf("registering outputs: %w", err)
}
🧰 Tools
🪛 golangci-lint (1.62.2)

75-75: ineffectual assignment to err

(ineffassign)

Merged via the queue into main with commit a5b1d09 Feb 13, 2025
9 of 10 checks passed
@gfyrag gfyrag deleted the feat/tools-k8s-platform branch February 13, 2025 17:12
@gfyrag gfyrag mentioned this pull request Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants