Skip to content
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

Support the validation for cluster.yaml #636

Merged
merged 10 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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
74 changes: 74 additions & 0 deletions k8s-deploy/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,77 @@ const docTemplate = `{
}
}
},
"/valueTemplateExample/{chartName}/{chartVersion}": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"Chart"
],
"summary": "return valueTemplateExample string by chart name and version",
"parameters": [
{
"type": "string",
"description": "chart name",
"name": "chartName",
"in": "path",
"required": true
},
{
"type": "string",
"description": "chart version",
"name": "chartVersion",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Authentication header",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"allOf": [
{
"$ref": "#/definitions/api.JSONResult"
},
{
"type": "object",
"properties": {
"data": {
"type": "string"
}
}
}
]
}
},
"401": {
"description": "Unauthorized operation",
"schema": {
"$ref": "#/definitions/api.JSONERRORResult"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/api.JSONERRORResult"
}
}
}
}
},
"/version": {
"get": {
"security": [
Expand Down Expand Up @@ -1883,6 +1954,9 @@ const docTemplate = `{
"values_template": {
"type": "string"
},
"values_template_example": {
"type": "string"
},
"version": {
"type": "string"
}
Expand Down
74 changes: 74 additions & 0 deletions k8s-deploy/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,77 @@
}
}
},
"/valueTemplateExample/{chartName}/{chartVersion}": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"Chart"
],
"summary": "return valueTemplateExample string by chart name and version",
"parameters": [
{
"type": "string",
"description": "chart name",
"name": "chartName",
"in": "path",
"required": true
},
{
"type": "string",
"description": "chart version",
"name": "chartVersion",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Authentication header",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"allOf": [
{
"$ref": "#/definitions/api.JSONResult"
},
{
"type": "object",
"properties": {
"data": {
"type": "string"
}
}
}
]
}
},
"401": {
"description": "Unauthorized operation",
"schema": {
"$ref": "#/definitions/api.JSONERRORResult"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/api.JSONERRORResult"
}
}
}
}
},
"/version": {
"get": {
"security": [
Expand Down Expand Up @@ -1875,6 +1946,9 @@
"values_template": {
"type": "string"
},
"values_template_example": {
"type": "string"
},
"version": {
"type": "string"
}
Expand Down
45 changes: 45 additions & 0 deletions k8s-deploy/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ definitions:
type: string
values_template:
type: string
values_template_example:
type: string
version:
type: string
type: object
Expand Down Expand Up @@ -1241,6 +1243,49 @@ paths:
summary: logout
tags:
- User
/valueTemplateExample/{chartName}/{chartVersion}:
get:
parameters:
- description: chart name
in: path
name: chartName
required: true
type: string
- description: chart version
in: path
name: chartVersion
required: true
type: string
- description: Authentication header
in: header
name: Authorization
required: true
type: string
produces:
- application/json
responses:
"200":
description: Success
schema:
allOf:
- $ref: '#/definitions/api.JSONResult'
- properties:
data:
type: string
type: object
"401":
description: Unauthorized operation
schema:
$ref: '#/definitions/api.JSONERRORResult'
"500":
description: Internal server error
schema:
$ref: '#/definitions/api.JSONERRORResult'
security:
- ApiKeyAuth: []
summary: return valueTemplateExample string by chart name and version
tags:
- Chart
/version:
get:
parameters:
Expand Down
32 changes: 32 additions & 0 deletions k8s-deploy/pkg/api/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (c *Chart) Router(r *gin.RouterGroup) {
chart.GET("/", c.getChartList)
chart.GET("/:chartId", c.getChart)
chart.DELETE("/:chartId", c.deleteChart)
chart.GET("/valueTemplateExample/:chartName/:chartVersion", c.getValueTemplateExample)
}
}

Expand All @@ -47,6 +48,37 @@ type HelmUUID struct {
HelmUUID string
}

// getValueTemplateExample return valueTemplateExample string by chart name and version
// @Summary return valueTemplateExample string by chart name and version
n063h marked this conversation as resolved.
Show resolved Hide resolved
// @Tags Chart
// @Produce json
// @Param chartName path string true "chart name"
// @Param chartVersion path string true "chart version"
// @Success 200 {object} JSONResult{data=string} "Success"
// @Failure 401 {object} JSONERRORResult "Unauthorized operation"
// @Failure 500 {object} JSONERRORResult "Internal server error"
// @Router /valueTemplateExample/{chartName}/{chartVersion} [get]
// @Param Authorization header string true "Authentication header"
// @Security ApiKeyAuth
func (*Chart) getValueTemplateExample(c *gin.Context) {
name, version := c.Param("chartName"), c.Param("chartVersion")
if name == "" || version == "" {
err := errors.New("name or version is empty")
log.Error().Err(err).Msg("request params error")
c.JSON(500, gin.H{"error": err.Error()})
return
}
helmChart, err := modules.GetFateChart(name, version)
if err != nil {
log.Error().Err(err).Msg("GetFateChart error")
c.JSON(500, gin.H{"error": err.Error()})
return
}
v := helmChart.ValuesTemplateExample
log.Debug().Interface("ValuesTemplateExample", v).Msg("getValueTemplateExample Success")
c.JSON(200, gin.H{"msg": "getChartByNameVersion Success", "data": v})
}

// createChart Upload a Chart
// @Summary Upload a Chart
// @Tags Chart
Expand Down
33 changes: 33 additions & 0 deletions k8s-deploy/pkg/cli/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
ERROR
MSG
JOB
VALUE
)

type Item interface {
Expand Down Expand Up @@ -161,6 +162,38 @@ func GetItem(i Item, UUID string) error {
return nil
}

func GetResponse(i Item, req *Request, respType int) (msg interface{}, err error) {
rep, err := Send(req)
if err != nil {
return
}

log.Debug().Int("rep.Code", rep.Code).Msg("rep.Code")

if rep.Code != 200 {
msg, err = i.getResult(ERROR)
if err != nil {
return
}
err = json.Unmarshal(rep.Body, &msg)
if err != nil {
return
}
err = i.output(msg, ERROR)
if err != nil {
return
}
return
}

msg, err = i.getResult(respType)
if err != nil {
return
}
err = json.Unmarshal(rep.Body, &msg)
return
}

func GetItemList(i Item) error {
req := &Request{
Type: "GET",
Expand Down
7 changes: 7 additions & 0 deletions k8s-deploy/pkg/cli/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ type ChartResultErr struct {
Error string
}

type ValueResult struct {
Data string
Msg string
}

func (c *Chart) getResult(Type int) (result interface{}, err error) {
switch Type {
case LIST:
Expand All @@ -62,6 +67,8 @@ func (c *Chart) getResult(Type int) (result interface{}, err error) {
result = new(ChartResultMsg)
case ERROR:
result = new(ChartResultErr)
case VALUE:
result = new(ValueResult)
default:
err = fmt.Errorf("no type %d", Type)
}
Expand Down
13 changes: 13 additions & 0 deletions k8s-deploy/pkg/cli/cluster_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"

"github.com/FederatedAI/KubeFATE/k8s-deploy/pkg/modules"
"github.com/fatih/color"
jsoniter "github.com/json-iterator/go"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -162,6 +163,18 @@ func ClusterInstallCommand() *cli.Command {
chartName = ""
}

if template, err := GetValueTemplateExample(chartName.(string), chartVersion.(string)); err != nil {
color.Yellow("Config Warning: %s", err.Error())
} else {
skippedKeys := getSkippedKeys(m)
errs := ValidateYaml(template, string(clusterConfig), skippedKeys)
for _, err := range errs {
if err != nil {
color.Yellow("Config Warning: %s", err.Error())
}
}
}

var json = jsoniter.ConfigCompatibleWithStandardLibrary
valBJ, err := json.Marshal(m)

Expand Down
Loading