Skip to content

Conversation

@aviralsrivastava01
Copy link
Contributor

@aviralsrivastava01 aviralsrivastava01 commented Dec 20, 2021

Description

Added API for uploading templates directly

Fixes #1325
Allowing user to upload custom deployment templates

Type of change

  • [yes ] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Changes are tested
Yes, checked uploading new charts, checked whether it rejects existing charts(name, version), checked by uploading file with missing files

Checklist:

  • [yes ] The title of the PR states what changed and the related issues number (used for the release note)
  • [yes] I have performed a self-review of my own code
  • [yes] I have tested it for all user roles

@@ -0,0 +1,22 @@
package deployment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file name should be DeploymentConfigRouter

@@ -0,0 +1,122 @@
package deployment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file name should be DeploymentConfigRestHandler

DeploymentTemplateValidate(templatejson interface{}, chartRefId int) (bool, error)
JsonSchemaExtractFromFile(chartRefId int) (map[string]interface{}, error)
GetSchemaAndReadmeForTemplateByChartRefId(chartRefId int) (schema []byte, readme []byte, err error)
ExtractChartIfMissing(ChartData []byte, RefChartDir string, Location string) (string, string, string, error)
Copy link
Contributor

@pghildiyal pghildiyal Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name of arguments cant start with capital letter do it for all the functions added whereever applicable


dir := impl.chartTemplateService.GetDir()

RandomChartWorkingDir := filepath.Join(RefChartDir, Location)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not start with capital letter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it may not be random

return
}

exists, err := handler.chartRefRepository.DataExists(chartName, chartVersion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this before extracting or atleast before copying otherwise this ll create issue, even though it is rejecting the upload it has already copied file in final destination

r.pProfRouter.initPProfRouter(pProfListenerRouter)

// deployment router starts
deploymentSubRouter := r.Router.PathPrefix("/orchestrator/deployment").Subrouter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is deployment/template

description: form-data as request body
required: true
content:
application/json:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content is not application/json

util/helper.go Outdated
}

func CheckForMissingFiles(ChartLocation string) error {
listofFiles := [7]string{"app-values.yaml", "Chart.yaml", "env-values.yaml", "pipeline-values.yaml",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we had to check for both .yaml file as well as .yml file i dont see that here

"time"
)

type DeploymentRestHandler interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change interface and impl object from Deployment to DeploymentConfig, so that one does not gets it confused with deployment operation

}

if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add log here

Copy link
Contributor

@snehith57624 snehith57624 Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging was already done in the function for each and every error so to avoid duplicate logging I ignored logging here

err = handler.chartRefRepository.Save(chartRefs)
if err != nil {
handler.Logger.Errorw("error in saving ConfigMap, CallbackConfigMap", "err", err)
common.WriteJsonResp(w, err, "Chart couldn't be saved", http.StatusBadRequest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be InternalServerError(500), right?


import "github.com/gorilla/mux"

type DeploymentRouter interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update interface and impl in this file to DeploymentConfig as well

r.pProfRouter.initPProfRouter(pProfListenerRouter)

// deployment router starts
deploymentSubRouter := r.Router.PathPrefix("/orchestrator/deployment/template").Subrouter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update this to deploymentConfig as well

GetDefault() (*ChartRef, error)
FindById(id int) (*ChartRef, error)
GetAll() ([]*ChartRef, error)
DataExists(name string, version string) (bool, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change this method name to CheckIfDataExists or something like this for clearer understanding?

ExtractChartIfMissing(chartData []byte, refChartDir string, location string) (*ChartDataInfo, error)
CheckChartExists(chartRefId int) error
GetChartLocation(chartDir string, fileName string) string
ValidateFileUploaded(fileName string) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we uploading any files in response?

return chartLocation
}

func (impl *ChartServiceImpl) ValidateFileUploaded(fileName string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for validating the received file in payload from user.. can we change the uploaded file part to avoid confusion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right it can be ValidateUploadedFile

CheckChartExists(chartRefId int) error
GetChartLocation(chartDir string, fileName string) string
ValidateFileUploaded(fileName string) error
ReadChartYamlForLocation(chartDir string, fileName string) (string, string, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can update the names of the output data variables here instead of only showing the type

Copy link
Contributor

@pghildiyal pghildiyal Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the name of the function also, focus not on how but what. It is more like GetChartNameAndVersionForLocation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the functions are following the above format

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main action is fetching chart metadat and not reading file, if tomorrow we start reading it from some other file its name should not change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pending

var chartService ChartService
err := chartService.CheckChartExists(environmentProperties.ChartRefId)
if err != nil {
impl.logger.Errorw("error in getting missing chart for chartRefId", "err", err, "chartRefId")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please pass value for key chartRefId

@snehith57624 snehith57624 requested a review from pghildiyal March 26, 2022 13:54
util/helper.go Outdated
}
}
if len(missingFiles) != 0 {
return errors.New("Missing files " + strings.Join(missingFiles, ",") + " files")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing file name should be chart.yml or chart.yaml and not chart

util/helper.go Outdated
".image_descriptor_template.json": true,
"chart": true,
}
missingFilesMap[".image_descriptor_template.json"] = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is redundant

@snehith57624 snehith57624 changed the title Multi charts feat: Multi charts Mar 29, 2022
@pghildiyal pghildiyal merged commit c0e913c into main Mar 29, 2022
@pghildiyal pghildiyal deleted the multi-charts branch March 29, 2022 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating Multi chart API for users to add directly

5 participants