github.com/oam-dev/kubevela@v1.9.11/references/common/trait.go (about) 1 /* 2 Copyright 2021 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 common 18 19 import ( 20 "context" 21 22 client2 "sigs.k8s.io/controller-runtime/pkg/client" 23 24 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" 25 "github.com/oam-dev/kubevela/pkg/oam" 26 "github.com/oam-dev/kubevela/pkg/oam/util" 27 "github.com/oam-dev/kubevela/pkg/utils/common" 28 ) 29 30 // ListRawWorkloadDefinitions will list raw definition 31 func ListRawWorkloadDefinitions(userNamespace string, c common.Args) ([]v1beta1.WorkloadDefinition, error) { 32 client, err := c.GetClient() 33 if err != nil { 34 return nil, err 35 } 36 ctx := util.SetNamespaceInCtx(context.Background(), userNamespace) 37 workloadList := v1beta1.WorkloadDefinitionList{} 38 ns := ctx.Value(util.AppDefinitionNamespace).(string) 39 if err = client.List(ctx, &workloadList, client2.InNamespace(ns)); err != nil { 40 return nil, err 41 } 42 if ns == oam.SystemDefinitionNamespace { 43 return workloadList.Items, nil 44 } 45 sysWorkloadList := v1beta1.WorkloadDefinitionList{} 46 if err = client.List(ctx, &sysWorkloadList, client2.InNamespace(oam.SystemDefinitionNamespace)); err != nil { 47 return nil, err 48 } 49 return append(workloadList.Items, sysWorkloadList.Items...), nil 50 }