mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-28 16:50:29 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17ac119f9b | ||
|
|
829b813b1a | ||
|
|
bce8bfd40f | ||
|
|
66855265c8 | ||
|
|
63f52ea556 | ||
|
|
fa37bf0284 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -46,6 +46,3 @@ dashboard/package-lock.json
|
||||
dashboard/src/.umi/
|
||||
package-lock.json
|
||||
dashboard/src/.umi-production/
|
||||
|
||||
# build
|
||||
charts/vela
|
||||
|
||||
@@ -98,7 +98,6 @@ func newCommand() *cobra.Command {
|
||||
|
||||
// Getting Start
|
||||
NewVersionCommand(),
|
||||
commands.NewInitCommand(commandArgs, ioStream),
|
||||
|
||||
// Apps
|
||||
commands.NewAppsCommand(commandArgs, ioStream),
|
||||
|
||||
@@ -46,9 +46,7 @@ var (
|
||||
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("sync"))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("successfully"))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("remove"))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("successfully synced"))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@@ -4,7 +4,6 @@ go 1.13
|
||||
|
||||
require (
|
||||
cuelang.org/go v0.2.2
|
||||
github.com/AlecAivazis/survey/v2 v2.1.1
|
||||
github.com/Azure/go-autorest v12.2.0+incompatible // Don't remove. https://github.com/kubernetes/client-go/issues/628
|
||||
github.com/coreos/prometheus-operator v0.41.1
|
||||
github.com/crossplane/crossplane-runtime v0.9.0
|
||||
|
||||
12
go.sum
12
go.sum
@@ -36,9 +36,6 @@ contrib.go.opencensus.io/exporter/ocagent v0.6.0/go.mod h1:zmKjrJcdo0aYcVS7bmEeS
|
||||
cuelang.org/go v0.2.2 h1:i/wFo48WDibGHKQTRZ08nB8PqmGpVpQ2sRflZPj73nQ=
|
||||
cuelang.org/go v0.2.2/go.mod h1:Dyjk8Y/B3CfFT1jQKJU0g5PpCeMiDe0yMOhk57oXwqo=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/AlecAivazis/survey v1.8.8 h1:Y4yypp763E8cbqb5RBqZhGgkCFLRFnbRBHrxnpMMsgQ=
|
||||
github.com/AlecAivazis/survey/v2 v2.1.1 h1:LEMbHE0pLj75faaVEKClEX1TM4AJmmnOh9eimREzLWI=
|
||||
github.com/AlecAivazis/survey/v2 v2.1.1/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk=
|
||||
github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737/go.mod h1:w1KSuh2JgIL3nyRiZijboSUwbbxOrTzWwyWVFUHtXBQ=
|
||||
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
|
||||
github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc=
|
||||
@@ -122,7 +119,6 @@ github.com/Microsoft/hcsshim v0.8.7 h1:ptnOoufxGSzauVTsdE+wMYnCWA301PdoN4xg5oRdZ
|
||||
github.com/Microsoft/hcsshim v0.8.7/go.mod h1:OHd7sQqRFrYd3RmSgbgji+ctCwkbq2wbEYNSzOYtcBQ=
|
||||
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
|
||||
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
|
||||
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/OneOfOne/xxhash v1.2.6/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
|
||||
github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmUx/1V+TNhjQvM=
|
||||
@@ -785,7 +781,6 @@ github.com/hashicorp/vault/api v1.0.4/go.mod h1:gDcqh3WGcR1cpF5AJz/B1UFheUEneMoI
|
||||
github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvhkWnjtSYCaS2M=
|
||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
|
||||
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
@@ -849,8 +844,6 @@ github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E
|
||||
github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0=
|
||||
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
|
||||
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
@@ -880,7 +873,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
|
||||
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
@@ -964,8 +956,6 @@ github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4f
|
||||
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/mholt/archiver/v3 v3.3.0 h1:vWjhY8SQp5yzM9P6OJ/eZEkmi3UAbRrxCq48MxjAzig=
|
||||
github.com/mholt/archiver/v3 v3.3.0/go.mod h1:YnQtqsp+94Rwd0D/rk5cnLrxusUBUXg+08Ebtr1Mqao=
|
||||
github.com/miekg/dns v0.0.0-20170721150254-0f3adef2e220/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
@@ -1306,7 +1296,6 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
@@ -1589,7 +1578,6 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/openservicemesh/osm/pkg/cli"
|
||||
)
|
||||
@@ -15,102 +11,10 @@ import (
|
||||
func main() {
|
||||
// Path relative to the Makefile where this is invoked.
|
||||
chartPath := filepath.Join("charts", "vela-core")
|
||||
tempChartPath, err := fixOpenAPIV3SchemaValidationIssue(chartPath)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "fixing OpenAPIV3SchemaValidation issue hit an error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
source, err := cli.GetChartSource(tempChartPath)
|
||||
source, err := cli.GetChartSource(chartPath)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "error getting chart source:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Print(source)
|
||||
// Delete the temporary Chart path
|
||||
os.RemoveAll(tempChartPath)
|
||||
}
|
||||
|
||||
// fixOpenAPIV3SchemaValidationIssue temporarily corrects spec.validation.openAPIV3Schema issue, and it would be removed
|
||||
// after this issue was fixed https://github.com/oam-dev/kubevela/issues/284.
|
||||
func fixOpenAPIV3SchemaValidationIssue(chartPath string) (string, error) {
|
||||
newDir, err := ioutil.TempDir(".", "charts")
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to crate temporary directory:", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
err = filepath.Walk(chartPath, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to list the content of", path)
|
||||
return err
|
||||
}
|
||||
targetPath := filepath.Join(newDir, path)
|
||||
if info.IsDir() {
|
||||
if err = os.MkdirAll(targetPath, os.ModePerm); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to make dir for", targetPath)
|
||||
}
|
||||
} else {
|
||||
targetFile, err := os.Create(filepath.Join(newDir, path))
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to open file:", path)
|
||||
return err
|
||||
}
|
||||
defer targetFile.Close()
|
||||
|
||||
if strings.Contains(path, filepath.Join(chartPath, "crds")) && info.Name() == "standard.oam.dev_containerizeds.yaml" {
|
||||
f, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to open file", path)
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
r := bufio.NewReader(f)
|
||||
var previousLine string
|
||||
if previousLine, err = r.ReadString('\n'); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to read file line:", err)
|
||||
return err
|
||||
}
|
||||
fmt.Fprint(targetFile, previousLine)
|
||||
|
||||
for {
|
||||
line, err := r.ReadString('\n')
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "failed to read file line:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.Contains(previousLine, "protocol:") &&
|
||||
strings.Contains(line, "description: Protocol for port. Must be UDP, TCP,") {
|
||||
tmp := strings.Split(line, "description")
|
||||
if len(tmp) > 0 {
|
||||
blanks := tmp[0]
|
||||
defaultStr := blanks + "default: TCP\n"
|
||||
fmt.Fprint(targetFile, defaultStr)
|
||||
}
|
||||
}
|
||||
fmt.Fprint(targetFile, line)
|
||||
previousLine = line
|
||||
}
|
||||
} else {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to read file", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(targetPath, data, os.ModePerm); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to read file:", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(newDir, "charts", "vela-core"), nil
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func (o *runOptions) Complete(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
appName, err := flags.GetString(App)
|
||||
appGroup, err := flags.GetString(App)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func (o *runOptions) Complete(cmd *cobra.Command, args []string) error {
|
||||
if err = flags.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
app, err := oam.BaseComplete(envName, workloadName, appName, flags, workloadType)
|
||||
app, err := oam.BaseComplete(envName, workloadName, appGroup, flags, workloadType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,276 +0,0 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/oam-dev/kubevela/api/types"
|
||||
"github.com/oam-dev/kubevela/pkg/application"
|
||||
cmdutil "github.com/oam-dev/kubevela/pkg/commands/util"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
"github.com/oam-dev/kubevela/pkg/plugins"
|
||||
)
|
||||
|
||||
type appInitOptions struct {
|
||||
client client.Client
|
||||
cmdutil.IOStreams
|
||||
Env *types.EnvMeta
|
||||
|
||||
app *application.Application
|
||||
appName string
|
||||
workloadName string
|
||||
workloadType string
|
||||
}
|
||||
|
||||
// NewInitCommand init application
|
||||
func NewInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
o := &appInitOptions{IOStreams: ioStreams}
|
||||
cmd := &cobra.Command{
|
||||
Use: "init",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: "Init an OAM Application",
|
||||
Long: "Init an OAM Application by one command",
|
||||
Annotations: map[string]string{
|
||||
types.TagCommandType: types.TypeStart,
|
||||
},
|
||||
Example: "vela init",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.client = newClient
|
||||
o.Env, err = GetEnv(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.IOStreams.Info("Welcome to use KubeVela CLI! We're going to help you run applications through a couple of questions.")
|
||||
o.IOStreams.Info()
|
||||
if err = o.CheckEnv(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = o.Naming(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = o.Workload(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = o.Traits(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = oam.BaseRun(false, o.app, o.client, o.Env)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.IOStreams.Info("App Deployed Succeed")
|
||||
//TODO(wonderflow) Wait for app running, and print trait info such as route, domain
|
||||
return printComponentStatus(context.Background(), o.client, o.IOStreams, o.workloadName, o.appName, o.Env)
|
||||
},
|
||||
}
|
||||
cmd.SetOut(ioStreams.Out)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *appInitOptions) Naming() error {
|
||||
prompt := &survey.Input{
|
||||
Message: "What would you like to name your application: ",
|
||||
}
|
||||
err := survey.AskOne(prompt, &o.appName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read app name err %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *appInitOptions) CheckEnv() error {
|
||||
if o.Env.Namespace == "" {
|
||||
o.Env.Namespace = "default"
|
||||
}
|
||||
o.Infof("Environment: %s, namespace: %s\n\n", o.Env.Name, o.Env.Namespace)
|
||||
if o.Env.Domain == "" {
|
||||
prompt := &survey.Input{
|
||||
Message: "Do you want to setup a domain for web service: ",
|
||||
}
|
||||
err := survey.AskOne(prompt, &o.Env.Domain)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read app name err %v", err)
|
||||
}
|
||||
}
|
||||
if o.Env.Email == "" {
|
||||
prompt := &survey.Input{
|
||||
Message: "Provide an email for production certification: ",
|
||||
}
|
||||
err := survey.AskOne(prompt, &o.Env.Email)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read app name err %v", err)
|
||||
}
|
||||
}
|
||||
if _, err := oam.CreateOrUpdateEnv(context.Background(), o.client, o.Env.Name, o.Env); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *appInitOptions) Workload() error {
|
||||
workloads, err := plugins.LoadInstalledCapabilityWithType(types.TypeWorkload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var workloadList []string
|
||||
for _, w := range workloads {
|
||||
workloadList = append(workloadList, w.Name)
|
||||
}
|
||||
prompt := &survey.Select{
|
||||
Message: "Choose an workload for your component: ",
|
||||
Options: workloadList,
|
||||
}
|
||||
err = survey.AskOne(prompt, &o.workloadType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read workload type err %v", err)
|
||||
}
|
||||
workload, err := GetCapabilityByName(o.workloadType, workloads)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
namePrompt := &survey.Input{
|
||||
Message: fmt.Sprintf("What would you name this %s: ", o.workloadType),
|
||||
}
|
||||
err = survey.AskOne(namePrompt, &o.workloadName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read name err %v", err)
|
||||
}
|
||||
fs := pflag.NewFlagSet("workload", pflag.ContinueOnError)
|
||||
for _, p := range workload.Parameters {
|
||||
if p.Name == "name" {
|
||||
continue
|
||||
}
|
||||
usage := p.Usage
|
||||
if usage == "" {
|
||||
usage = "what would you configure for parameter '" + color.New(color.FgCyan).Sprintf("%s", p.Name) + "'"
|
||||
}
|
||||
switch p.Type {
|
||||
case cue.StringKind:
|
||||
var data string
|
||||
prompt := &survey.Input{
|
||||
Message: usage,
|
||||
}
|
||||
var opts []survey.AskOpt
|
||||
if p.Required {
|
||||
opts = append(opts, survey.WithValidator(survey.Required))
|
||||
}
|
||||
err = survey.AskOne(prompt, &data, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read param %s err %v", p.Name, err)
|
||||
}
|
||||
fs.String(p.Name, data, p.Usage)
|
||||
case cue.NumberKind, cue.FloatKind:
|
||||
var data string
|
||||
prompt := &survey.Input{
|
||||
Message: usage,
|
||||
}
|
||||
var opts []survey.AskOpt
|
||||
if p.Required {
|
||||
opts = append(opts, survey.WithValidator(survey.Required))
|
||||
}
|
||||
opts = append(opts, survey.WithValidator(func(ans interface{}) error {
|
||||
data := ans.(string)
|
||||
if data == "" && !p.Required {
|
||||
return nil
|
||||
}
|
||||
_, err := strconv.ParseFloat(data, 64)
|
||||
return err
|
||||
}))
|
||||
err = survey.AskOne(prompt, &data, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read param %s err %v", p.Name, err)
|
||||
}
|
||||
val, _ := strconv.ParseFloat(data, 64)
|
||||
fs.Float64(p.Name, val, p.Usage)
|
||||
case cue.IntKind:
|
||||
var data string
|
||||
prompt := &survey.Input{
|
||||
Message: usage,
|
||||
}
|
||||
var opts []survey.AskOpt
|
||||
if p.Required {
|
||||
opts = append(opts, survey.WithValidator(survey.Required))
|
||||
}
|
||||
opts = append(opts, survey.WithValidator(func(ans interface{}) error {
|
||||
data := ans.(string)
|
||||
if data == "" && !p.Required {
|
||||
return nil
|
||||
}
|
||||
_, err := strconv.ParseInt(data, 10, 64)
|
||||
return err
|
||||
}))
|
||||
err = survey.AskOne(prompt, &data, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read param %s err %v", p.Name, err)
|
||||
}
|
||||
val, _ := strconv.ParseInt(data, 10, 64)
|
||||
fs.Int64(p.Name, val, p.Usage)
|
||||
case cue.BoolKind:
|
||||
var data bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: usage,
|
||||
}
|
||||
if p.Required {
|
||||
err = survey.AskOne(prompt, &data, survey.WithValidator(survey.Required))
|
||||
} else {
|
||||
err = survey.AskOne(prompt, &data)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("read param %s err %v", p.Name, err)
|
||||
}
|
||||
fs.Bool(p.Name, data, p.Usage)
|
||||
}
|
||||
}
|
||||
o.app, err = oam.BaseComplete(o.Env.Name, o.workloadName, o.appName, fs, o.workloadType)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetCapabilityByName(name string, workloads []types.Capability) (types.Capability, error) {
|
||||
for _, v := range workloads {
|
||||
if v.Name == name {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
return types.Capability{}, fmt.Errorf("%s not found", name)
|
||||
}
|
||||
|
||||
func (o *appInitOptions) Traits() error {
|
||||
traits, err := plugins.LoadInstalledCapabilityWithType(types.TypeTrait)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch o.workloadType {
|
||||
case "webservice":
|
||||
//TODO(wonderflow) this should get from workload definition to know which trait should be suggestions
|
||||
var suggestTraits = []string{"route"}
|
||||
for _, tr := range suggestTraits {
|
||||
trait, err := GetCapabilityByName(tr, traits)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
tflags := pflag.NewFlagSet("trait", pflag.ContinueOnError)
|
||||
for _, pa := range trait.Parameters {
|
||||
types.SetFlagBy(tflags, pa)
|
||||
}
|
||||
//TODO(wonderflow): give a way to add parameter for trait
|
||||
o.app, err = oam.AddOrUpdateTrait(o.Env, o.appName, o.workloadName, tflags, trait)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -60,7 +60,6 @@ func NewCompListCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Comman
|
||||
ctx := context.Background()
|
||||
cmd := &cobra.Command{
|
||||
Use: "ls",
|
||||
Aliases: []string{"list"},
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: "List applications",
|
||||
Long: "List applications with workloads, traits, status and created time",
|
||||
|
||||
@@ -38,28 +38,22 @@ func NewRefreshCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command
|
||||
func RefreshDefinitions(ctx context.Context, c client.Client, ioStreams cmdutil.IOStreams) error {
|
||||
dir, _ := system.GetCapabilityDir()
|
||||
|
||||
syncedTemplates := []types.Capability{}
|
||||
ioStreams.Info("syncing workload definitions from cluster...")
|
||||
templates, err := plugins.GetWorkloadsFromCluster(ctx, types.DefaultOAMNS, c, dir, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
syncedTemplates = append(syncedTemplates, templates...)
|
||||
ioStreams.Infof("get %d workload definition(s) from cluster, syncing...", len(templates))
|
||||
ioStreams.Infof("get %d workload definitions from cluster, syncing...", len(templates))
|
||||
successNum := plugins.SinkTemp2Local(templates, dir)
|
||||
ioStreams.Infof("sync %d workload definition(s) successfully\n", successNum)
|
||||
ioStreams.Infof("%d workload definitions successfully synced\n", successNum)
|
||||
|
||||
ioStreams.Info("syncing trait definitions from cluster...")
|
||||
templates, err = plugins.GetTraitsFromCluster(ctx, types.DefaultOAMNS, c, dir, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
syncedTemplates = append(syncedTemplates, templates...)
|
||||
ioStreams.Infof("get %d trait definition(s) from cluster, syncing...", len(templates))
|
||||
ioStreams.Infof("get %d trait definitions from cluster, syncing...", len(templates))
|
||||
successNum = plugins.SinkTemp2Local(templates, dir)
|
||||
ioStreams.Infof("sync %d trait definition(s) successfully\n", successNum)
|
||||
|
||||
legacyNum := plugins.RemoveLegacyTemps(syncedTemplates, dir)
|
||||
ioStreams.Infof("remove %d legacy capability definition(s) successfully\n", legacyNum)
|
||||
ioStreams.Infof("%d trait definitions successfully synced\n", successNum)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -87,7 +87,8 @@ func NewAdminInfoCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
func (i *infoCmd) run(ioStreams cmdutil.IOStreams) error {
|
||||
clusterVersion, err := GetOAMReleaseVersion()
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to get cluster chartPath: %v", err)
|
||||
ioStreams.Errorf("fail to get cluster chartPath, err: %v \n", err)
|
||||
return err
|
||||
}
|
||||
ioStreams.Info("Versions:")
|
||||
ioStreams.Infof("oam-kubernetes-runtime: %s \n", clusterVersion)
|
||||
|
||||
@@ -139,41 +139,6 @@ func SinkTemp2Local(templates []types.Capability, dir string) int {
|
||||
return success
|
||||
}
|
||||
|
||||
// RemoveLegacyTemps will remove capability definitions under `dir` but not included in `retainedTemps`.
|
||||
func RemoveLegacyTemps(retainedTemps []types.Capability, dir string) int {
|
||||
success := 0
|
||||
retainedFiles := []string{}
|
||||
subDirs := []string{GetSubDir(dir, types.TypeWorkload), GetSubDir(dir, types.TypeTrait)}
|
||||
for _, tmp := range retainedTemps {
|
||||
subDir := GetSubDir(dir, tmp.Type)
|
||||
tmpFilePath := filepath.Join(subDir, tmp.Name)
|
||||
retainedFiles = append(retainedFiles, tmpFilePath)
|
||||
}
|
||||
|
||||
for _, subDir := range subDirs {
|
||||
if err := filepath.Walk(subDir, func(path string, info os.FileInfo, err error) error {
|
||||
if info == nil || info.IsDir() {
|
||||
// omit subDir or subDir not exist
|
||||
return nil
|
||||
}
|
||||
for _, retainedFile := range retainedFiles {
|
||||
if retainedFile == path {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if err := os.Remove(path); err != nil {
|
||||
fmt.Printf("remove legacy %s err: %v\n", path, err)
|
||||
return err
|
||||
}
|
||||
success++
|
||||
return nil
|
||||
}); err != nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
||||
func LoadCapabilityFromSyncedCenter(dir string) ([]types.Capability, error) {
|
||||
var tmps []types.Capability
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
deployment = types.Capability{
|
||||
func TestLocalSink(t *testing.T) {
|
||||
deployment := types.Capability{
|
||||
Name: "deployment",
|
||||
Type: types.TypeWorkload,
|
||||
Parameters: []types.Parameter{
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
statefulset = types.Capability{
|
||||
statefulset := types.Capability{
|
||||
Name: "statefulset",
|
||||
Type: types.TypeWorkload,
|
||||
Parameters: []types.Parameter{
|
||||
@@ -32,7 +32,7 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
route = types.Capability{
|
||||
route := types.Capability{
|
||||
Name: "route",
|
||||
Type: types.TypeTrait,
|
||||
Parameters: []types.Parameter{
|
||||
@@ -43,9 +43,6 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func TestLocalSink(t *testing.T) {
|
||||
|
||||
cases := map[string]struct {
|
||||
dir string
|
||||
@@ -106,43 +103,3 @@ func testInDir(t *testing.T, casename, dir string, tmps, defexp []types.Capabili
|
||||
assert.Equal(t, defexp, gotDef, casename)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLegacyTemps(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
caseName string
|
||||
newTemps []types.Capability
|
||||
rmNum int
|
||||
}{
|
||||
{
|
||||
caseName: "remove all",
|
||||
newTemps: []types.Capability{},
|
||||
rmNum: 3,
|
||||
},
|
||||
{
|
||||
caseName: "nothing removed",
|
||||
newTemps: []types.Capability{deployment, statefulset, route},
|
||||
rmNum: 0,
|
||||
},
|
||||
{
|
||||
caseName: "remove part of existings",
|
||||
newTemps: []types.Capability{statefulset, route},
|
||||
rmNum: 1,
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
runInDirRemoveLegacyTemps(t, c.caseName, c.newTemps, c.rmNum)
|
||||
}
|
||||
}
|
||||
|
||||
func runInDirRemoveLegacyTemps(t *testing.T, caseName string, newTemps []types.Capability, rmNum int) {
|
||||
dir := "vela-test-rm-temps"
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
assert.NoError(t, err, caseName)
|
||||
defer os.RemoveAll(dir)
|
||||
existingTemps := []types.Capability{deployment, statefulset, route}
|
||||
number := SinkTemp2Local(existingTemps, dir)
|
||||
assert.Equal(t, 3, number)
|
||||
resultRemoveNum := RemoveLegacyTemps(newTemps, dir)
|
||||
assert.Equal(t, rmNum, resultRemoveNum, caseName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user