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

Feat/env template#376

Merged
abdheshnayak merged 5 commits into
release-v1.0.8from
feat/env-template
Oct 1, 2024
Merged

Feat/env template#376
abdheshnayak merged 5 commits into
release-v1.0.8from
feat/env-template

Conversation

@abdheshnayak
Copy link
Copy Markdown
Contributor

@abdheshnayak abdheshnayak commented Oct 1, 2024

  • added template env while creating teams

Summary by Sourcery

Implement a feature to set up a default environment template, enabling the creation of environments based on a predefined template. Enhance intercept configurations with optional IP address support and update the supergraph configuration by commenting out the iot-console-api subgraph.

New Features:

  • Introduce a default environment template setup mechanism, allowing environments to be cloned from a predefined template.

Enhancements:

  • Add support for optional IP address specification in intercept configurations.

Build:

  • Comment out the iot-console-api subgraph configuration in the supergraph.yml file.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Oct 1, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new feature for creating environment templates. The main changes include adding a new function to set up a default environment template, modifying the environment creation process, and adding support for cloning environment templates.

Sequence Diagram

sequenceDiagram
    participant User
    participant API
    participant Domain
    participant Repositories
    User->>API: Request to setup default environment
    API->>Domain: Call SetupDefaultEnvTemplate
    Domain->>Repositories: Clone environment template
    Repositories-->>Domain: Return cloned environment
    Domain-->>API: Confirm setup
    API-->>User: Setup complete
    User->>API: Create new environment
    API->>Domain: Call CreateEnvironment
    Domain->>Domain: Check for reserved names
    Domain->>Repositories: Create environment
    Repositories-->>Domain: Return created environment
    Domain-->>API: Return new environment
    API-->>User: Environment created
Loading

File-Level Changes

Change Details Files
Added functionality to set up a default environment template
  • Introduced a new function SetupDefaultEnvTemplate
  • Added environment variables for default template account name and template name
  • Created a new GraphQL mutation for setting up the default environment
apps/console/internal/domain/environment.go
apps/console/internal/env/env.go
apps/console/internal/app/graph/schema.resolvers.go
Modified the environment creation process
  • Added a check for reserved names based on the default environment template
  • Made the cluster name optional when creating an environment
  • Updated the logic for setting cluster ownership labels
apps/console/internal/domain/environment.go
Implemented environment template cloning functionality
  • Added a new file clone-env-template.go with CloneEnvTemplate function
  • Implemented logic to clone apps, external apps, secrets, configs, routers, and managed resources
apps/console/internal/domain/clone-env-template.go
Updated API interfaces and models
  • Added SetupDefaultEnvTemplate to the Domain interface
  • Updated models to include new fields for intercepts
apps/console/internal/domain/api.go
apps/console/internal/app/graph/model/models_gen.go
Made minor changes and improvements
  • Updated resource mapping logic
  • Commented out iot-console-api in the supergraph configuration
apps/console/internal/domain/resource-mapping.go
apps/gateway/supergraph.yml

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

@abdheshnayak abdheshnayak merged commit 6b353e5 into release-v1.0.8 Oct 1, 2024
@abdheshnayak abdheshnayak deleted the feat/env-template branch October 1, 2024 12:30
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 @abdheshnayak - 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 and I'll use the feedback to improve your reviews.

EnvRoutingMode crdsv1.EnvironmentRoutingMode
}

func (d *domain) CloneEnvTemplate(ctx ConsoleContext, args CloneEnvironmentTemplateArgs) (*entities.Environment, 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: Improve error handling and resource management in CloneEnvTemplate

The CloneEnvTemplate function is creating multiple resources. Consider implementing a rollback mechanism or using transactions to ensure that all resources are created successfully or none at all. This will help maintain data consistency in case of partial failures.

func (d *domain) CloneEnvTemplate(ctx ConsoleContext, args CloneEnvironmentTemplateArgs) (*entities.Environment, error) {
	tx, err := d.db.BeginTx(ctx, nil)
	if err != nil {
		return nil, errors.NewE(err)
	}
	defer tx.Rollback()

	env, err := d.cloneEnvTemplateWithTx(ctx, tx, args)
	if err != nil {
		return nil, errors.NewE(err)
	}

	if err := tx.Commit(); err != nil {
		return nil, errors.NewE(err)
	}
	return env, nil
}

SyncStatus: t.GenSyncStatus(t.SyncActionApply, 0),
}

if err := d.k8sClient.ValidateObject(ctx, &destEnv.Environment); err != 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: Consider adding more detailed validation for the destination environment

While basic object validation is performed, consider adding more detailed validation specific to the environment creation process. This could include checking for naming conflicts, resource limits, or other business logic constraints.

if err := d.k8sClient.ValidateObject(ctx, &destEnv.Environment); err != nil {
	return nil, errors.NewE(err)
}
if err := d.validateEnvironmentDetails(ctx, destEnv); err != nil {
	return nil, errors.NewE(err)
}

abdheshnayak added a commit that referenced this pull request Nov 5, 2024
- added template env setup mutation query
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.

2 participants