-
Notifications
You must be signed in to change notification settings - Fork 554
feat: Add pipeline-level build infrastructure profile support #6838
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
Draft
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/fix-0e06542a-a1ba-4958-a01f-cd07b49eff2b
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |||||
| "github.com/devtron-labs/devtron/pkg/infraConfig/repository" | ||||||
| "github.com/devtron-labs/devtron/pkg/resourceQualifiers" | ||||||
| "github.com/go-pg/pg" | ||||||
| "github.com/pkg/errors" | ||||||
| ) | ||||||
|
|
||||||
| type InfraConfigServiceEnt interface { | ||||||
|
|
@@ -51,6 +52,34 @@ func (impl *InfraConfigServiceImpl) getDefaultBuildxDriverType() v1.BuildxDriver | |||||
| } | ||||||
|
|
||||||
| func (impl *InfraConfigServiceImpl) getInfraProfileIdsByScope(scope *v1.Scope) ([]int, error) { | ||||||
| // for OSS, user can't create infra profiles so no need to fetch infra profiles | ||||||
| // First check if there's a pipeline-level infra profile | ||||||
| if scope.PipelineId > 0 { | ||||||
| pipelineInfraProfileId, err := impl.getPipelineInfraProfileId(scope.PipelineId) | ||||||
| if err != nil { | ||||||
| impl.logger.Errorw("error in fetching pipeline-level infra profile", "pipelineId", scope.PipelineId, "error", err) | ||||||
| return make([]int, 0), err | ||||||
| } | ||||||
| if pipelineInfraProfileId != nil { | ||||||
| impl.logger.Debugw("found pipeline-level infra profile", "pipelineId", scope.PipelineId, "infraProfileId", *pipelineInfraProfileId) | ||||||
| return []int{*pipelineInfraProfileId}, nil | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // For OSS, user can't create infra profiles so no need to fetch infra profiles | ||||||
| // Falls back to global profile | ||||||
| return make([]int, 0), nil | ||||||
| } | ||||||
|
|
||||||
| func (impl *InfraConfigServiceImpl) getPipelineInfraProfileId(pipelineId int) (*int, error) { | ||||||
| // Query the ci_pipeline table directly for the infra_profile_id | ||||||
| var infraProfileId *int | ||||||
| query := `SELECT infra_profile_id FROM ci_pipeline WHERE id = ? AND deleted = false` | ||||||
| _, err := impl.infraProfileRepo.GetDbConnection().Query(&infraProfileId, query, pipelineId) | ||||||
| if err != nil { | ||||||
| if errors.Is(err, pg.ErrNoRows) { | ||||||
| return nil, nil // Pipeline not found, fall back to app-level profile | ||||||
|
||||||
| return nil, nil // Pipeline not found, fall back to app-level profile | |
| return nil, nil // Pipeline not found; returning nil signals caller to handle fallback to app-level profile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| -- Rollback migration for pipeline-level infra profile support | ||
|
|
||
| BEGIN; | ||
|
|
||
| -- Drop the foreign key constraint | ||
| ALTER TABLE ci_pipeline DROP CONSTRAINT IF EXISTS fk_ci_pipeline_infra_profile; | ||
|
|
||
| -- Drop the infra_profile_id column | ||
| ALTER TABLE ci_pipeline DROP COLUMN IF EXISTS infra_profile_id; | ||
|
|
||
| COMMIT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| -- Migration to add pipeline-level infra profile support to ci_pipeline table | ||
| -- This enables selecting different build infrastructure per pipeline | ||
|
|
||
| BEGIN; | ||
|
|
||
| -- Add infra_profile_id column to ci_pipeline table | ||
| ALTER TABLE ci_pipeline | ||
| ADD COLUMN IF NOT EXISTS infra_profile_id INTEGER; | ||
|
|
||
| -- Add foreign key constraint to infra_profile table | ||
| ALTER TABLE ci_pipeline | ||
| ADD CONSTRAINT fk_ci_pipeline_infra_profile | ||
| FOREIGN KEY (infra_profile_id) REFERENCES infra_profile(id); | ||
|
|
||
| -- Add comment to explain the column | ||
| COMMENT ON COLUMN ci_pipeline.infra_profile_id IS 'Optional pipeline-level infra profile override. If null, falls back to application-level profile.'; | ||
|
|
||
| COMMIT; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using raw SQL query instead of the repository pattern breaks the established abstraction. Consider using the CiPipelineRepository.GetInfraProfileIdByPipelineId method that's already implemented in the same PR.