Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/chartRepo/repository/ChartRefRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ChartRef struct {
IsAppMetricsSupported bool `sql:"is_app_metrics_supported,notnull"`
DeploymentStrategyPath string `sql:"deployment_strategy_path"`
JsonPathForStrategy string `sql:"json_path_for_strategy"`
EmailId string `sql:"email_id"`
sql.AuditLog
}

Expand All @@ -58,6 +59,7 @@ type ChartRefRepository interface {
FetchChart(name string) ([]*ChartRef, error)
FetchInfoOfChartConfiguredInApp(appId int) (*ChartRef, error)
FetchAllNonUserUploadedChartInfo() ([]*ChartRef, error)
GetAllWithUserEmail() ([]*ChartRef, error)
}
type ChartRefRepositoryImpl struct {
dbConnection *pg.DB
Expand Down Expand Up @@ -171,6 +173,17 @@ func (impl ChartRefRepositoryImpl) FetchInfoOfChartConfiguredInApp(appId int) (*
return &repo, nil
}

func (impl ChartRefRepositoryImpl) GetAllWithUserEmail() ([]*ChartRef, error) {
var chartRefs []*ChartRef
err := impl.dbConnection.
Model(&chartRefs).
Column("chart_ref.id", "chart_ref.name", "chart_ref.chart_description", "chart_ref.version", "chart_ref.user_uploaded", "users.email_id"). // Include user email in the query
Join("JOIN users ON users.id = chart_ref.created_by"). // Join with users table
Where("chart_ref.active = ?", true). // Filter by active charts
Select()
return chartRefs, err
}

// pipeline strategy metadata repository starts here
type DeploymentStrategy string

Expand Down
12 changes: 11 additions & 1 deletion pkg/deployment/deployedApp/DeployedAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import (
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"github.com/devtron-labs/devtron/pkg/cluster/environment/repository"
"github.com/devtron-labs/devtron/pkg/deployment/deployedApp/bean"
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartResourceConfig"
"github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps"
bean3 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean"
"github.com/devtron-labs/devtron/pkg/k8s"
bean4 "github.com/devtron-labs/devtron/pkg/k8s/bean"
"github.com/devtron-labs/devtron/pkg/resourceQualifiers"
"github.com/go-pg/pg"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -91,7 +93,15 @@ func (impl *DeployedAppServiceImpl) StopStartApp(ctx context.Context, stopReques
impl.logger.Errorw("error in fetching latest release", "err", err)
return 0, err
}
stopTemplate := `{"replicaCount":0,"autoscaling":{"MinReplicas":0,"MaxReplicas":0 ,"enabled": false},"kedaAutoscaling":{"minReplicaCount":0,"maxReplicaCount":0 ,"enabled": false}}`
scope := &resourceQualifiers.Scope{
AppId: stopRequest.AppId,
EnvId: stopRequest.EnvironmentId,
}
stopTemplate, err := chartResourceConfig.GetStopTemplate(scope)
if err != nil {
impl.logger.Errorw("error in fetching stop template", "err", err)
return 0, err
}
overrideRequest := &bean2.ValuesOverrideRequest{
PipelineId: pipeline.Id,
AppId: stopRequest.AppId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (impl *ChartRefServiceImpl) FetchCustomChartsInfo() ([]*bean.ChartDto, erro
for _, resultMetadata := range resultsMetadata {
chartsMetadata[resultMetadata.ChartName] = resultMetadata.ChartDescription
}
repo, err := impl.chartRefRepository.GetAll()
repo, err := impl.chartRefRepository.GetAllWithUserEmail()
if err != nil {
return nil, err
}
Expand All @@ -421,6 +421,7 @@ func (impl *ChartRefServiceImpl) FetchCustomChartsInfo() ([]*bean.ChartDto, erro
ChartDescription: ref.ChartDescription,
Version: ref.Version,
IsUserUploaded: ref.UserUploaded,
UploadedBy: ref.EmailId,
}
chartDtos = append(chartDtos, chartDto)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ type ChartDto struct {
ChartDescription string `json:"chartDescription"`
Version string `json:"version"`
IsUserUploaded bool `json:"isUserUploaded"`
UploadedBy string `json:"uploadedBy"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package chartResourceConfig

import "github.com/devtron-labs/devtron/pkg/resourceQualifiers"

func GetStopTemplate(scope *resourceQualifiers.Scope) (string, error) {
stopTemplate := `{"replicaCount":0,"autoscaling":{"MinReplicas":0,"MaxReplicas":0 ,"enabled": false},"kedaAutoscaling":{"minReplicaCount":0,"maxReplicaCount":0 ,"enabled": false}}`
return stopTemplate, nil
}
7 changes: 7 additions & 0 deletions scripts/sql/31902800_app_hibernation_patch.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Drop the unique index if it exists
DROP INDEX IF EXISTS public.chart_ref_schema_unique_active_idx;

-- Drop columns if they exist
ALTER TABLE public.chart_ref_schema
DROP COLUMN IF EXISTS resourceType,
DROP COLUMN IF EXISTS resourceValue;
21 changes: 21 additions & 0 deletions scripts/sql/31902800_app_hibernation_patch.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Begin;

ALTER TABLE public.chart_ref_schema
ADD COLUMN IF NOT EXISTS resourceType INT NOT NULL DEFAULT 0;

ALTER TABLE public.chart_ref_schema
ALTER COLUMN resourceType DROP DEFAULT;

ALTER TABLE public.chart_ref_schema
ADD COLUMN IF NOT EXISTS resourceValue TEXT;

-- Migrate data from old column "schema" to "resourceValue"
UPDATE public.chart_ref_schema
SET resourceValue = schema
WHERE schema IS NOT NULL;

CREATE UNIQUE INDEX chart_ref_schema_unique_active_idx
ON public.chart_ref_schema (name, resourceType)
WHERE active = TRUE;

End;
2 changes: 1 addition & 1 deletion wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.