Skip to content

Commit

Permalink
merge main into ref-chart-4-15-fix (#2601)
Browse files Browse the repository at this point in the history
* fixed migration query in 90th migration (#2586)

* updated wiring for TelemetryEventClientExtended.go (#2588)

* feat: Provide description for Chart Types (#2585)

* chart description provided with the api call

* added code to provide chart description with the api call

* refined the code for poviding chart description

* mitigated nil pointer exception in ChartService

* refactoring

* changes in sql files

Co-authored-by: Manish Agrawal <[email protected]>

* sql script semicolon fix (#2590)

* Ci Build config API backward compatibilty (#2598)

* docker build config added as backward compatible changes

* dependency injection fix

Co-authored-by: kartik-579 <[email protected]>
Co-authored-by: Prakash Kumar <[email protected]>
Co-authored-by: Manish Agrawal <[email protected]>
Co-authored-by: kripanshdevtron <[email protected]>
  • Loading branch information
5 people authored Nov 9, 2022
1 parent 879c185 commit 5e82591
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 19 deletions.
17 changes: 13 additions & 4 deletions api/appbean/AppDetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ type GitMaterial struct {
}

type DockerConfig struct {
DockerRegistry string `json:"dockerRegistry" validate:"required"`
DockerRepository string `json:"dockerRepository" validate:"required"`
CiBuildConfig *bean.CiBuildConfigBean `json:"ciBuildConfig" validate:"required"`
CheckoutPath string `json:"checkoutPath"`
DockerRegistry string `json:"dockerRegistry" validate:"required"`
DockerRepository string `json:"dockerRepository" validate:"required"`
CiBuildConfig *bean.CiBuildConfigBean `json:"ciBuildConfig"`
DockerBuildConfig *DockerBuildConfig `json:"dockerBuildConfig,omitempty"` // Deprecated, should use CiBuildConfig for development
CheckoutPath string `json:"checkoutPath"`
}

type DockerBuildConfig struct {
GitCheckoutPath string `json:"gitCheckoutPath,omitempty" validate:"required"`
DockerfileRelativePath string `json:"dockerfileRelativePath,omitempty" validate:"required"`
Args map[string]string `json:"args,omitempty"`
TargetPlatform string `json:"targetPlatform"`
DockerBuildOptions map[string]string `json:"dockerBuildOptions,omitempty"`
}

type DeploymentTemplate struct {
Expand Down
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) {
}
})
}
}
14 changes: 13 additions & 1 deletion api/restHandler/CoreAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository"
"github.com/devtron-labs/devtron/pkg/pipeline"
bean2 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
"github.com/devtron-labs/devtron/pkg/sql"
"github.com/devtron-labs/devtron/pkg/team"
"github.com/devtron-labs/devtron/pkg/user"
Expand Down Expand Up @@ -1244,7 +1245,18 @@ func (handler CoreAppRestHandlerImpl) createGitMaterials(appId int, gitMaterials
// create docker config
func (handler CoreAppRestHandlerImpl) createDockerConfig(appId int, dockerConfig *appBean.DockerConfig, userId int32) (error, int) {
handler.logger.Infow("Create App - creating docker config", "appId", appId, "DockerConfig", dockerConfig)

dockerBuildConfig := dockerConfig.DockerBuildConfig
if dockerBuildConfig != nil {
dockerConfig.CheckoutPath = dockerBuildConfig.GitCheckoutPath
dockerConfig.CiBuildConfig = &bean2.CiBuildConfigBean{
DockerBuildConfig: &bean2.DockerBuildConfig{
DockerfilePath: dockerBuildConfig.DockerfileRelativePath,
DockerBuildOptions: dockerBuildConfig.DockerBuildOptions,
Args: dockerBuildConfig.Args,
TargetPlatform: dockerBuildConfig.TargetPlatform,
},
}
}
createDockerConfigRequest := &bean.CiConfigRequest{
AppId: appId,
UserId: userId,
Expand Down
5 changes: 4 additions & 1 deletion client/telemetry/TelemetryEventClientExtended.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
ciWorkflowRepository pipelineConfig.CiWorkflowRepository, cdWorkflowRepository pipelineConfig.CdWorkflowRepository,
dockerArtifactStoreRepository repository.DockerArtifactStoreRepository,
materialRepository pipelineConfig.MaterialRepository, ciTemplateRepository pipelineConfig.CiTemplateRepository,
chartRepository chartRepoRepository.ChartRepository, moduleRepository moduleRepo.ModuleRepository, serverDataStore *serverDataStore.ServerDataStore, userAuditService user.UserAuditService) (*TelemetryEventClientImplExtended, error) {
chartRepository chartRepoRepository.ChartRepository, moduleRepository moduleRepo.ModuleRepository,
serverDataStore *serverDataStore.ServerDataStore, userAuditService user.UserAuditService,
ciBuildConfigService pipeline.CiBuildConfigService) (*TelemetryEventClientImplExtended, error) {

cron := cron.New(
cron.WithChain())
Expand All @@ -72,6 +74,7 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
materialRepository: materialRepository,
ciTemplateRepository: ciTemplateRepository,
chartRepository: chartRepository,
ciBuildConfigService: ciBuildConfigService,
TelemetryEventClientImpl: &TelemetryEventClientImpl{
cron: cron,
logger: logger,
Expand Down
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
4 changes: 2 additions & 2 deletions scripts/sql/90_ci_build_config.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ ALTER TABLE ci_template
ADD COLUMN IF NOT EXISTS ci_build_config_id integer;

ALTER TABLE ONLY public.ci_template
ADD CONSTRAINT IF NOT EXISTS ci_template_ci_build_config_id_fkey FOREIGN KEY (ci_build_config_id) REFERENCES public.ci_build_config(id);
ADD CONSTRAINT ci_template_ci_build_config_id_fkey FOREIGN KEY (ci_build_config_id) REFERENCES public.ci_build_config(id);


ALTER TABLE ci_template_override
ADD COLUMN IF NOT EXISTS ci_build_config_id integer;

ALTER TABLE ONLY public.ci_template_override
ADD CONSTRAINT IF NOT EXISTS ci_template_override_ci_build_config_id_fkey FOREIGN KEY (ci_build_config_id) REFERENCES public.ci_build_config(id);
ADD CONSTRAINT ci_template_override_ci_build_config_id_fkey FOREIGN KEY (ci_build_config_id) REFERENCES public.ci_build_config(id);

ALTER TABLE ci_workflow
ADD COLUMN IF NOT EXISTS ci_build_type varchar(100);
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.');
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.

0 comments on commit 5e82591

Please sign in to comment.