Skip to content

Commit fb3adce

Browse files
committed
align with kubevela-v1.10.4 from commit a8b652e59da9a3349ccb0e9d455c04c8d88e0868
1 parent acee58f commit fb3adce

File tree

90 files changed

+1562
-6392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1562
-6392
lines changed

apis/core.oam.dev/common/types.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ type Status struct {
135135
// HealthPolicy defines the health check policy for the abstraction
136136
// +optional
137137
HealthPolicy string `json:"healthPolicy,omitempty"`
138+
// Details stores a string representation of a CUE status map to be evaluated at runtime for display
139+
// +optional
140+
Details string `json:"details,omitempty"`
138141
}
139142

140143
// ApplicationPhase is a label for the condition of an application at the current time
@@ -172,6 +175,7 @@ type ApplicationComponentStatus struct {
172175
// WorkloadDefinition is the definition of a WorkloadDefinition, such as deployments/apps.v1
173176
WorkloadDefinition WorkloadGVK `json:"workloadDefinition,omitempty"`
174177
Healthy bool `json:"healthy"`
178+
Details map[string]string `json:"details,omitempty"`
175179
Message string `json:"message,omitempty"`
176180
Traits []ApplicationTraitStatus `json:"traits,omitempty"`
177181
Scopes []corev1.ObjectReference `json:"scopes,omitempty"`
@@ -185,9 +189,10 @@ func (in ApplicationComponentStatus) Equal(r ApplicationComponentStatus) bool {
185189

186190
// ApplicationTraitStatus records the trait health status
187191
type ApplicationTraitStatus struct {
188-
Type string `json:"type"`
189-
Healthy bool `json:"healthy"`
190-
Message string `json:"message,omitempty"`
192+
Type string `json:"type"`
193+
Healthy bool `json:"healthy"`
194+
Details map[string]string `json:"details,omitempty"`
195+
Message string `json:"message,omitempty"`
191196
}
192197

193198
// Revision has name and revision number

apis/core.oam.dev/common/zz_generated.deepcopy.go

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/core.oam.dev/v1alpha1/register.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ func init() {
6060
SchemeBuilder.Register(&workflowv1alpha1.Workflow{}, &workflowv1alpha1.WorkflowList{})
6161
_ = SchemeBuilder.AddToScheme(k8sscheme.Scheme)
6262
}
63+
64+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
65+
func Resource(resource string) schema.GroupResource {
66+
return SchemeGroupVersion.WithResource(resource).GroupResource()
67+
}

apis/core.oam.dev/v1beta1/register.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
ComponentDefinitionGroupKind = schema.GroupKind{Group: Group, Kind: ComponentDefinitionKind}.String()
5050
ComponentDefinitionKindAPIVersion = ComponentDefinitionKind + "." + SchemeGroupVersion.String()
5151
ComponentDefinitionGroupVersionKind = SchemeGroupVersion.WithKind(ComponentDefinitionKind)
52+
ComponentDefinitionGVR = SchemeGroupVersion.WithResource("componentdefinitions")
5253
)
5354

5455
// WorkloadDefinition type metadata.
@@ -65,6 +66,7 @@ var (
6566
TraitDefinitionGroupKind = schema.GroupKind{Group: Group, Kind: TraitDefinitionKind}.String()
6667
TraitDefinitionKindAPIVersion = TraitDefinitionKind + "." + SchemeGroupVersion.String()
6768
TraitDefinitionGroupVersionKind = SchemeGroupVersion.WithKind(TraitDefinitionKind)
69+
TraitDefinitionGVR = SchemeGroupVersion.WithResource("traitdefinitions")
6870
)
6971

7072
// PolicyDefinition type metadata.
@@ -73,6 +75,7 @@ var (
7375
PolicyDefinitionGroupKind = schema.GroupKind{Group: Group, Kind: PolicyDefinitionKind}.String()
7476
PolicyDefinitionKindAPIVersion = PolicyDefinitionKind + "." + SchemeGroupVersion.String()
7577
PolicyDefinitionGroupVersionKind = SchemeGroupVersion.WithKind(PolicyDefinitionKind)
78+
PolicyDefinitionGVR = SchemeGroupVersion.WithResource("policydefinitions")
7679
)
7780

7881
// WorkflowStepDefinition type metadata.
@@ -81,6 +84,7 @@ var (
8184
WorkflowStepDefinitionGroupKind = schema.GroupKind{Group: Group, Kind: WorkflowStepDefinitionKind}.String()
8285
WorkflowStepDefinitionKindAPIVersion = WorkflowStepDefinitionKind + "." + SchemeGroupVersion.String()
8386
WorkflowStepDefinitionGroupVersionKind = SchemeGroupVersion.WithKind(WorkflowStepDefinitionKind)
87+
WorkflowStepDefinitionGVR = SchemeGroupVersion.WithResource("workflowstepdefinitions")
8488
)
8589

8690
// DefinitionRevision type metadata.
@@ -115,6 +119,20 @@ var (
115119
ResourceTrackerKindVersionKind = SchemeGroupVersion.WithKind(ResourceTrackerKind)
116120
)
117121

122+
// DefinitionTypeInfo contains the mapping information for a definition type
123+
type DefinitionTypeInfo struct {
124+
GVR schema.GroupVersionResource
125+
Kind string
126+
}
127+
128+
// DefinitionTypeMap maps definition types to their corresponding GVR and Kind
129+
var DefinitionTypeMap = map[reflect.Type]DefinitionTypeInfo{
130+
reflect.TypeOf(ComponentDefinition{}): {GVR: ComponentDefinitionGVR, Kind: ComponentDefinitionKind},
131+
reflect.TypeOf(TraitDefinition{}): {GVR: TraitDefinitionGVR, Kind: TraitDefinitionKind},
132+
reflect.TypeOf(PolicyDefinition{}): {GVR: PolicyDefinitionGVR, Kind: PolicyDefinitionKind},
133+
reflect.TypeOf(WorkflowStepDefinition{}): {GVR: WorkflowStepDefinitionGVR, Kind: WorkflowStepDefinitionKind},
134+
}
135+
118136
func init() {
119137
SchemeBuilder.Register(&ComponentDefinition{}, &ComponentDefinitionList{})
120138
SchemeBuilder.Register(&WorkloadDefinition{}, &WorkloadDefinitionList{})
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
Copyright 2025 The KubeVela Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"reflect"
21+
"strings"
22+
"testing"
23+
24+
"github.com/stretchr/testify/assert"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
26+
)
27+
28+
func TestDefinitionTypeMap(t *testing.T) {
29+
tests := []struct {
30+
name string
31+
defType reflect.Type
32+
expectedGVR schema.GroupVersionResource
33+
expectedKind string
34+
}{
35+
{
36+
name: "ComponentDefinition",
37+
defType: reflect.TypeOf(ComponentDefinition{}),
38+
expectedGVR: ComponentDefinitionGVR,
39+
expectedKind: ComponentDefinitionKind,
40+
},
41+
{
42+
name: "TraitDefinition",
43+
defType: reflect.TypeOf(TraitDefinition{}),
44+
expectedGVR: TraitDefinitionGVR,
45+
expectedKind: TraitDefinitionKind,
46+
},
47+
{
48+
name: "PolicyDefinition",
49+
defType: reflect.TypeOf(PolicyDefinition{}),
50+
expectedGVR: PolicyDefinitionGVR,
51+
expectedKind: PolicyDefinitionKind,
52+
},
53+
{
54+
name: "WorkflowStepDefinition",
55+
defType: reflect.TypeOf(WorkflowStepDefinition{}),
56+
expectedGVR: WorkflowStepDefinitionGVR,
57+
expectedKind: WorkflowStepDefinitionKind,
58+
},
59+
}
60+
61+
for _, tt := range tests {
62+
t.Run(tt.name, func(t *testing.T) {
63+
info, ok := DefinitionTypeMap[tt.defType]
64+
assert.Truef(t, ok, "Type %v should exist in DefinitionTypeMap", tt.defType)
65+
assert.Equal(t, tt.expectedGVR, info.GVR)
66+
assert.Equal(t, tt.expectedKind, info.Kind)
67+
68+
// Verify GVR follows Kubernetes conventions
69+
assert.Equal(t, Group, info.GVR.Group)
70+
assert.Equal(t, Version, info.GVR.Version)
71+
// Resource should be lowercase plural of Kind
72+
assert.Equal(t, strings.ToLower(info.Kind)+"s", info.GVR.Resource)
73+
})
74+
}
75+
}
76+
77+
func TestDefinitionTypeMapCompleteness(t *testing.T) {
78+
// Ensure all expected definition types are in the map
79+
expectedTypes := []reflect.Type{
80+
reflect.TypeOf(ComponentDefinition{}),
81+
reflect.TypeOf(TraitDefinition{}),
82+
reflect.TypeOf(PolicyDefinition{}),
83+
reflect.TypeOf(WorkflowStepDefinition{}),
84+
}
85+
86+
assert.Equal(t, len(expectedTypes), len(DefinitionTypeMap), "DefinitionTypeMap should contain exactly %d entries", len(expectedTypes))
87+
88+
for _, expectedType := range expectedTypes {
89+
_, ok := DefinitionTypeMap[expectedType]
90+
assert.Truef(t, ok, "DefinitionTypeMap should contain %v", expectedType)
91+
}
92+
}
93+
94+
func TestDefinitionKindValues(t *testing.T) {
95+
// Verify that the Kind values match the actual type names
96+
tests := []struct {
97+
defType interface{}
98+
expectedKind string
99+
}{
100+
{ComponentDefinition{}, "ComponentDefinition"},
101+
{TraitDefinition{}, "TraitDefinition"},
102+
{PolicyDefinition{}, "PolicyDefinition"},
103+
{WorkflowStepDefinition{}, "WorkflowStepDefinition"},
104+
}
105+
106+
for _, tt := range tests {
107+
t.Run(tt.expectedKind, func(t *testing.T) {
108+
actualKind := reflect.TypeOf(tt.defType).Name()
109+
assert.Equal(t, tt.expectedKind, actualKind)
110+
111+
// Also verify it matches what's in the map
112+
info, ok := DefinitionTypeMap[reflect.TypeOf(tt.defType)]
113+
assert.True(t, ok)
114+
assert.Equal(t, tt.expectedKind, info.Kind)
115+
})
116+
}
117+
}

apis/core.oam.dev/v1beta1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ require (
2222
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
2323
sigs.k8s.io/controller-runtime v0.19.7
2424
sigs.k8s.io/controller-tools v0.16.5
25-
sigs.k8s.io/structured-merge-diff/v4 v4.6.0
2625
sigs.k8s.io/yaml v1.4.0
2726
)
2827

@@ -136,6 +135,7 @@ require (
136135
sigs.k8s.io/apiserver-runtime v1.1.2-0.20250117204231-9282f514a674 // indirect
137136
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
138137
sigs.k8s.io/randfill v1.0.0 // indirect
138+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
139139
)
140140

141141
replace sigs.k8s.io/apiserver-network-proxy/konnectivity-client => sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.36

0 commit comments

Comments
 (0)