mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
Fix(workflow): set the namespace to app's ns if it's not specified (#2133)
* Fix(workflow): set the namespace to app's ns if it's not specified * fix dryrun test
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
// ComponentManifest contains resources rendered from an application component.
|
||||
type ComponentManifest struct {
|
||||
Name string
|
||||
Namespace string
|
||||
RevisionName string
|
||||
RevisionHash string
|
||||
ExternalRevision string
|
||||
|
||||
@@ -277,9 +277,13 @@ func (af *Appfile) GenerateComponentManifests() ([]*types.ComponentManifest, err
|
||||
|
||||
// GenerateComponentManifest generate only one ComponentManifest
|
||||
func (af *Appfile) GenerateComponentManifest(wl *Workload) (*types.ComponentManifest, error) {
|
||||
if af.Namespace == "" {
|
||||
af.Namespace = corev1.NamespaceDefault
|
||||
}
|
||||
if wl.ConfigNotReady {
|
||||
return &types.ComponentManifest{
|
||||
Name: wl.Name,
|
||||
Namespace: af.Namespace,
|
||||
InsertConfigNotReady: true,
|
||||
}, nil
|
||||
}
|
||||
@@ -387,6 +391,7 @@ func baseGenerateComponent(pCtx process.Context, wl *Workload, appName, ns strin
|
||||
return nil, err
|
||||
}
|
||||
compManifest.Name = wl.Name
|
||||
compManifest.Namespace = ns
|
||||
// we record the external revision name in ExternalRevision field
|
||||
compManifest.ExternalRevision = wl.ExternalRevision
|
||||
|
||||
@@ -666,6 +671,7 @@ func generateComponentFromHelmModule(wl *Workload, appName, revision, ns string)
|
||||
// re-use the way CUE module generates comp & acComp
|
||||
compManifest := &types.ComponentManifest{
|
||||
Name: wl.Name,
|
||||
Namespace: ns,
|
||||
ExternalRevision: wl.ExternalRevision,
|
||||
}
|
||||
if wl.FullTemplate.Reference.Type != types.AutoDetectWorkloadDefinition {
|
||||
|
||||
@@ -103,12 +103,21 @@ func SprintComponentManifest(cm *types.ComponentManifest) string {
|
||||
if cm.StandardWorkload.GetName() == "" {
|
||||
cm.StandardWorkload.SetName(cm.Name)
|
||||
}
|
||||
if cm.StandardWorkload.GetNamespace() == "" {
|
||||
cm.StandardWorkload.SetNamespace(cm.Namespace)
|
||||
}
|
||||
cl := map[string]interface{}{
|
||||
ManifestKeyWorkload: string(util.MustJSONMarshal(cm.StandardWorkload)),
|
||||
}
|
||||
|
||||
trs := []string{}
|
||||
for _, tr := range cm.Traits {
|
||||
if tr.GetName() == "" {
|
||||
tr.SetName(cm.Name)
|
||||
}
|
||||
if tr.GetNamespace() == "" {
|
||||
tr.SetNamespace(cm.Namespace)
|
||||
}
|
||||
trs = append(trs, string(util.MustJSONMarshal(tr)))
|
||||
}
|
||||
cl[ManifestKeyTraits] = trs
|
||||
|
||||
@@ -357,5 +357,5 @@ spec:
|
||||
}
|
||||
`
|
||||
|
||||
testConfigMapComponentValue = `{"test-component":"{\"Scopes\":[],\"StandardWorkload\":\"{\\\"apiVersion\\\":\\\"apps/v1\\\",\\\"kind\\\":\\\"Deployment\\\",\\\"metadata\\\":{\\\"annotations\\\":{},\\\"labels\\\":{\\\"app.oam.dev/appRevision\\\":\\\"test-wf-policy-v1\\\",\\\"app.oam.dev/component\\\":\\\"test-component\\\",\\\"app.oam.dev/name\\\":\\\"test-wf-policy\\\",\\\"workload.oam.dev/type\\\":\\\"worker\\\"},\\\"name\\\":\\\"test-component\\\"},\\\"spec\\\":{\\\"selector\\\":{\\\"matchLabels\\\":{\\\"app.oam.dev/component\\\":\\\"test-component\\\"}},\\\"template\\\":{\\\"metadata\\\":{\\\"labels\\\":{\\\"app.oam.dev/component\\\":\\\"test-component\\\"}},\\\"spec\\\":{\\\"containers\\\":[{\\\"command\\\":[\\\"sleep\\\",\\\"1000\\\"],\\\"image\\\":\\\"busybox\\\",\\\"name\\\":\\\"test-component\\\"}]}}}}\",\"Traits\":[]}"}`
|
||||
testConfigMapComponentValue = `{"test-component":"{\"Scopes\":[],\"StandardWorkload\":\"{\\\"apiVersion\\\":\\\"apps/v1\\\",\\\"kind\\\":\\\"Deployment\\\",\\\"metadata\\\":{\\\"annotations\\\":{},\\\"labels\\\":{\\\"app.oam.dev/appRevision\\\":\\\"test-wf-policy-v1\\\",\\\"app.oam.dev/component\\\":\\\"test-component\\\",\\\"app.oam.dev/name\\\":\\\"test-wf-policy\\\",\\\"workload.oam.dev/type\\\":\\\"worker\\\"},\\\"name\\\":\\\"test-component\\\",\\\"namespace\\\":\\\"test-ns\\\"},\\\"spec\\\":{\\\"selector\\\":{\\\"matchLabels\\\":{\\\"app.oam.dev/component\\\":\\\"test-component\\\"}},\\\"template\\\":{\\\"metadata\\\":{\\\"labels\\\":{\\\"app.oam.dev/component\\\":\\\"test-component\\\"}},\\\"spec\\\":{\\\"containers\\\":[{\\\"command\\\":[\\\"sleep\\\",\\\"1000\\\"],\\\"image\\\":\\\"busybox\\\",\\\"name\\\":\\\"test-component\\\"}]}}}}\",\"Traits\":[]}"}`
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
ExternalRevision: ""
|
||||
InsertConfigNotReady: false
|
||||
Name: myweb
|
||||
Namespace: default
|
||||
PackagedTraitResources: null
|
||||
PackagedWorkloadResources: null
|
||||
RevisionHash: ""
|
||||
|
||||
Reference in New Issue
Block a user