mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
Fix: do not override the workload name if its specified (#2336)
* Fix: do not override the workload name if its specified * Fix: resolve comments
This commit is contained in:
@@ -350,9 +350,11 @@ func (af *Appfile) setNamespace(obj *unstructured.Unstructured) {
|
||||
}
|
||||
|
||||
func (af *Appfile) assembleWorkload(wl *unstructured.Unstructured, compName string, labels map[string]string) {
|
||||
// use component name as workload name
|
||||
// override the name set in render phase if exist
|
||||
wl.SetName(compName)
|
||||
// use component name as workload name if workload name is not specified
|
||||
// don't override the name set in render phase if exist
|
||||
if len(wl.GetName()) == 0 {
|
||||
wl.SetName(compName)
|
||||
}
|
||||
af.setNamespace(wl)
|
||||
af.setWorkloadLabels(wl, labels)
|
||||
af.filterAndSetAnnotations(wl)
|
||||
|
||||
@@ -47,8 +47,9 @@ import (
|
||||
|
||||
var _ = Describe("Test Helm schematic appfile", func() {
|
||||
var (
|
||||
appName = "test-app"
|
||||
compName = "test-comp"
|
||||
appName = "test-app"
|
||||
compName = "test-comp"
|
||||
workloadName = "test-workload"
|
||||
)
|
||||
|
||||
It("Test generate AppConfig resources from Helm schematic", func() {
|
||||
@@ -63,7 +64,7 @@ var _ = Describe("Test Helm schematic appfile", func() {
|
||||
},
|
||||
Workloads: []*Workload{
|
||||
{
|
||||
Name: compName,
|
||||
Name: workloadName,
|
||||
Type: "webapp-chart",
|
||||
CapabilityCategory: oamtypes.HelmCategory,
|
||||
Params: map[string]interface{}{
|
||||
@@ -123,7 +124,7 @@ var _ = Describe("Test Helm schematic appfile", func() {
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
expectCompManifest := &oamtypes.ComponentManifest{
|
||||
Name: compName,
|
||||
Name: workloadName,
|
||||
StandardWorkload: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
@@ -240,7 +241,6 @@ spec:
|
||||
},
|
||||
Workloads: []*Workload{
|
||||
{
|
||||
Name: compName,
|
||||
Type: "kube-worker",
|
||||
CapabilityCategory: oamtypes.KubeCategory,
|
||||
Params: map[string]interface{}{
|
||||
|
||||
@@ -292,9 +292,11 @@ func (am *AppManifests) validate() error {
|
||||
|
||||
func assembleWorkload(compName string, wl *unstructured.Unstructured,
|
||||
labels map[string]string, resources []*unstructured.Unstructured, appRev *v1beta1.ApplicationRevision, wop []WorkloadOption) (*unstructured.Unstructured, error) {
|
||||
// use component name as workload name
|
||||
// override the name set in render phase if exist
|
||||
wl.SetName(compName)
|
||||
// use component name as workload name if workload name is not specified
|
||||
// don't override the name set in render phase if exist
|
||||
if len(wl.GetName()) == 0 {
|
||||
wl.SetName(compName)
|
||||
}
|
||||
setWorkloadLabels(wl, labels)
|
||||
|
||||
workloadType := wl.GetLabels()[oam.WorkloadTypeLabel]
|
||||
|
||||
@@ -147,7 +147,8 @@ var _ = Describe("Test Assemble Options", func() {
|
||||
|
||||
It("test annotation and label filter", func() {
|
||||
var (
|
||||
compName = "frontend"
|
||||
compName = "frontend"
|
||||
workloadName = "test-workload"
|
||||
)
|
||||
appRev := &v1beta1.ApplicationRevision{}
|
||||
b, err := os.ReadFile("./testdata/filter_annotations.yaml")
|
||||
@@ -197,5 +198,8 @@ var _ = Describe("Test Assemble Options", func() {
|
||||
annotationKeys := getKeys(wl.GetAnnotations())
|
||||
Expect(annotationKeys).ShouldNot(ContainElements("notPassAnno1", "notPassAnno2"))
|
||||
Expect(annotationKeys).Should(ContainElements("canPassAnno"))
|
||||
|
||||
By("Verify workload metadata (name)")
|
||||
Expect(wl.GetName()).Should(Equal(workloadName))
|
||||
})
|
||||
})
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user