Files
kubevela/references/docgen/convert.go
T
github-actions[bot]andJianbo Sun d110e97d68 [Backport release-1.5] Chore: update description of policy/workflowstep definition (#4435)
* Chore: update description of policy definition

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
(cherry picked from commit 679ee6d8cd)

* Fix: support workflow step generation for doc

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
(cherry picked from commit 418cd20315)

* Chore: refactor package refereces/plugins to references/docgen

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
(cherry picked from commit 346c3b8f2b)

* Chore: add examples of def docs for workflow step

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
(cherry picked from commit ea5d9b9076)

* Feat: refine workflow description

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
(cherry picked from commit bdfc66c65e)

* Chore: refine the workflow step definition

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
(cherry picked from commit 249af896b3)

* Chore: update workflow step definition

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
(cherry picked from commit 3aa5569dd5)

Co-authored-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
2022-07-25 10:48:00 +08:00

77 lines
3.0 KiB
Go

/*
Copyright 2022 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package docgen
import (
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/cue/packages"
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
"github.com/oam-dev/kubevela/pkg/oam/util"
)
// ParseCapabilityFromUnstructured will convert Unstructured to Capability
func ParseCapabilityFromUnstructured(mapper discoverymapper.DiscoveryMapper, pd *packages.PackageDiscover, obj unstructured.Unstructured) (types.Capability, error) {
var err error
switch obj.GetKind() {
case "ComponentDefinition":
var cd v1beta1.ComponentDefinition
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &cd)
if err != nil {
return types.Capability{}, err
}
var workloadDefinitionRef string
if cd.Spec.Workload.Type != "" {
workloadDefinitionRef = cd.Spec.Workload.Type
} else if mapper != nil {
ref, err := util.ConvertWorkloadGVK2Definition(mapper, cd.Spec.Workload.Definition)
if err != nil {
return types.Capability{}, err
}
workloadDefinitionRef = ref.Name
}
return HandleDefinition(cd.Name, workloadDefinitionRef, cd.Annotations, cd.Labels, cd.Spec.Extension, types.TypeComponentDefinition, nil, cd.Spec.Schematic, pd)
case "TraitDefinition":
var td v1beta1.TraitDefinition
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &td)
if err != nil {
return types.Capability{}, err
}
return HandleDefinition(td.Name, td.Spec.Reference.Name, td.Annotations, td.Labels, td.Spec.Extension, types.TypeTrait, td.Spec.AppliesToWorkloads, td.Spec.Schematic, pd)
case "PolicyDefinition":
var plcd v1beta1.PolicyDefinition
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &plcd)
if err != nil {
return types.Capability{}, err
}
return HandleDefinition(plcd.Name, plcd.Spec.Reference.Name, plcd.Annotations, plcd.Labels, nil, types.TypePolicy, nil, plcd.Spec.Schematic, pd)
case "WorkflowStepDefinition":
var wfd v1beta1.WorkflowStepDefinition
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &wfd)
if err != nil {
return types.Capability{}, err
}
return HandleDefinition(wfd.Name, wfd.Spec.Reference.Name, wfd.Annotations, wfd.Labels, nil, types.TypeWorkflowStep, nil, wfd.Spec.Schematic, pd)
}
return types.Capability{}, fmt.Errorf("unknown definition Type %s", obj.GetKind())
}