mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
feat: enhance schema handling with playbook results (#2667)
- Added a new field `Result` to `SchemaTablePlaybook` to store the result of the associated playbook. - Updated the `allSchema` function to unmarshal and assign the playbook result if available. - Cleared `PlaybookPath` after processing to prevent unintended references. - Adjusted the `SchemaTable` struct to include `PlaybookPath` for better schema management. Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
parent
2b8ea3eb46
commit
6b9636d144
|
|
@ -74,23 +74,26 @@ type InventoryHostGroups struct {
|
|||
// It includes fields such as name, type, title, description, version, namespace, logo, priority, and associated playbooks.
|
||||
// The Playbook field is a slice of SchemaTablePlaybook, each representing a playbook reference.
|
||||
type SchemaTable struct {
|
||||
Name string `json:"name"` // Name of schema, defined by filename
|
||||
SchemaType string `json:"schemaType"` // Type of the schema (e.g., CRD, built-in)
|
||||
Title string `json:"title"` // Title of the schema
|
||||
Description string `json:"description"` // Description of the schema
|
||||
Version string `json:"version"` // Version of the schema
|
||||
Namespace string `json:"namespace"` // Namespace of the schema
|
||||
Logo string `json:"logo"` // Logo URL or identifier
|
||||
Priority int `json:"priority"` // Priority for display or ordering
|
||||
Playbook SchemaTablePlaybook `json:"playbook"` // List of reference playbooks
|
||||
Name string `json:"name"` // Name of schema, defined by filename
|
||||
SchemaType string `json:"schemaType"` // Type of the schema (e.g., CRD, built-in)
|
||||
Title string `json:"title"` // Title of the schema
|
||||
Description string `json:"description"` // Description of the schema
|
||||
Version string `json:"version"` // Version of the schema
|
||||
Namespace string `json:"namespace"` // Namespace of the schema
|
||||
Logo string `json:"logo"` // Logo URL or identifier
|
||||
Priority int `json:"priority"` // Priority for display or ordering
|
||||
Playbook SchemaTablePlaybook `json:"playbook"` // List of reference playbooks
|
||||
PlaybookPath map[string]string `json:"playbookPath,omitempty"` // PlaybookPath for current schema
|
||||
}
|
||||
|
||||
// SchemaTablePlaybook represents a reference to a playbook associated with a schema.
|
||||
// It includes the playbook's name, namespace, and phase.
|
||||
type SchemaTablePlaybook struct {
|
||||
Path string `json:"path"` // Path of playbook template.
|
||||
Name string `json:"name"` // Name of the playbook
|
||||
Namespace string `json:"namespace"` // Namespace of the playbook
|
||||
Phase string `json:"phase"` // Phase of the playbook
|
||||
Result any `json:"result"` // Result of the playbook
|
||||
}
|
||||
|
||||
// IPTable represents an IP address entry and its SSH status information.
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func NewSchemaService(rootPath string, workdir string, client ctrlclient.Client)
|
|||
Doc("list all schema as table").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{_const.ResourceTag}).
|
||||
Param(ws.QueryParameter("schemaType", "the type of schema json").Required(false)).
|
||||
Param(ws.QueryParameter("playbookLabel", "the reference playbook of schema. eg: \"install.kubekey.kubesphere.io/schema\", \"check.kubekey.kubesphere.io/schema\" \\n"+
|
||||
Param(ws.QueryParameter("playbookLabel", "the reference playbook of schema. eg: \"install.kubekey.kubesphere.io/schema\", \"check.kubekey.kubesphere.io/schema\" "+
|
||||
"if empty will not return any reference playbook").Required(false)).
|
||||
Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d")).
|
||||
Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)).
|
||||
|
|
@ -232,10 +232,19 @@ func (h schemaHandler) allSchema(request *restful.Request, response *restful.Res
|
|||
case 0: // skip
|
||||
case 1:
|
||||
item := &playbookList.Items[0]
|
||||
var result any
|
||||
if len(item.Status.Result.Raw) != 0 {
|
||||
if err := json.Unmarshal(item.Status.Result.Raw, &result); err != nil {
|
||||
api.HandleBadRequest(response, request, errors.Errorf("failed to unmarshal result from playbook of schema %q", schema.Name))
|
||||
return
|
||||
}
|
||||
}
|
||||
schema.Playbook = api.SchemaTablePlaybook{
|
||||
Path: schema.PlaybookPath[playbookLabel],
|
||||
Name: item.Name,
|
||||
Namespace: item.Namespace,
|
||||
Phase: string(item.Status.Phase),
|
||||
Result: result,
|
||||
}
|
||||
default:
|
||||
playbookNames := make([]string, 0, len(playbookList.Items))
|
||||
|
|
@ -246,6 +255,8 @@ func (h schemaHandler) allSchema(request *restful.Request, response *restful.Res
|
|||
return
|
||||
}
|
||||
}
|
||||
// clear PlaybookPath
|
||||
schema.PlaybookPath = nil
|
||||
schemaTable = append(schemaTable, schema)
|
||||
}
|
||||
// less is a comparison function for sorting SchemaTable items by a given field.
|
||||
|
|
|
|||
Loading…
Reference in New Issue