mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
fix label not int
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/crossplane/oam-kubernetes-runtime/pkg/oam"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
cueJson "cuelang.org/go/pkg/encoding/json"
|
||||
"github.com/crossplane/oam-kubernetes-runtime/apis/core/v1alpha2"
|
||||
@@ -97,12 +99,16 @@ func (s Service) RenderService(tm template.Manager, name, ns, image string) (
|
||||
component.Spec.Workload.Object = u
|
||||
|
||||
// render traits
|
||||
traits := []v1alpha2.ComponentTrait{}
|
||||
for k, v := range traitKeys {
|
||||
ts, err := evalTraits(tm.LoadTemplate(k), ctxData, intifyValues(v))
|
||||
traits := make([]v1alpha2.ComponentTrait, 0)
|
||||
for traitType, traitData := range traitKeys {
|
||||
ts, err := evalTraits(tm.LoadTemplate(traitType), ctxData, intifyValues(traitData))
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("eval traits failed: %w", err)
|
||||
}
|
||||
// one capability corresponds to one trait only
|
||||
if len(ts) == 1 {
|
||||
ts[0].SetLabels(map[string]string{oam.TraitTypeLabel: traitType})
|
||||
}
|
||||
for _, t := range ts {
|
||||
traits = append(traits, v1alpha2.ComponentTrait{
|
||||
Trait: runtime.RawExtension{
|
||||
@@ -244,7 +250,6 @@ func evalTraits(raw string, ctxValues, userValues interface{}) ([]*unstructured.
|
||||
}
|
||||
return renderAllOutputs(outputField)
|
||||
}
|
||||
|
||||
u, err := renderOneOutput(appValue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
package appfile
|
||||
@@ -5,6 +5,13 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
"github.com/crossplane/oam-kubernetes-runtime/apis/core/v1alpha2"
|
||||
"github.com/oam-dev/kubevela/pkg/appfile"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
@@ -136,3 +143,45 @@ services:
|
||||
assert.Equal(t, c.ExpTraits, traits, caseName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddWorkloadTypeLabel(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
comps []*v1alpha2.Component
|
||||
services map[string]appfile.Service
|
||||
expect []*v1alpha2.Component
|
||||
}{
|
||||
"empty case": {
|
||||
comps: []*v1alpha2.Component{},
|
||||
services: map[string]appfile.Service{},
|
||||
expect: []*v1alpha2.Component{},
|
||||
},
|
||||
"add type to labels normal case": {
|
||||
comps: []*v1alpha2.Component{
|
||||
{
|
||||
ObjectMeta: v1.ObjectMeta{Name: "mycomp"},
|
||||
Spec: v1alpha2.ComponentSpec{Workload: runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{}}}},
|
||||
},
|
||||
},
|
||||
services: map[string]appfile.Service{
|
||||
"mycomp": {"type": "kubewatch"},
|
||||
},
|
||||
expect: []*v1alpha2.Component{
|
||||
{
|
||||
ObjectMeta: v1.ObjectMeta{Name: "mycomp"},
|
||||
Spec: v1alpha2.ComponentSpec{
|
||||
Workload: runtime.RawExtension{
|
||||
Object: &unstructured.Unstructured{Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": map[string]interface{}{
|
||||
"workload.oam.dev/type": "kubewatch",
|
||||
}}}}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for key, ca := range tests {
|
||||
addWorkloadTypeLabel(ca.comps, ca.services)
|
||||
assert.Equal(t, ca.expect, ca.comps, key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user