Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion api/restHandler/BatchOperationRestHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
package restHandler

import (
"github.com/devtron-labs/devtron/pkg/apis/devtron/v1"
"testing"

v1 "github.com/devtron-labs/devtron/pkg/apis/devtron/v1"
)

func Test_validatePipeline(t *testing.T) {
Expand Down Expand Up @@ -82,3 +83,4 @@ func Test_validatePipeline(t *testing.T) {
}
})
}
}
39 changes: 31 additions & 8 deletions pkg/chart/ChartService.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ import (
"context"
"encoding/json"
"fmt"

"github.com/devtron-labs/devtron/internal/constants"

//"github.com/devtron-labs/devtron/pkg/pipeline"

"github.com/devtron-labs/devtron/internal/sql/repository/app"
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
"github.com/devtron-labs/devtron/pkg/pipeline/history"

repository4 "github.com/devtron-labs/devtron/pkg/cluster/repository"
"github.com/devtron-labs/devtron/pkg/sql"
dirCopy "github.com/otiai10/copy"
"io/ioutil"
"net/http"
"os"
Expand All @@ -41,6 +40,10 @@ import (
"strings"
"time"

repository4 "github.com/devtron-labs/devtron/pkg/cluster/repository"
"github.com/devtron-labs/devtron/pkg/sql"
dirCopy "github.com/otiai10/copy"

repository2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/devtron-labs/devtron/client/argocdServer/repository"
Expand Down Expand Up @@ -951,11 +954,16 @@ type chartRef struct {
UserUploaded bool `json:"userUploaded"`
}

type ChartRefMetaData struct {
ChartDescription string `json:"chartDescription"`
}

type chartRefResponse struct {
ChartRefs []chartRef `json:"chartRefs"`
LatestChartRef int `json:"latestChartRef"`
LatestAppChartRef int `json:"latestAppChartRef"`
LatestEnvChartRef int `json:"latestEnvChartRef,omitempty"`
ChartRefs []chartRef `json:"chartRefs"`
LatestChartRef int `json:"latestChartRef"`
LatestAppChartRef int `json:"latestAppChartRef"`
LatestEnvChartRef int `json:"latestEnvChartRef,omitempty"`
ChartsMetadata map[string]ChartRefMetaData `json:"chartMetadata"` // chartName vs Metadata
}

type ChartYamlStruct struct {
Expand Down Expand Up @@ -995,14 +1003,28 @@ func (impl ChartServiceImpl) ChartRefAutocomplete() ([]chartRef, error) {
}

func (impl ChartServiceImpl) ChartRefAutocompleteForAppOrEnv(appId int, envId int) (*chartRefResponse, error) {
chartRefResponse := &chartRefResponse{}
chartRefResponse := &chartRefResponse{
ChartsMetadata: make(map[string]ChartRefMetaData),
}
var chartRefs []chartRef

results, err := impl.chartRefRepository.GetAll()
if err != nil {
impl.logger.Errorw("error in fetching chart config", "err", err)
return chartRefResponse, err
}

resultsMetadata, err := impl.chartRefRepository.GetAllChartMetadata()
if err != nil {
impl.logger.Errorw("error in fetching chart metadata", "err", err)
return chartRefResponse, err
}
for _, resultMetadata := range resultsMetadata {
chartRefMetadata := ChartRefMetaData{
ChartDescription: resultMetadata.ChartDescription,
}
chartRefResponse.ChartsMetadata[resultMetadata.ChartName] = chartRefMetadata
}
var LatestAppChartRef int
for _, result := range results {
if len(result.Name) == 0 {
Expand All @@ -1013,6 +1035,7 @@ func (impl ChartServiceImpl) ChartRefAutocompleteForAppOrEnv(appId int, envId in
LatestAppChartRef = result.Id
}
}

chart, err := impl.chartRepository.FindLatestChartForAppByAppId(appId)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error in fetching latest chart", "err", err)
Expand Down
16 changes: 15 additions & 1 deletion pkg/chartRepo/repository/ChartRepoRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
package chartRepoRepository

import (
"strings"

"github.com/devtron-labs/devtron/internal/sql/models"
"github.com/devtron-labs/devtron/internal/sql/repository"
"github.com/devtron-labs/devtron/pkg/sql"
"github.com/go-pg/pg"
"strings"
)

type Chart struct {
Expand Down Expand Up @@ -334,11 +335,18 @@ type ChartRef struct {
sql.AuditLog
}

type ChartRefMetaData struct {
tableName struct{} `sql:"chart_ref_metadata" pg:",discard_unknown_columns"`
ChartName string `sql:"chart_name,pk"`
ChartDescription string `sql:"chart_description"`
}

type ChartRefRepository interface {
Save(chartRepo *ChartRef) error
GetDefault() (*ChartRef, error)
FindById(id int) (*ChartRef, error)
GetAll() ([]*ChartRef, error)
GetAllChartMetadata() ([]*ChartRefMetaData, error)
FindByVersionAndName(name, version string) (*ChartRef, error)
CheckIfDataExists(name string, version string) (bool, error)
FetchChart(name string) ([]*ChartRef, error)
Expand Down Expand Up @@ -397,6 +405,12 @@ func (impl ChartRefRepositoryImpl) GetAll() ([]*ChartRef, error) {
return chartRefs, err
}

func (impl ChartRefRepositoryImpl) GetAllChartMetadata() ([]*ChartRefMetaData, error) {
var chartRefMetaDatas []*ChartRefMetaData
err := impl.dbConnection.Model(&chartRefMetaDatas).Select()
return chartRefMetaDatas, err
}

func (impl ChartRefRepositoryImpl) CheckIfDataExists(name string, version string) (bool, error) {
repo := &ChartRef{}
return impl.dbConnection.Model(repo).
Expand Down
1 change: 1 addition & 0 deletions scripts/sql/91_create_chart_metadata.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."chart_ref_metadata" CASCADE;
16 changes: 16 additions & 0 deletions scripts/sql/91_create_chart_metadata.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Table Definition
CREATE TABLE "public"."chart_ref_metadata" (
"chart_name" varchar(100) NOT NULL,
"chart_description" text NOT NULL,
PRIMARY KEY ("chart_name")
);

---Inserting Records-----
INSERT INTO "chart_ref_metadata" ("chart_name", "chart_description") VALUES
('Rollout Deployment', 'Chart to deploy an advanced version of Deployment that supports blue-green and canary deployments. It requires a rollout controller to run inside the cluster to function.')
INSERT INTO "chart_ref_metadata" ("chart_name", "chart_description") VALUES
('CronJob & Job', 'Chart to deploy a Job/CronJob. Job is a controller object that represents a finite task and CronJob can be used to schedule creation of Jobs.')
INSERT INTO "chart_ref_metadata" ("chart_name", "chart_description") VALUES
('Knative', 'Chart to deploy an Open-Source Enterprise-level solution to deploy Serverless apps.')
INSERT INTO "chart_ref_metadata" ("chart_name", "chart_description") VALUES
('Deployment', 'Chart to deploy a Deployment that runs multiple replicas of your application and automatically replaces any instances that fail or become unresponsive.')