convert v1alpha2 to v1beta1 (#1289)

This commit is contained in:
yangsoon
2021-03-25 10:55:54 +08:00
committed by GitHub
parent 53ae9aaa40
commit 33dae5e36e
27 changed files with 183 additions and 79 deletions
-1
View File
@@ -4,7 +4,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
corev1alpha2 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/types"
)
+5 -5
View File
@@ -22,8 +22,8 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
corev1alpha2 "github.com/oam-dev/kubevela/apis/core.oam.dev"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
coreoam "github.com/oam-dev/kubevela/apis/core.oam.dev"
corev1beta1 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/oam/util"
"github.com/oam-dev/kubevela/pkg/utils/system"
// +kubebuilder:scaffold:imports
@@ -34,7 +34,7 @@ var scheme *runtime.Scheme
var k8sClient client.Client
var testEnv *envtest.Environment
var definitionDir string
var wd v1alpha2.WorkloadDefinition
var wd corev1beta1.WorkloadDefinition
var addonNamespace = "test-addon"
func TestAppFile(t *testing.T) {
@@ -59,7 +59,7 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).ToNot(HaveOccurred())
Expect(cfg).ToNot(BeNil())
scheme = runtime.NewScheme()
Expect(corev1alpha2.AddToScheme(scheme)).NotTo(HaveOccurred())
Expect(coreoam.AddToScheme(scheme)).NotTo(HaveOccurred())
Expect(clientgoscheme.AddToScheme(scheme)).NotTo(HaveOccurred())
Expect(v1beta1.AddToScheme(scheme)).NotTo(HaveOccurred())
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
@@ -83,7 +83,7 @@ var _ = BeforeSuite(func(done Done) {
def, err := ioutil.ReadFile("testdata/terraform-aliyun-oss-workloadDefinition.yaml")
Expect(err).Should(BeNil())
var terraformDefinition v1alpha2.WorkloadDefinition
var terraformDefinition corev1beta1.WorkloadDefinition
Expect(yaml.Unmarshal(def, &terraformDefinition)).Should(BeNil())
terraformDefinition.Namespace = addonNamespace
logf.Log.Info("Creating workload definition", "data", terraformDefinition)
+1 -1
View File
@@ -168,7 +168,7 @@ func (app *AppFile) BuildOAMApplication(env *types.EnvMeta, io cmdutil.IOStreams
}
servApp.Spec.Components = append(servApp.Spec.Components, comp)
}
servApp.SetGroupVersionKind(v1alpha2.SchemeGroupVersion.WithKind("Application"))
servApp.SetGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("Application"))
auxiliaryObjects = append(auxiliaryObjects, addDefaultHealthScopeToApplication(servApp))
return servApp, auxiliaryObjects, nil
}
+2 -2
View File
@@ -53,7 +53,7 @@ func TestBuildOAMApplication2(t *testing.T) {
expectApp: &v1beta1.Application{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
APIVersion: "core.oam.dev/v1alpha2",
APIVersion: "core.oam.dev/v1beta1",
}, ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
@@ -87,7 +87,7 @@ func TestBuildOAMApplication2(t *testing.T) {
expectApp: &v1beta1.Application{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
APIVersion: "core.oam.dev/v1alpha2",
APIVersion: "core.oam.dev/v1beta1",
}, ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
+8 -7
View File
@@ -11,6 +11,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/utils/common"
"github.com/oam-dev/kubevela/references/appfile/api"
@@ -55,12 +56,12 @@ func Validate(app *api.Application) error {
}
// LoadApplication will load application from cluster.
func LoadApplication(namespace, appName string, c common.Args) (*v1alpha2.Application, error) {
func LoadApplication(namespace, appName string, c common.Args) (*v1beta1.Application, error) {
newClient, err := c.GetClient()
if err != nil {
return nil, err
}
app := &v1alpha2.Application{}
app := &v1beta1.Application{}
if err := newClient.Get(context.TODO(), client.ObjectKey{Namespace: namespace, Name: appName}, app); err != nil {
return nil, err
}
@@ -78,7 +79,7 @@ func Save(app *api.Application, envName string) error {
}
// GetComponents will get oam components from Appfile.
func GetComponents(app *v1alpha2.Application) []string {
func GetComponents(app *v1beta1.Application) []string {
var components []string
for _, cmp := range app.Spec.Components {
components = append(components, cmp.Name)
@@ -97,12 +98,12 @@ func GetServiceConfig(app *api.Application, componentName string) (string, map[s
}
// GetApplicationSettings will get service type and it's configuration
func GetApplicationSettings(app *v1alpha2.Application, componentName string) (string, map[string]interface{}) {
func GetApplicationSettings(app *v1beta1.Application, componentName string) (string, map[string]interface{}) {
for _, comp := range app.Spec.Components {
if comp.Name == componentName {
data := map[string]interface{}{}
_ = json.Unmarshal(comp.Settings.Raw, &data)
return comp.WorkloadType, data
_ = json.Unmarshal(comp.Properties.Raw, &data)
return comp.Type, data
}
}
return "", make(map[string]interface{})
@@ -142,7 +143,7 @@ func GetTraits(app *api.Application, componentName string) (map[string]map[strin
}
// GetAppConfig will get AppConfig from K8s cluster.
func GetAppConfig(ctx context.Context, c client.Client, app *v1alpha2.Application, env *types.EnvMeta) (*v1alpha2.ApplicationConfiguration, error) {
func GetAppConfig(ctx context.Context, c client.Client, app *v1beta1.Application, env *types.EnvMeta) (*v1alpha2.ApplicationConfiguration, error) {
appConfig := &v1alpha2.ApplicationConfiguration{}
if err := c.Get(ctx, client.ObjectKey{Namespace: env.Namespace, Name: app.Name}, appConfig); err != nil {
return nil, err
+6 -6
View File
@@ -7,7 +7,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/references/appfile/api"
)
@@ -32,7 +32,7 @@ func SetWorkload(app *api.Application, componentName, workloadType string, workl
}
// SetTrait will set user trait for Appfile
func SetTrait(app *v1alpha2.Application, componentName, traitType string, traitData map[string]interface{}) error {
func SetTrait(app *v1beta1.Application, componentName, traitType string, traitData map[string]interface{}) error {
if app == nil {
return errorAppNilPointer
}
@@ -51,14 +51,14 @@ func SetTrait(app *v1alpha2.Application, componentName, traitType string, traitD
foundComp = true
var added bool
for j, tr := range app.Spec.Components[idx].Traits {
if tr.Name != traitType {
if tr.Type != traitType {
continue
}
added = true
app.Spec.Components[idx].Traits[j].Properties.Raw = data
}
if !added {
app.Spec.Components[idx].Traits = append(app.Spec.Components[idx].Traits, v1alpha2.ApplicationTrait{Name: traitType, Properties: runtime.RawExtension{Raw: data}})
app.Spec.Components[idx].Traits = append(app.Spec.Components[idx].Traits, v1beta1.ApplicationTrait{Type: traitType, Properties: runtime.RawExtension{Raw: data}})
}
}
if !foundComp {
@@ -82,11 +82,11 @@ func RemoveTrait(app *api.Application, componentName, traitType string) error {
}
// RemoveComponent will remove component from Application
func RemoveComponent(app *v1alpha2.Application, componentName string) error {
func RemoveComponent(app *v1beta1.Application, componentName string) error {
if app == nil {
return errorAppNilPointer
}
var newComps []v1alpha2.ApplicationComponent
var newComps []v1beta1.ApplicationComponent
for _, comp := range app.Spec.Components {
if comp.Name == componentName {
continue
+1 -2
View File
@@ -9,7 +9,6 @@ import (
ctypes "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/oam"
)
@@ -55,7 +54,7 @@ func CreateOrUpdateObjects(ctx context.Context, client client.Client, objects []
// CreateOrUpdateApplication will create if not exist and update if exists.
func CreateOrUpdateApplication(ctx context.Context, client client.Client, app *v1beta1.Application) error {
var geta v1alpha2.Application
var geta v1beta1.Application
key := ctypes.NamespacedName{Name: app.Name, Namespace: app.Namespace}
var exist = true
if err := client.Get(ctx, key, &geta); err != nil {
@@ -1,4 +1,4 @@
apiVersion: core.oam.dev/v1alpha2
apiVersion: core.oam.dev/v1beta1
kind: WorkloadDefinition
metadata:
name: aliyun-oss
+1 -1
View File
@@ -1,4 +1,4 @@
apiVersion: core.oam.dev/v1alpha2
apiVersion: core.oam.dev/v1beta1
kind: WorkloadDefinition
metadata:
name: deployments.testapps
+1
View File
@@ -74,6 +74,7 @@ func NewCommand() *cobra.Command {
CapabilityCommandGroup(commandArgs, ioStream),
NewTemplateCommand(ioStream),
NewTraitsCommand(commandArgs, ioStream),
NewComponentsCommand(commandArgs, ioStream),
NewWorkloadsCommand(commandArgs, ioStream),
// Helper
+71
View File
@@ -0,0 +1,71 @@
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/oam-dev/kubevela/apis/types"
oamutil "github.com/oam-dev/kubevela/pkg/oam/util"
common2 "github.com/oam-dev/kubevela/pkg/utils/common"
cmdutil "github.com/oam-dev/kubevela/pkg/utils/util"
"github.com/oam-dev/kubevela/references/common"
"github.com/oam-dev/kubevela/references/plugins"
)
// NewComponentsCommand creates `components` command
func NewComponentsCommand(c common2.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "components",
DisableFlagsInUseLine: true,
Short: "List components",
Long: "List components",
Example: `vela components`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return c.SetConfig()
},
RunE: func(cmd *cobra.Command, args []string) error {
env, err := GetEnv(cmd)
if err != nil {
return err
}
return printComponentList(env.Namespace, c, ioStreams)
},
Annotations: map[string]string{
types.TagCommandType: types.TypeCap,
},
}
cmd.SetOut(ioStreams.Out)
return cmd
}
func printComponentList(userNamespace string, c common2.Args, ioStreams cmdutil.IOStreams) error {
def, err := common.ListRawComponentDefinitions(userNamespace, c)
if err != nil {
return err
}
dm, err := c.GetDiscoveryMapper()
if err != nil {
return fmt.Errorf("get discoveryMapper error %w", err)
}
table := newUITable()
table.AddRow("NAME", "NAMESPACE", "WORKLOAD", "DESCRIPTION")
for _, r := range def {
var workload string
if r.Spec.Workload.Type != "" {
workload = r.Spec.Workload.Type
} else {
definition, err := oamutil.ConvertWorkloadGVK2Definition(dm, r.Spec.Workload.Definition)
if err != nil {
return fmt.Errorf("get workload definitionReference error %w", err)
}
workload = definition.Name
}
table.AddRow(r.Name, r.Namespace, workload, plugins.GetDescription(r.Annotations))
}
ioStreams.Info(table.String())
return nil
}
+2 -2
View File
@@ -14,7 +14,7 @@ import (
cmdexec "k8s.io/kubectl/pkg/cmd/exec"
k8scmdutil "k8s.io/kubectl/pkg/cmd/util"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/utils/common"
@@ -40,7 +40,7 @@ type VelaExecOptions struct {
context.Context
VelaC common.Args
Env *types.EnvMeta
App *v1alpha2.Application
App *v1beta1.Application
f k8scmdutil.Factory
kcExecOptions *cmdexec.ExecOptions
+2 -2
View File
@@ -15,7 +15,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/utils/common"
"github.com/oam-dev/kubevela/pkg/utils/util"
@@ -69,7 +69,7 @@ type Args struct {
Output string
Env *types.EnvMeta
C common.Args
App *v1alpha2.Application
App *v1beta1.Application
}
// Run refer to the implementation at https://github.com/oam-dev/stern/blob/master/stern/main.go
+4 -4
View File
@@ -8,7 +8,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/utils/common"
cmdutil "github.com/oam-dev/kubevela/pkg/utils/util"
@@ -56,7 +56,7 @@ func NewListCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
func printApplicationList(ctx context.Context, c client.Reader, namespace string, ioStreams cmdutil.IOStreams) error {
table := newUITable()
table.AddRow("APP", "COMPONENT", "TYPE", "TRAITS", "PHASE", "HEALTHY", "STATUS", "CREATED-TIME")
applist := v1alpha2.ApplicationList{}
applist := v1beta1.ApplicationList{}
if err := c.List(ctx, &applist, client.InNamespace(namespace)); err != nil {
if apierrors.IsNotFound(err) {
ioStreams.Info(table.String())
@@ -85,9 +85,9 @@ func printApplicationList(ctx context.Context, c client.Reader, namespace string
}
var traits []string
for _, tr := range cmp.Traits {
traits = append(traits, tr.Name)
traits = append(traits, tr.Type)
}
table.AddRow(appName, cmp.Name, cmp.WorkloadType, strings.Join(traits, ","), a.Status.Phase, healthy, status, a.CreationTimestamp)
table.AddRow(appName, cmp.Name, cmp.Type, strings.Join(traits, ","), a.Status.Phase, healthy, status, a.CreationTimestamp)
}
}
ioStreams.Info(table.String())
+2 -1
View File
@@ -23,6 +23,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/utils/common"
@@ -39,7 +40,7 @@ type VelaPortForwardOptions struct {
context.Context
VelaC common.Args
Env *types.EnvMeta
App *v1alpha2.Application
App *v1beta1.Application
f k8scmdutil.Factory
kcPortForwardOptions *cmdpf.PortForwardOptions
+6 -5
View File
@@ -14,6 +14,7 @@ import (
commontypes "github.com/oam-dev/kubevela/apis/core.oam.dev/common"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/oam/util"
"github.com/oam-dev/kubevela/pkg/utils/common"
@@ -127,8 +128,8 @@ func printAppStatus(ctx context.Context, c client.Client, ioStreams cmdutil.IOSt
return loopCheckStatus(ctx, c, ioStreams, appName, env)
}
func loadRemoteApplication(c client.Client, ns string, name string) (*v1alpha2.Application, error) {
app := new(v1alpha2.Application)
func loadRemoteApplication(c client.Client, ns string, name string) (*v1beta1.Application, error) {
app := new(v1beta1.Application)
err := c.Get(context.Background(), client.ObjectKey{
Namespace: ns,
Name: name,
@@ -150,7 +151,7 @@ func loopCheckStatus(ctx context.Context, c client.Client, ioStreams cmdutil.IOS
return err
}
ioStreams.Infof(white.Sprintf(" - Name: %s\n", compName))
ioStreams.Infof(" Type: %s\n", comp.WorkloadType)
ioStreams.Infof(" Type: %s\n", comp.Type)
healthColor := getHealthStatusColor(healthStatus)
healthInfo = strings.ReplaceAll(healthInfo, "\n", "\n\t") // format healthInfo output
@@ -175,7 +176,7 @@ func loopCheckStatus(ctx context.Context, c client.Client, ioStreams cmdutil.IOS
}
var message string
for _, v := range comp.Traits {
if v.Name == tr.Type {
if v.Type == tr.Type {
traitData, _ := util.RawExtension2Map(&v.Properties)
for k, v := range traitData {
message += fmt.Sprintf("%v=%v\n\t\t", k, v)
@@ -320,7 +321,7 @@ func trackHealthCheckingStatus(ctx context.Context, c client.Client, compName, a
return compStatusHealthCheckDone, HealthStatusNotDiagnosed, "", nil
}
func getWorkloadStatusFromApp(app *v1alpha2.Application, compName string) (commontypes.ApplicationComponentStatus, bool) {
func getWorkloadStatusFromApp(app *v1beta1.Application, compName string) (commontypes.ApplicationComponentStatus, bool) {
foundWlStatus := false
wlStatus := commontypes.ApplicationComponentStatus{}
if app == nil {
+16
View File
@@ -1,3 +1,19 @@
/*
Copyright 2021. The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cli
import (
+5 -5
View File
@@ -99,9 +99,9 @@ type DeleteOptions struct {
// ListApplications lists all applications
func ListApplications(ctx context.Context, c client.Reader, opt Option) ([]apis.ApplicationMeta, error) {
var applicationMetaList applicationMetaList
var appList corev1alpha2.ApplicationList
var appList corev1beta1.ApplicationList
if opt.AppName != "" {
var app corev1alpha2.Application
var app corev1beta1.Application
if err := c.Get(ctx, client.ObjectKey{Name: opt.AppName, Namespace: opt.Namespace}, &app); err != nil {
return applicationMetaList, err
}
@@ -180,7 +180,7 @@ func ListComponents(ctx context.Context, c client.Reader, opt Option) ([]apis.Co
func RetrieveApplicationStatusByName(ctx context.Context, c client.Reader, applicationName string,
namespace string) (apis.ApplicationMeta, error) {
var applicationMeta apis.ApplicationMeta
var app corev1alpha2.Application
var app corev1beta1.Application
if err := c.Get(ctx, client.ObjectKey{Name: applicationName, Namespace: namespace}, &app); err != nil {
return applicationMeta, err
}
@@ -197,7 +197,7 @@ func (o *DeleteOptions) DeleteApp() (string, error) {
return "", err
}
ctx := context.Background()
var app = new(corev1alpha2.Application)
var app = new(corev1beta1.Application)
err := o.Client.Get(ctx, client.ObjectKey{Name: o.AppName, Namespace: o.Env.Namespace}, app)
if err != nil {
if apierrors.IsNotFound(err) {
@@ -467,7 +467,7 @@ func (o *AppfileOptions) ApplyApp(app *corev1beta1.Application, scopes []oam.Obj
Name: app.Name,
}
o.IO.Infof("Checking if app has been deployed...\n")
var tmpApp corev1alpha2.Application
var tmpApp corev1beta1.Application
err := o.Kubecli.Get(context.TODO(), key, &tmpApp)
switch {
case apierrors.IsNotFound(err):
+5 -5
View File
@@ -20,7 +20,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
"github.com/oam-dev/kubevela/pkg/oam/util"
@@ -95,7 +95,7 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
defDir, _ := system.GetCapabilityDir()
switch tp.Type {
case types.TypeWorkload:
var wd v1alpha2.WorkloadDefinition
var wd v1beta1.WorkloadDefinition
workloadData, err := ioutil.ReadFile(filepath.Clean(filepath.Join(repoDir, tp.Name+".yaml")))
if err != nil {
return err
@@ -127,7 +127,7 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
return err
}
case types.TypeTrait:
var td v1alpha2.TraitDefinition
var td v1beta1.TraitDefinition
traitdata, err := ioutil.ReadFile(filepath.Clean(filepath.Join(repoDir, tp.Name+".yaml")))
if err != nil {
return err
@@ -294,9 +294,9 @@ func uninstallCap(client client.Client, cap types.Capability, ioStreams cmdutil.
var obj runtime.Object
switch cap.Type {
case types.TypeTrait:
obj = &v1alpha2.TraitDefinition{ObjectMeta: v1.ObjectMeta{Name: cap.Name, Namespace: types.DefaultKubeVelaNS}}
obj = &v1beta1.TraitDefinition{ObjectMeta: v1.ObjectMeta{Name: cap.Name, Namespace: types.DefaultKubeVelaNS}}
case types.TypeWorkload:
obj = &v1alpha2.WorkloadDefinition{ObjectMeta: v1.ObjectMeta{Name: cap.Name, Namespace: types.DefaultKubeVelaNS}}
obj = &v1beta1.WorkloadDefinition{ObjectMeta: v1.ObjectMeta{Name: cap.Name, Namespace: types.DefaultKubeVelaNS}}
case types.TypeScope:
return fmt.Errorf("uninstall scope capability was not supported yet")
case types.TypeComponentDefinition:
+26 -9
View File
@@ -5,15 +5,14 @@ import (
"fmt"
"strings"
"github.com/oam-dev/kubevela/pkg/utils/common"
plur "github.com/gertd/go-pluralize"
client2 "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/oam/util"
"github.com/oam-dev/kubevela/pkg/utils/common"
"github.com/oam-dev/kubevela/references/plugins"
)
@@ -33,17 +32,17 @@ func ListTraitDefinitions(userNamespace string, c common.Args, workloadName *str
}
// ListRawTraitDefinitions will list raw definition
func ListRawTraitDefinitions(userNamespace string, c common.Args) ([]v1alpha2.TraitDefinition, error) {
func ListRawTraitDefinitions(userNamespace string, c common.Args) ([]v1beta1.TraitDefinition, error) {
client, err := c.GetClient()
if err != nil {
return nil, err
}
ctx := util.SetNamespaceInCtx(context.Background(), userNamespace)
traitList := v1alpha2.TraitDefinitionList{}
traitList := v1beta1.TraitDefinitionList{}
if err = client.List(ctx, &traitList, client2.InNamespace(userNamespace)); err != nil {
return nil, err
}
sysTraitList := v1alpha2.TraitDefinitionList{}
sysTraitList := v1beta1.TraitDefinitionList{}
if err = client.List(ctx, &sysTraitList, client2.InNamespace(oam.SystemDefinitonNamespace)); err != nil {
return nil, err
}
@@ -51,23 +50,41 @@ func ListRawTraitDefinitions(userNamespace string, c common.Args) ([]v1alpha2.Tr
}
// ListRawWorkloadDefinitions will list raw definition
func ListRawWorkloadDefinitions(userNamespace string, c common.Args) ([]v1alpha2.WorkloadDefinition, error) {
func ListRawWorkloadDefinitions(userNamespace string, c common.Args) ([]v1beta1.WorkloadDefinition, error) {
client, err := c.GetClient()
if err != nil {
return nil, err
}
ctx := util.SetNamespaceInCtx(context.Background(), userNamespace)
workloadList := v1alpha2.WorkloadDefinitionList{}
workloadList := v1beta1.WorkloadDefinitionList{}
if err = client.List(ctx, &workloadList); err != nil {
return nil, err
}
sysWorkloadList := v1alpha2.WorkloadDefinitionList{}
sysWorkloadList := v1beta1.WorkloadDefinitionList{}
if err = client.List(ctx, &sysWorkloadList, client2.InNamespace(oam.SystemDefinitonNamespace)); err != nil {
return nil, err
}
return append(workloadList.Items, sysWorkloadList.Items...), nil
}
// ListRawComponentDefinitions will list raw component definition
func ListRawComponentDefinitions(userNamespace string, c common.Args) ([]v1beta1.ComponentDefinition, error) {
client, err := c.GetClient()
if err != nil {
return nil, err
}
ctx := util.SetNamespaceInCtx(context.Background(), userNamespace)
componentList := v1beta1.ComponentDefinitionList{}
if err = client.List(ctx, &componentList); err != nil {
return nil, err
}
sysComponentList := v1beta1.ComponentDefinitionList{}
if err = client.List(ctx, &sysComponentList, client2.InNamespace(oam.SystemDefinitonNamespace)); err != nil {
return nil, err
}
return append(componentList.Items, sysComponentList.Items...), nil
}
// GetTraitDefinition will get trait capability with applyTo converted
func GetTraitDefinition(userNamespace string, c common.Args, workloadName *string, traitType string) (types.Capability, error) {
var traitDef types.Capability
+3 -3
View File
@@ -17,7 +17,7 @@ import (
"golang.org/x/oauth2"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/utils/system"
)
@@ -170,14 +170,14 @@ func ParseAndSyncCapability(data []byte) (types.Capability, error) {
}
switch obj.GetKind() {
case "WorkloadDefinition":
var rd v1alpha2.WorkloadDefinition
var rd v1beta1.WorkloadDefinition
err = yaml.Unmarshal(data, &rd)
if err != nil {
return types.Capability{}, err
}
return HandleDefinition(rd.Name, rd.Spec.Reference.Name, rd.Annotations, rd.Spec.Extension, types.TypeWorkload, nil, rd.Spec.Schematic)
case "TraitDefinition":
var td v1alpha2.TraitDefinition
var td v1beta1.TraitDefinition
err = yaml.Unmarshal(data, &td)
if err != nil {
return types.Capability{}, err
+5 -5
View File
@@ -12,7 +12,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
commontypes "github.com/oam-dev/kubevela/apis/core.oam.dev/common"
corev1alpha2 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/cue"
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
@@ -51,7 +51,7 @@ func GetWorkloadsFromCluster(ctx context.Context, namespace string, c common.Arg
}
var templates []types.Capability
var workloadDefs corev1alpha2.WorkloadDefinitionList
var workloadDefs v1beta1.WorkloadDefinitionList
err = newClient.List(ctx, &workloadDefs, &client.ListOptions{Namespace: namespace, LabelSelector: selector})
if err != nil {
return nil, nil, fmt.Errorf("list WorkloadDefinition err: %w", err)
@@ -84,7 +84,7 @@ func GetTraitsFromCluster(ctx context.Context, namespace string, c common.Args,
return nil, nil, err
}
var templates []types.Capability
var traitDefs corev1alpha2.TraitDefinitionList
var traitDefs v1beta1.TraitDefinitionList
err = newClient.List(ctx, &traitDefs, &client.ListOptions{Namespace: namespace, LabelSelector: selector})
if err != nil {
return nil, nil, fmt.Errorf("list TraitDefinition err: %w", err)
@@ -233,7 +233,7 @@ func SyncDefinitionToLocal(ctx context.Context, c common.Args, localDefinitionDi
if err != nil {
return nil, err
}
var workloadDef corev1alpha2.WorkloadDefinition
var workloadDef v1beta1.WorkloadDefinition
err = newClient.Get(ctx, client.ObjectKey{Namespace: types.DefaultKubeVelaNS, Name: capabilityName}, &workloadDef)
if err == nil {
// return nil, fmt.Errorf("get WorkloadDefinition err: %w", err)
@@ -248,7 +248,7 @@ func SyncDefinitionToLocal(ctx context.Context, c common.Args, localDefinitionDi
}
foundCapability = false
var traitDef corev1alpha2.TraitDefinition
var traitDef v1beta1.TraitDefinition
err = newClient.Get(ctx, client.ObjectKey{Namespace: types.DefaultKubeVelaNS, Name: capabilityName}, &traitDef)
if err == nil {
foundCapability = true
+6 -8
View File
@@ -7,8 +7,6 @@ import (
"path/filepath"
"testing"
"github.com/oam-dev/kubevela/pkg/utils/system"
"github.com/ghodss/yaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -24,10 +22,10 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
corev1alpha2 "github.com/oam-dev/kubevela/apis/core.oam.dev"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
coreoam "github.com/oam-dev/kubevela/apis/core.oam.dev"
corev1beta1 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/oam/util"
"github.com/oam-dev/kubevela/pkg/utils/system"
// +kubebuilder:scaffold:imports
)
@@ -39,8 +37,8 @@ var scheme *runtime.Scheme
var k8sClient client.Client
var testEnv *envtest.Environment
var definitionDir string
var td v1alpha2.TraitDefinition
var wd, websvcWD v1alpha2.WorkloadDefinition
var td corev1beta1.TraitDefinition
var wd, websvcWD corev1beta1.WorkloadDefinition
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
@@ -65,7 +63,7 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).ToNot(HaveOccurred())
Expect(cfg).ToNot(BeNil())
scheme = runtime.NewScheme()
Expect(corev1alpha2.AddToScheme(scheme)).NotTo(HaveOccurred())
Expect(coreoam.AddToScheme(scheme)).NotTo(HaveOccurred())
Expect(clientgoscheme.AddToScheme(scheme)).NotTo(HaveOccurred())
Expect(v1beta1.AddToScheme(scheme)).NotTo(HaveOccurred())
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
+1 -1
View File
@@ -1,4 +1,4 @@
apiVersion: core.oam.dev/v1alpha2
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
name: ingress.test
+1 -1
View File
@@ -1,4 +1,4 @@
apiVersion: core.oam.dev/v1alpha2
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
name: scaler
+1 -1
View File
@@ -1,4 +1,4 @@
apiVersion: core.oam.dev/v1alpha2
apiVersion: core.oam.dev/v1beta1
kind: WorkloadDefinition
metadata:
name: webservice.testapps
+1 -1
View File
@@ -1,4 +1,4 @@
apiVersion: core.oam.dev/v1alpha2
apiVersion: core.oam.dev/v1beta1
kind: WorkloadDefinition
metadata:
name: deployments.testapps