mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
@@ -34,25 +34,6 @@ jobs:
|
||||
with:
|
||||
version: "v0.7.0"
|
||||
|
||||
# TODO(zzxwill) This step and the follow one need to be removed after rudr admin:init is ready
|
||||
- name: Install OAM runtime and prepare WorkloadDefinitions/TraitDefinitions
|
||||
run: |
|
||||
sudo apt-get install -y apt-transport-https gnupg2
|
||||
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
|
||||
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
|
||||
sudo apt-get install -y kubectl
|
||||
|
||||
curl https://helm.baltorepo.com/organization/signing.asc | sudo apt-key add -
|
||||
sudo apt-get install apt-transport-https --yes
|
||||
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
|
||||
sudo apt-get update
|
||||
sudo apt-get install helm
|
||||
kubectl create namespace oam-system
|
||||
helm repo add crossplane-master https://charts.crossplane.io/master/
|
||||
helm install oam --namespace oam-system crossplane-master/oam-kubernetes-runtime --devel
|
||||
|
||||
kubectl apply -R -f config/samples
|
||||
|
||||
- name: Run e2e tests
|
||||
run: |
|
||||
make e2e-setup
|
||||
|
||||
@@ -44,8 +44,8 @@ Available Commands:
|
||||
deployment:run <appname> [args] Run deployment workloads
|
||||
|
||||
Traits:
|
||||
manualscaler <appname> [args] Attach manualscaler trait to an app
|
||||
manualscaler:detach <appname> Detach manualscaler trait from an app
|
||||
scale <appname> [args] Attach manualscaler trait to an app
|
||||
scale:detach <appname> Detach manualscaler trait from an app
|
||||
rollout <appname> [args] Attach rollout trait to an app
|
||||
rollout:detach <appname> Detach rollout trait from an app
|
||||
route <appname> [args] Attach route trait to an app
|
||||
@@ -171,4 +171,21 @@ $ source <(vela completion zsh)
|
||||
|
||||
To load completions for every new session, execute once:
|
||||
$ vela completion zsh > "${fpath[1]}/_vela"
|
||||
```
|
||||
|
||||
### Clean your environment
|
||||
|
||||
```shell script
|
||||
$ helm uninstall core-runtime -n oam-system
|
||||
release "core-runtime" uninstalled
|
||||
```
|
||||
|
||||
```shell script
|
||||
$ kubectl delete crd workloaddefinitions.core.oam.dev traitdefinitions.core.oam.dev
|
||||
customresourcedefinition.apiextensions.k8s.io "workloaddefinitions.core.oam.dev" deleted
|
||||
customresourcedefinition.apiextensions.k8s.io "traitdefinitions.core.oam.dev" deleted
|
||||
```
|
||||
|
||||
```shell script
|
||||
$ rm -r ~/.vela
|
||||
```
|
||||
+2
-2
@@ -76,7 +76,7 @@ func newCommand() *cobra.Command {
|
||||
cmd.Println("Flags:")
|
||||
cmd.Println(" -h, --help help for vela")
|
||||
cmd.Println()
|
||||
cmd.Println(`Want more? Use "vela [command] --help" for more information about a command.`)
|
||||
cmd.Println(`Use "vela [command] --help" for more information about a command.`)
|
||||
},
|
||||
SilenceUsage: true,
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
@@ -162,7 +162,7 @@ func PrintHelpByTag(cmd *cobra.Command, all []*cobra.Command, tag string) {
|
||||
if len(table.Rows) > 0 {
|
||||
cmd.Println()
|
||||
}
|
||||
cmd.Println(" <use 'vela refresh' to sync from cluster or install by `vela cap` >")
|
||||
cmd.Println(" Want more? < install more capabilities by `vela cap` >")
|
||||
}
|
||||
cmd.Println()
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ spec:
|
||||
apiVersion: "core.oam.dev/v1alpha2"
|
||||
kind: "ManualScalerTrait"
|
||||
spec: {
|
||||
replicaCount: manualscaler.replica
|
||||
replicaCount: scale.replica
|
||||
}
|
||||
}
|
||||
manualscaler: {
|
||||
scale: {
|
||||
//+short=r
|
||||
replica: *2 | int
|
||||
}
|
||||
|
||||
@@ -15,22 +15,35 @@ spec:
|
||||
kind: "Deployment"
|
||||
metadata: name: deployment.name
|
||||
spec: {
|
||||
containers: [{
|
||||
image: deployment.image
|
||||
name: deployment.name
|
||||
env: deployment.env
|
||||
ports: [{
|
||||
containerPort: deployment.port
|
||||
protocol: "TCP"
|
||||
name: "default"
|
||||
selector:
|
||||
matchLabels:
|
||||
app: deployment.name
|
||||
template: {
|
||||
metadata:
|
||||
labels:
|
||||
app: deployment.name
|
||||
spec: containers: [{
|
||||
image: deployment.image
|
||||
name: deployment.name
|
||||
env: deployment.env
|
||||
ports: [{
|
||||
containerPort: deployment.port
|
||||
protocol: "TCP"
|
||||
name: "default"
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deployment: {
|
||||
name: string
|
||||
name: string
|
||||
// +usage=specify app image
|
||||
// +short=i
|
||||
image: string
|
||||
port: *8080 | int
|
||||
// +usage=specify port for container
|
||||
// +short=p
|
||||
port: *8080 | int
|
||||
env: [...{
|
||||
name: string
|
||||
value: string
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
var (
|
||||
envName = "env-application"
|
||||
applicationName = "app-basic"
|
||||
traitAlias = "manualscaler"
|
||||
traitAlias = "scale"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("Application", func() {
|
||||
|
||||
+1
-2
@@ -45,6 +45,5 @@ func Exec(cli string) (string, error) {
|
||||
func BeforeSuit() {
|
||||
_, err := GetCliBinary()
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
//Exec("vela system:init")
|
||||
Exec("vela refresh")
|
||||
Exec("vela system:init")
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ var (
|
||||
RefreshContext = func(context string) bool {
|
||||
return ginkgo.Context(context, func() {
|
||||
ginkgo.It("Sync commands from your Kubernetes cluster and locally cached them", func() {
|
||||
output, err := Exec("vela refresh")
|
||||
output, err := Exec("vela system:update")
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("syncing workload definitions from cluster..."))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("successfully synced"))
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
var (
|
||||
envName = "env-trait"
|
||||
applicationName = "app-trait-basic"
|
||||
traitAlias = "manualscaler"
|
||||
traitAlias = "scale"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("Trait", func() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("example test", func () {
|
||||
var _ = Describe("example test", func() {
|
||||
|
||||
It("Test get environment", func() {
|
||||
w := httptest.NewRecorder()
|
||||
@@ -20,4 +20,4 @@ var _ = Describe("example test", func () {
|
||||
// TODO: unmarshall the body and check
|
||||
fmt.Println(w.Body.String())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -145,18 +145,18 @@ func (app *Application) GetComponents() []string {
|
||||
return components
|
||||
}
|
||||
|
||||
func (app *Application) GetWorkload(componentName string) (string, map[string]interface{}, error) {
|
||||
func (app *Application) GetWorkload(componentName string) (string, map[string]interface{}) {
|
||||
comp, ok := app.Components[componentName]
|
||||
if !ok {
|
||||
return "", nil, fmt.Errorf("%s not exist", componentName)
|
||||
return "", make(map[string]interface{})
|
||||
}
|
||||
for tp, workload := range comp {
|
||||
if NotWorkload(tp) {
|
||||
continue
|
||||
}
|
||||
return tp, workload.(map[string]interface{}), nil
|
||||
return tp, workload.(map[string]interface{})
|
||||
}
|
||||
return "", nil, fmt.Errorf("workload not exist in %s", componentName)
|
||||
return "", make(map[string]interface{})
|
||||
}
|
||||
|
||||
func (app *Application) GetTraits(componentName string) (map[string]map[string]interface{}, error) {
|
||||
@@ -196,9 +196,9 @@ func (app *Application) GetTraitsByType(componentName, traitType string) (map[st
|
||||
}
|
||||
|
||||
func (app *Application) GetWorkloadObject(componentName string) (*unstructured.Unstructured, error) {
|
||||
workloadType, workloadData, err := app.GetWorkload(componentName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
workloadType, workloadData := app.GetWorkload(componentName)
|
||||
if workloadType == "" {
|
||||
return nil, errors.New(componentName + " workload not exist")
|
||||
}
|
||||
return EvalToObject(workloadType, workloadData)
|
||||
}
|
||||
|
||||
@@ -151,8 +151,7 @@ components:
|
||||
}
|
||||
assert.Equal(t, c.ExpName, app.Name, caseName)
|
||||
assert.Equal(t, c.ExpComponents, app.GetComponents(), caseName)
|
||||
workloadType, workload, err := app.GetWorkload(c.WantWorkload)
|
||||
assert.NoError(t, err, caseName)
|
||||
workloadType, workload := app.GetWorkload(c.WantWorkload)
|
||||
assert.Equal(t, c.ExpWorklaod, workload, caseName)
|
||||
assert.Equal(t, c.ExpWorkloadType, workloadType, caseName)
|
||||
traits, err := app.GetTraits(c.WantWorkload)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/cloud-native-application/rudrx/pkg/builtin/traitdefinition"
|
||||
"github.com/cloud-native-application/rudrx/pkg/builtin/workloaddefinition"
|
||||
)
|
||||
|
||||
func TestValidYaml(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"scale": traitdefinition.ManualScaler,
|
||||
"rollout": traitdefinition.SimpleRollout,
|
||||
"containerized": workloaddefinition.ContainerizedWorkload,
|
||||
"deployment": workloaddefinition.Deployment,
|
||||
}
|
||||
for name, val := range cases {
|
||||
data := unstructured.Unstructured{}
|
||||
assert.NoError(t, yaml.Unmarshal([]byte(val), &data), name)
|
||||
}
|
||||
}
|
||||
@@ -2,27 +2,29 @@ package traitdefinition
|
||||
|
||||
var ManualScaler = `apiVersion: core.oam.dev/v1alpha2
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
metadata:
|
||||
annotations:
|
||||
oam.appengine.info/apiVersion: core.oam.dev/v1alpha2
|
||||
oam.appengine.info/kind: ManualScalerTrait
|
||||
name: manualscalertraits.core.oam.dev
|
||||
annotations:
|
||||
oam.appengine.info/apiVersion: "core.oam.dev/v1alpha2"
|
||||
oam.appengine.info/kind: "ManualScalerTrait"
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- core.oam.dev/v1alpha2.ContainerizedWorkload
|
||||
definitionRef:
|
||||
- apps/v1.Deployment
|
||||
definitionRef:
|
||||
name: manualscalertraits.core.oam.dev
|
||||
extension:
|
||||
template: |
|
||||
#Template: {
|
||||
apiVersion: "core.oam.dev/v1alpha2"
|
||||
kind: "ManualScalerTrait"
|
||||
spec: {
|
||||
replicaCount: manualscaler.replica
|
||||
}
|
||||
}
|
||||
manualscaler: {
|
||||
//+short=r
|
||||
replica: *2 | int
|
||||
}
|
||||
extension:
|
||||
template: |-
|
||||
#Template: {
|
||||
apiVersion: "core.oam.dev/v1alpha2"
|
||||
kind: "ManualScalerTrait"
|
||||
spec: {
|
||||
replicaCount: scale.replica
|
||||
}
|
||||
}
|
||||
scale: {
|
||||
//+short=r
|
||||
replica: *2 | int
|
||||
}
|
||||
workloadRefPath: spec.workloadRef
|
||||
`
|
||||
|
||||
@@ -17,22 +17,35 @@ spec:
|
||||
kind: "Deployment"
|
||||
metadata: name: deployment.name
|
||||
spec: {
|
||||
containers: [{
|
||||
image: deployment.image
|
||||
name: deployment.name
|
||||
env: deployment.env
|
||||
ports: [{
|
||||
containerPort: deployment.port
|
||||
protocol: "TCP"
|
||||
name: "default"
|
||||
selector:
|
||||
matchLabels:
|
||||
app: deployment.name
|
||||
template: {
|
||||
metadata:
|
||||
labels:
|
||||
app: deployment.name
|
||||
spec: containers: [{
|
||||
image: deployment.image
|
||||
name: deployment.name
|
||||
env: deployment.env
|
||||
ports: [{
|
||||
containerPort: deployment.port
|
||||
protocol: "TCP"
|
||||
name: "default"
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deployment: {
|
||||
name: string
|
||||
name: string
|
||||
// +usage=specify app image
|
||||
// +short=i
|
||||
image: string
|
||||
port: *8080 | int
|
||||
// +usage=specify port for container
|
||||
// +short=p
|
||||
port: *8080 | int
|
||||
env: [...{
|
||||
name: string
|
||||
value: string
|
||||
|
||||
@@ -372,7 +372,7 @@ func InstallCapability(client client.Client, centerName, capabilityName string,
|
||||
}
|
||||
|
||||
func InstallHelmChart(ioStreams cmdutil.IOStreams, c types.Chart) error {
|
||||
return HelmInstall(ioStreams, c.Repo, c.URl, c.Name, c.Version, c.Name)
|
||||
return HelmInstall(ioStreams, c.Repo, c.URl, c.Name, c.Version, c.Name, nil)
|
||||
}
|
||||
|
||||
func GetSyncedCapabilities(repoName, addonName string) (types.Capability, error) {
|
||||
|
||||
+2
-2
@@ -14,11 +14,11 @@ import (
|
||||
func NewRefreshCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
ctx := context.Background()
|
||||
cmd := &cobra.Command{
|
||||
Use: "refresh",
|
||||
Use: "system:update",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: "Sync definition from cluster",
|
||||
Long: "Refresh and sync definition files from cluster",
|
||||
Example: `vela refresh`,
|
||||
Example: `vela system:update`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
|
||||
if err != nil {
|
||||
|
||||
+14
-5
@@ -148,7 +148,7 @@ func NewAdminInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Comma
|
||||
}
|
||||
|
||||
func (i *initCmd) run(ioStreams cmdutil.IOStreams) error {
|
||||
ioStreams.Info("- Install OAM Kubernetes Runtime:")
|
||||
ioStreams.Info("- Installing OAM Kubernetes Runtime:")
|
||||
if !cmdutil.IsNamespaceExist(i.client, types.DefaultOAMNS) {
|
||||
if err := cmdutil.NewNamespace(i.client, types.DefaultOAMNS); err != nil {
|
||||
return err
|
||||
@@ -163,10 +163,15 @@ func (i *initCmd) run(ioStreams cmdutil.IOStreams) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ioStreams.Info("- Apply builtin capabilities:")
|
||||
ioStreams.Info("- Installing builtin capabilities:")
|
||||
if err := GenNativeResourceDefinition(i.client); err != nil {
|
||||
return err
|
||||
}
|
||||
ioStreams.Info()
|
||||
if err := RefreshDefinitions(context.Background(), i.client, ioStreams); err != nil {
|
||||
return err
|
||||
}
|
||||
ioStreams.Info("- Finished.")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -194,10 +199,10 @@ func IsHelmReleaseRunning(releaseName, chartName string, streams cmdutil.IOStrea
|
||||
}
|
||||
|
||||
func InstallOamRuntime(ioStreams cmdutil.IOStreams, version string) error {
|
||||
return HelmInstall(ioStreams, types.DefaultOAMRepoName, types.DefaultOAMRepoUrl, types.DefaultOAMRuntimeChartName, version, types.DefaultOAMReleaseName)
|
||||
return HelmInstall(ioStreams, types.DefaultOAMRepoName, types.DefaultOAMRepoUrl, types.DefaultOAMRuntimeChartName, version, types.DefaultOAMReleaseName, nil)
|
||||
}
|
||||
|
||||
func HelmInstall(ioStreams cmdutil.IOStreams, repoName, repoUrl, chartName, version, releaseName string) error {
|
||||
func HelmInstall(ioStreams cmdutil.IOStreams, repoName, repoUrl, chartName, version, releaseName string, vals map[string]interface{}) error {
|
||||
if !IsHelmRepositoryExist(repoName, repoUrl) {
|
||||
err := AddHelmRepository(repoName, repoUrl,
|
||||
"", "", "", "", "", false, ioStreams.Out)
|
||||
@@ -217,7 +222,7 @@ func HelmInstall(ioStreams cmdutil.IOStreams, repoName, repoUrl, chartName, vers
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
release, err := chartClient.Run(chartRequested, nil)
|
||||
release, err := chartClient.Run(chartRequested, vals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -254,6 +259,9 @@ func NewHelmInstall(version, releaseName string, ioStreams cmdutil.IOStreams) (*
|
||||
|
||||
client := action.NewInstall(actionConfig)
|
||||
client.ReleaseName = releaseName
|
||||
// MUST set here, client didn't use namespace from configuration
|
||||
client.Namespace = types.DefaultOAMNS
|
||||
|
||||
if len(version) > 0 {
|
||||
client.Version = version
|
||||
} else {
|
||||
@@ -405,6 +413,7 @@ func GenNativeResourceDefinition(c client.Client) error {
|
||||
for name, manifest := range traitResource {
|
||||
traitDefinition, err := NewTraitDefinition(manifest)
|
||||
if err != nil {
|
||||
fmt.Printf("creating local definition %s err %v", name, err)
|
||||
continue
|
||||
}
|
||||
err = c.Get(context.Background(), client.ObjectKey{Name: name}, &traitDefinition)
|
||||
|
||||
@@ -104,11 +104,10 @@ func (o *runOptions) Complete(cmd *cobra.Command, args []string, ctx context.Con
|
||||
if app.Components == nil {
|
||||
app.Components = make(map[string]map[string]interface{})
|
||||
}
|
||||
tp, workloadData, err := app.GetWorkload(o.workloadName)
|
||||
if err != nil {
|
||||
tp, workloadData := app.GetWorkload(o.workloadName)
|
||||
if tp == "" {
|
||||
// Not exist
|
||||
tp = o.Template.Name
|
||||
workloadData = make(map[string]interface{})
|
||||
}
|
||||
|
||||
for _, v := range o.Template.Parameters {
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestEval(t *testing.T) {
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, `{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"myapp"},"spec":{"containers":[{"name":"myapp","env":[{"name":"MYDB","value":"true"}],"image":"nginx:v1","ports":[{"name":"default","containerPort":8080,"protocol":"TCP"}]}]}}`,
|
||||
assert.Equal(t, `{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"myapp"},"spec":{"selector":{"matchLabels":{"app":"myapp"}},"template":{"metadata":{"labels":{"app":"myapp"}},"spec":{"containers":[{"name":"myapp","env":[{"name":"MYDB","value":"true"}],"image":"nginx:v1","ports":[{"name":"default","containerPort":8080,"protocol":"TCP"}]}]}}}}`,
|
||||
data)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,10 +2,10 @@
|
||||
apiVersion: "core.oam.dev/v1alpha2"
|
||||
kind: "ManualScalerTrait"
|
||||
spec: {
|
||||
replicaCount: manualscaler.replica
|
||||
replicaCount: scale.replica
|
||||
}
|
||||
}
|
||||
manualscaler: {
|
||||
scale: {
|
||||
//+short=r
|
||||
replica: *2 | int
|
||||
}
|
||||
|
||||
+17
-9
@@ -3,16 +3,24 @@
|
||||
kind: "Deployment"
|
||||
metadata: name: deployment.name
|
||||
spec: {
|
||||
containers: [{
|
||||
image: deployment.image
|
||||
name: deployment.name
|
||||
env: deployment.env
|
||||
ports: [{
|
||||
containerPort: deployment.port
|
||||
protocol: "TCP"
|
||||
name: "default"
|
||||
selector:
|
||||
matchLabels:
|
||||
app: deployment.name
|
||||
template: {
|
||||
metadata:
|
||||
labels:
|
||||
app: deployment.name
|
||||
spec: containers: [{
|
||||
image: deployment.image
|
||||
name: deployment.name
|
||||
env: deployment.env
|
||||
ports: [{
|
||||
containerPort: deployment.port
|
||||
protocol: "TCP"
|
||||
name: "default"
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user