fix lint issues in /pkg/commands

Signed-off-by: roy wang <seiwy2010@gmail.com>
This commit is contained in:
roy wang
2020-11-25 18:00:09 +09:00
parent aa5a11bcdd
commit ee9b44fa80
16 changed files with 92 additions and 69 deletions

View File

@@ -28,6 +28,12 @@ linters-settings:
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
ignore: fmt:.*,io/ioutil:^Read.*
exhaustive:
# indicates that switch statements are to be considered exhaustive if a
# 'default' case is present, even if all enum members aren't listed in the
# switch
default-signifies-exhaustive: true
govet:
# report about shadowed variables
check-shadowing: false

View File

@@ -16,6 +16,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
// constants used in `svc` command
const (
Staging = "staging"
App = "app"
@@ -30,6 +31,7 @@ func newRunOptions(ioStreams util.IOStreams) *runOptions {
return &runOptions{IOStreams: ioStreams}
}
// AddCompCommands creates `svc` command and its nested children command
func AddCompCommands(c types.Args, ioStreams util.IOStreams) *cobra.Command {
compCommands := &cobra.Command{
Use: "svc",
@@ -45,6 +47,7 @@ func AddCompCommands(c types.Args, ioStreams util.IOStreams) *cobra.Command {
return compCommands
}
// NewCompDeployCommands creates `deploy` command
func NewCompDeployCommands(c types.Args, ioStreams util.IOStreams) *cobra.Command {
runCmd := &cobra.Command{
Use: "deploy [args]",
@@ -89,6 +92,7 @@ func NewCompDeployCommands(c types.Args, ioStreams util.IOStreams) *cobra.Comman
return runCmd
}
// GetWorkloadNameFromArgs gets workload from the args
func GetWorkloadNameFromArgs(args []string) (string, error) {
argsLength := len(args)
if argsLength < 1 {

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -33,6 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
// NewDashboardCommand creates `dashboard` command and its nested children commands
func NewDashboardCommand(c types.Args, ioStreams cmdutil.IOStreams, frontendSource string) *cobra.Command {
var o Options
o.frontendSource = frontendSource
@@ -70,6 +69,7 @@ func NewDashboardCommand(c types.Args, ioStreams cmdutil.IOStreams, frontendSour
return cmd
}
// Options creates options for `dashboard` command
type Options struct {
logFilePath string
logRetainDate int
@@ -80,6 +80,7 @@ type Options struct {
frontendSource string
}
// GetStaticPath gets the path of front-end directory
func (o *Options) GetStaticPath() error {
if o.frontendSource == "" {
return nil
@@ -87,23 +88,23 @@ func (o *Options) GetStaticPath() error {
var err error
o.staticPath, err = system.GetDefaultFrontendDir()
if err != nil {
return fmt.Errorf("get fontend dir err %v", err)
return fmt.Errorf("get fontend dir err %w", err)
}
_ = os.RemoveAll(o.staticPath)
//nolint:gosec
err = os.MkdirAll(o.staticPath, 0755)
if err != nil {
return fmt.Errorf("create fontend dir err %v", err)
return fmt.Errorf("create fontend dir err %w", err)
}
data, err := base64.StdEncoding.DecodeString(o.frontendSource)
if err != nil {
return fmt.Errorf("decode frontendSource err %v", err)
return fmt.Errorf("decode frontendSource err %w", err)
}
tgzpath := filepath.Join(o.staticPath, "frontend.tgz")
//nolint:gosec
err = ioutil.WriteFile(tgzpath, data, 0644)
if err != nil {
return fmt.Errorf("write frontend.tgz to static path err %v", err)
return fmt.Errorf("write frontend.tgz to static path err %w", err)
}
//nolint:errcheck
defer os.Remove(tgzpath)
@@ -111,11 +112,11 @@ func (o *Options) GetStaticPath() error {
//nolint:errcheck
defer tgz.Close()
if err = tgz.Unarchive(tgzpath, o.staticPath); err != nil {
return fmt.Errorf("write static files to fontend dir err %v", err)
return fmt.Errorf("write static files to fontend dir err %w", err)
}
files, err := ioutil.ReadDir(o.staticPath)
if err != nil {
return fmt.Errorf("read static file %s err %v", o.staticPath, err)
return fmt.Errorf("read static file %s err %w", o.staticPath, err)
}
var name string
for _, fi := range files {
@@ -131,6 +132,7 @@ func (o *Options) GetStaticPath() error {
return nil
}
// SetupAPIServer starts a RESTfulAPI server
func SetupAPIServer(c types.Args, cmd *cobra.Command, o Options) error {
// setup logging
var w io.Writer
@@ -159,7 +161,7 @@ func SetupAPIServer(c types.Args, cmd *cobra.Command, o Options) error {
o.port = ":" + o.port
}
//Setup RESTful server
// Setup RESTful server
server, err := server.New(c, o.port, o.staticPath)
if err != nil {
return err
@@ -190,8 +192,8 @@ func SetupAPIServer(c types.Args, cmd *cobra.Command, o Options) error {
return server.Shutdown(ctx)
}
// nolint:gosec
// OpenBrowser will open browser by url in different OS system
// nolint:gosec
func OpenBrowser(url string) error {
var err error
switch runtime.GOOS {
@@ -207,6 +209,7 @@ func OpenBrowser(url string) error {
return err
}
// CheckVelaRuntimeInstalledAndReady checks whether vela-core runtime is installed and ready
func CheckVelaRuntimeInstalledAndReady(ioStreams cmdutil.IOStreams, c client.Client) (bool, error) {
if !helm.IsHelmReleaseRunning(types.DefaultKubeVelaReleaseName, types.DefaultKubeVelaChartName, types.DefaultKubeVelaNS, ioStreams) {
ioStreams.Info(fmt.Sprintf("\n%s %s", emojiFail, "KubeVela runtime is not installed yet."))

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -17,6 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
// NewEnvCommand creates `env` command and its nested children
func NewEnvCommand(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "env",
@@ -32,6 +31,7 @@ func NewEnvCommand(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
return cmd
}
// NewEnvListCommand creates `env list` command for listing all environments
func NewEnvListCommand(ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "ls",
@@ -51,6 +51,7 @@ func NewEnvListCommand(ioStream cmdutil.IOStreams) *cobra.Command {
return cmd
}
// NewEnvInitCommand creates `env init` command for initializing environments
func NewEnvInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
var envArgs types.EnvMeta
var syncCluster bool
@@ -85,6 +86,7 @@ func NewEnvInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command
return cmd
}
// NewEnvDeleteCommand creates `env delete` command for deleting environments
func NewEnvDeleteCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
@@ -104,6 +106,7 @@ func NewEnvDeleteCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
return cmd
}
// NewEnvSetCommand creates `env set` command for setting current environment
func NewEnvSetCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "set",
@@ -123,6 +126,7 @@ func NewEnvSetCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
return cmd
}
// ListEnvs shows info of all environments
func ListEnvs(args []string, ioStreams cmdutil.IOStreams) error {
table := uitable.New()
table.MaxColWidth = 60
@@ -142,6 +146,7 @@ func ListEnvs(args []string, ioStreams cmdutil.IOStreams) error {
return nil
}
// DeleteEnv deletes an environment
func DeleteEnv(ctx context.Context, args []string, ioStreams cmdutil.IOStreams) error {
if len(args) < 1 {
return fmt.Errorf("you must specify environment name for 'vela env delete' command")
@@ -156,6 +161,7 @@ func DeleteEnv(ctx context.Context, args []string, ioStreams cmdutil.IOStreams)
return nil
}
// CreateOrUpdateEnv creates or updates an environment
func CreateOrUpdateEnv(ctx context.Context, c client.Client, envArgs *types.EnvMeta, args []string, ioStreams cmdutil.IOStreams) error {
if len(args) < 1 {
return fmt.Errorf("you must specify environment name for 'vela env init' command")
@@ -170,6 +176,7 @@ func CreateOrUpdateEnv(ctx context.Context, c client.Client, envArgs *types.EnvM
return nil
}
// SetEnv sets current environment
func SetEnv(args []string, ioStreams cmdutil.IOStreams) error {
if len(args) < 1 {
return fmt.Errorf("you must specify environment name for vela env command")
@@ -183,6 +190,8 @@ func SetEnv(args []string, ioStreams cmdutil.IOStreams) error {
return nil
}
// GetEnv gets environment by name or current environment
// if no env exists, then init default environment
func GetEnv(cmd *cobra.Command) (*types.EnvMeta, error) {
var envName string
var err error

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -30,6 +28,7 @@ const (
defaultTTY = true
)
// VelaExecOptions creates options for `exec` command
type VelaExecOptions struct {
Cmd *cobra.Command
Args []string
@@ -46,6 +45,7 @@ type VelaExecOptions struct {
ClientSet kubernetes.Interface
}
// NewExecCommand creates `exec` command
func NewExecCommand(c types.Args, ioStreams velacmdutil.IOStreams) *cobra.Command {
o := &VelaExecOptions{
kcExecOptions: &cmdexec.ExecOptions{
@@ -98,6 +98,7 @@ func NewExecCommand(c types.Args, ioStreams velacmdutil.IOStreams) *cobra.Comman
return cmd
}
// Init prepares the arguments accepted by the Exec command
func (o *VelaExecOptions) Init(ctx context.Context, c *cobra.Command, argsIn []string) error {
o.Context = ctx
o.Cmd = c
@@ -128,6 +129,7 @@ func (o *VelaExecOptions) Init(ctx context.Context, c *cobra.Command, argsIn []s
return nil
}
// Complete loads data from the command environment
func (o *VelaExecOptions) Complete() error {
compName, err := util.AskToChooseOneService(o.App.GetComponents())
if err != nil {
@@ -151,7 +153,7 @@ func (o *VelaExecOptions) Complete() error {
func (o *VelaExecOptions) getPodName(compName string) (string, error) {
podList, err := o.ClientSet.CoreV1().Pods(o.Env.Namespace).List(o.Context, v1.ListOptions{
LabelSelector: labels.Set(map[string]string{
//TODO(roywang) except core workloads, not any workloads will pass these label to pod
// TODO(roywang) except core workloads, not any workloads will pass these label to pod
// find a rigorous way to get pod by compname
oam.LabelAppComponent: compName,
}).String(),
@@ -172,6 +174,7 @@ func (o *VelaExecOptions) getPodName(compName string) (string, error) {
return podList.Items[0].Name, nil
}
// Run executes a validated remote execution against a pod
func (o *VelaExecOptions) Run() error {
return o.kcExecOptions.Run()
}

View File

@@ -34,7 +34,7 @@ type appInitOptions struct {
renderOnly bool
}
// NewInitCommand init application
// NewInitCommand creates `init` command
func NewInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
o := &appInitOptions{IOStreams: ioStreams}
cmd := &cobra.Command{
@@ -110,6 +110,7 @@ func NewInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
return cmd
}
// Naming asks user to input app name
func (o *appInitOptions) Naming() error {
prompt := &survey.Input{
Message: "What would you like to name your application (required): ",
@@ -121,6 +122,7 @@ func (o *appInitOptions) Naming() error {
return nil
}
// CheckEnv checks environment, e.g., domain and email.
func (o *appInitOptions) CheckEnv() error {
if o.Env.Namespace == "" {
o.Env.Namespace = "default"
@@ -150,6 +152,7 @@ func (o *appInitOptions) CheckEnv() error {
return nil
}
// Workload asks user to choose workload type from installed workloads
func (o *appInitOptions) Workload() error {
workloads, err := plugins.LoadInstalledCapabilityWithType(types.TypeWorkload)
if err != nil {
@@ -292,6 +295,7 @@ func GetCapabilityByName(name string, workloads []types.Capability) (types.Capab
return types.Capability{}, fmt.Errorf("%s not found", name)
}
// Traits attaches specific trait to service
func (o *appInitOptions) Traits() error {
traits, err := plugins.LoadInstalledCapabilityWithType(types.TypeTrait)
if err != nil {

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -23,6 +21,7 @@ import (
"k8s.io/client-go/kubernetes"
)
// NewLogsCommand creates `logs` command to tail logs of application
func NewLogsCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
largs := &Args{C: c}
cmd := &cobra.Command{}
@@ -57,6 +56,7 @@ func NewLogsCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
return cmd
}
// Args creates arguments for `logs` command
type Args struct {
Output string
Env *types.EnvMeta
@@ -75,7 +75,7 @@ func (l *Args) Run(ctx context.Context, ioStreams cmdutil.IOStreams) error {
if err != nil {
return err
}
//TODO(wonderflow): we could get labels from service to narrow the pods scope selected
// TODO(wonderflow): we could get labels from service to narrow the pods scope selected
labelSelector := labels.Everything()
pod, err := regexp.Compile(compName + "-.*")
if err != nil {
@@ -137,7 +137,7 @@ func (l *Args) Run(ctx context.Context, ioStreams cmdutil.IOStreams) error {
if tails[id] != nil {
continue
}
//48h
// 48h
dur, _ := time.ParseDuration("48h")
tail := stern.NewTail(p.Namespace, p.Pod, p.Container, template, &stern.TailOptions{
Timestamps: true,
@@ -145,7 +145,7 @@ func (l *Args) Run(ctx context.Context, ioStreams cmdutil.IOStreams) error {
Exclude: nil,
Include: nil,
Namespace: false,
TailLines: nil, //default for all logs
TailLines: nil, // default for all logs
})
tails[id] = tail

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -20,6 +18,7 @@ import (
"github.com/oam-dev/kubevela/pkg/server/apis"
)
// NewListCommand creates `ls` command and its nested children command
func NewListCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
@@ -130,6 +129,7 @@ func mergeStagingComponents(deployed []apis.ComponentMeta, env *types.EnvMeta, i
return all
}
// GetCompMeta gets meta of a component
func GetCompMeta(deployed []apis.ComponentMeta, appName, compName string) (apis.ComponentMeta, bool) {
for _, v := range deployed {
if v.Name == compName && v.App == appName {

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -58,14 +56,9 @@ var (
// CompStatus represents the status of a component during "vela init"
type CompStatus int
// Enums of CompStatus
const (
// nolint
compStatusInitializing CompStatus = iota
// nolint
compStatusInitFail
// nolint
compStatusInitialized
compStatusDeploying
compStatusDeploying CompStatus = iota
compStatusDeployFail
compStatusDeployed
compStatusHealthChecking
@@ -73,6 +66,7 @@ const (
compStatusUnknown
)
// Error msg used in `status` command
const (
ErrNotLoadAppConfig = "cannot load the application"
ErrFmtNotInitialized = "service: %s not ready"
@@ -87,23 +81,18 @@ var (
)
var (
emojiSucceed = emoji.Sprint(":check_mark_button:")
emojiFail = emoji.Sprint(":cross_mark:")
// nolint
emojiTimeout = emoji.Sprint(":heavy_exclamation_mark:")
emojiSucceed = emoji.Sprint(":check_mark_button:")
emojiFail = emoji.Sprint(":cross_mark:")
emojiLightBulb = emoji.Sprint(":light_bulb:")
// nolint
emojiWait = emoji.Sprint(":hourglass:")
)
const (
trackingInterval time.Duration = 1 * time.Second
// nolint
initTimeout time.Duration = 30 * time.Second
trackingInterval time.Duration = 1 * time.Second
deployTimeout time.Duration = 10 * time.Second
healthCheckBufferTime time.Duration = 120 * time.Second
)
// NewAppStatusCommand creates `status` command for showing status
func NewAppStatusCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
@@ -294,7 +283,6 @@ TrackDeployLoop:
if err != nil {
return compStatusUnknown, err
}
// nolint:exhaustive
switch deployStatus {
case compStatusDeploying:
continue
@@ -305,6 +293,8 @@ TrackDeployLoop:
ioStreams.Info(red.Sprintf("\n%sApplication Failed to Deploy!", emojiFail))
ioStreams.Info(red.Sprintf("Reason: %s", failMsg))
return compStatusDeployFail, nil
default:
continue
}
}
return compStatusDeployed, nil
@@ -446,15 +436,10 @@ func applySpinnerNewSuffix(s *spinner.Spinner, suffix string) {
func getHealthStatusColor(s HealthStatus) *color.Color {
var c *color.Color
// nolint:exhaustive
switch s {
case HealthStatusHealthy:
c = green
case HealthStatusUnhealthy:
c = red
case HealthStatusUnknown:
c = yellow
case HealthStatusNotDiagnosed:
case HealthStatusUnknown, HealthStatusNotDiagnosed:
c = yellow
default:
c = red

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -25,8 +23,10 @@ import (
"github.com/oam-dev/kubevela/pkg/utils/helm"
)
// VelaRuntimeStatus enums vela-core runtime status
type VelaRuntimeStatus int
// Enums of VelaRuntimeStatus
const (
NotFound VelaRuntimeStatus = iota
Pending
@@ -54,6 +54,7 @@ type infoCmd struct {
out io.Writer
}
// SystemCommandGroup creates `system` command and its nested children command
func SystemCommandGroup(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "system",
@@ -67,6 +68,7 @@ func SystemCommandGroup(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command
return cmd
}
// NewAdminInfoCommand creates `system info` command
func NewAdminInfoCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
i := &infoCmd{out: ioStreams.Out}
@@ -87,7 +89,7 @@ func NewAdminInfoCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
func (i *infoCmd) run(ioStreams cmdutil.IOStreams) error {
clusterVersion, err := GetOAMReleaseVersion(types.DefaultKubeVelaNS)
if err != nil {
return fmt.Errorf("fail to get cluster chartPath: %v", err)
return fmt.Errorf("fail to get cluster chartPath: %w", err)
}
ioStreams.Info("Versions:")
ioStreams.Infof("oam-kubernetes-runtime: %s \n", clusterVersion)
@@ -96,6 +98,7 @@ func (i *infoCmd) run(ioStreams cmdutil.IOStreams) error {
return nil
}
// NewInstallCommand creates `install` command
func NewInstallCommand(c types.Args, chartContent string, ioStreams cmdutil.IOStreams) *cobra.Command {
i := &initCmd{ioStreams: ioStreams}
cmd := &cobra.Command{
@@ -130,7 +133,7 @@ func NewInstallCommand(c types.Args, chartContent string, ioStreams cmdutil.IOSt
func (i *initCmd) run(ioStreams cmdutil.IOStreams, chartSource string) error {
waitDuration, err := time.ParseDuration(i.waitReady)
if err != nil {
return fmt.Errorf("invalid wait timeoout duration %v, should use '120s', '5m' like format", err)
return fmt.Errorf("invalid wait timeoout duration %w, should use '120s', '5m' like format", err)
}
ioStreams.Info("- Installing Vela Core Chart:")
@@ -176,7 +179,7 @@ func (i *initCmd) run(ioStreams cmdutil.IOStreams, chartSource string) error {
return nil
}
// MUST wait to install capability succeed
// CheckCapabilityReady waits unitl capability is installed successfully
func CheckCapabilityReady(ctx context.Context, c types.Args, timeout time.Duration) error {
if timeout < 2*time.Minute {
timeout = 2 * time.Minute
@@ -199,7 +202,7 @@ func CheckCapabilityReady(ctx context.Context, c types.Args, timeout time.Durati
return nil
}
if time.Since(start) > timeout {
return fmt.Errorf("timeout checking capability ready: %v", err)
return fmt.Errorf("timeout checking capability ready: %w", err)
}
time.Sleep(5 * time.Second)
}
@@ -208,7 +211,7 @@ func CheckCapabilityReady(ctx context.Context, c types.Args, timeout time.Durati
func (i *initCmd) resolveValues() (map[string]interface{}, error) {
finalValues := map[string]interface{}{}
valuesConfig := []string{
//TODO(wonderflow) values here could give more arguments in command line
// TODO(wonderflow) values here could give more arguments in command line
fmt.Sprintf("image.repository=%s", i.chartArgs.imageRepo),
fmt.Sprintf("image.tag=%s", i.chartArgs.imageTag),
fmt.Sprintf("image.pullPolicy=%s", i.chartArgs.imagePullPolicy),
@@ -222,6 +225,7 @@ func (i *initCmd) resolveValues() (map[string]interface{}, error) {
return finalValues, nil
}
// InstallOamRuntime installs vela-core runtime from helm chart
func InstallOamRuntime(chartPath, chartSource string, vals map[string]interface{}, ioStreams cmdutil.IOStreams) error {
var err error
var chartRequested *chart.Chart
@@ -236,11 +240,11 @@ func InstallOamRuntime(chartPath, chartSource string, vals map[string]interface{
}
}
if err != nil {
return fmt.Errorf("error loading chart for installation: %s", err)
return fmt.Errorf("error loading chart for installation: %w", err)
}
installClient, err := helm.NewHelmInstall("", types.DefaultKubeVelaNS, types.DefaultKubeVelaReleaseName)
if err != nil {
return fmt.Errorf("error create helm install client: %s", err)
return fmt.Errorf("error create helm install client: %w", err)
}
release, err := installClient.Run(chartRequested, vals)
if err != nil {
@@ -253,6 +257,7 @@ func InstallOamRuntime(chartPath, chartSource string, vals map[string]interface{
return nil
}
// GetOAMReleaseVersion gets version of vela-core runtime helm release
func GetOAMReleaseVersion(ns string) (string, error) {
results, err := helm.GetHelmRelease(ns)
if err != nil {
@@ -267,6 +272,7 @@ func GetOAMReleaseVersion(ns string) (string, error) {
return "", errors.New("oam-kubernetes-runtime not found in your kubernetes cluster, try `vela install` to install")
}
// PrintTrackVelaRuntimeStatus prints status of installing vela-core runtime
func PrintTrackVelaRuntimeStatus(ctx context.Context, c client.Client, ioStreams cmdutil.IOStreams, trackTimeout time.Duration) (bool, error) {
trackInterval := 5 * time.Second

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -10,6 +8,7 @@ import (
mycue "github.com/oam-dev/kubevela/pkg/cue"
)
// NewTemplateCommand creates `template` command and its nested children command
func NewTemplateCommand(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "template",
@@ -25,6 +24,7 @@ func NewTemplateCommand(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command
return cmd
}
// NewTemplateContextCommand creates `context` command
func NewTemplateContextCommand(ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "context",

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -31,6 +29,7 @@ type commandOptions struct {
cmdutil.IOStreams
}
// AddTraitCommands loads Trait command from installed capabilities
func AddTraitCommands(parentCmd *cobra.Command, c types.Args, ioStreams cmdutil.IOStreams) error {
templates, err := plugins.LoadInstalledCapabilityWithType(types.TypeTrait)
if err != nil {
@@ -86,6 +85,7 @@ func AddTraitCommands(parentCmd *cobra.Command, c types.Args, ioStreams cmdutil.
return nil
}
// Prepare prepares data for constructing OAM entities
func (o *commandOptions) Prepare(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("please specify the name of the app")
@@ -119,6 +119,7 @@ func (o *commandOptions) Prepare(cmd *cobra.Command, args []string) error {
return nil
}
// AddOrUpdateTrait adds or updates trait
func (o *commandOptions) AddOrUpdateTrait(cmd *cobra.Command, args []string) error {
var err error
if err = o.Prepare(cmd, args); err != nil {
@@ -132,6 +133,7 @@ func (o *commandOptions) AddOrUpdateTrait(cmd *cobra.Command, args []string) err
return nil
}
// DetachTrait removes a trait already attached to a service
func (o *commandOptions) DetachTrait(cmd *cobra.Command, args []string) error {
var err error
if err = o.Prepare(cmd, args); err != nil {
@@ -147,6 +149,7 @@ func (o *commandOptions) DetachTrait(cmd *cobra.Command, args []string) error {
return o.app.Save(o.Env.Name)
}
// Run executes create/update/detach trait
func (o *commandOptions) Run(ctx context.Context, cmd *cobra.Command, io cmdutil.IOStreams) error {
if o.Detach {
o.Infof("Detaching %s from app %s\n", o.traitType, o.workloadName)

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -14,6 +12,7 @@ import (
"github.com/oam-dev/kubevela/pkg/oam"
)
// NewTraitsCommand creates `traits` command
func NewTraitsCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
var workloadName string
var syncCluster bool

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -34,6 +32,7 @@ var (
appFilePath string
)
// NewUpCommand will create command for applying an AppFile
func NewUpCommand(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "up",
@@ -71,6 +70,7 @@ func NewUpCommand(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
return cmd
}
// AppfileOptions is some configuration that modify options for an Appfile
type AppfileOptions struct {
Kubecli client.Client
IO cmdutil.IOStreams
@@ -87,6 +87,7 @@ func saveRemoteAppfile(url string) (string, error) {
return dest, ioutil.WriteFile(dest, body, 0644)
}
// Run starts an application according to Appfile
func (o *AppfileOptions) Run(filePath string) error {
var app *appfile.AppFile
var err error
@@ -174,7 +175,7 @@ func (o *AppfileOptions) saveToAppDir(f *appfile.AppFile) error {
return app.Save(o.Env.Name)
}
// Apply deploy config resources for the app.
// ApplyAppConfig applys config resources for the app.
// It differs by create and update:
// - for create, it displays app status along with information of url, metrics, ssh, logging.
// - for update, it rolls out a canary deployment and prints its information. User can verify the canary deployment.
@@ -215,6 +216,7 @@ func (o *AppfileOptions) apply(ac *v1alpha2.ApplicationConfiguration, comps []*v
return application.CreateOrUpdateAppConfig(context.TODO(), o.Kubecli, ac)
}
// Info shows the status of each service in the Appfile
func (o *AppfileOptions) Info(appName string, comps []*v1alpha2.Component) string {
var appUpMessage = "✅ App has been deployed 🚀🚀🚀\n" +
fmt.Sprintf(" Port forward: vela port-forward %s\n", appName) +

View File

@@ -31,7 +31,7 @@ func AskToChooseOneService(svcNames []string) (string, error) {
var svcName string
err := survey.AskOne(prompt, &svcName)
if err != nil {
return "", fmt.Errorf("choosing service err %v", err)
return "", fmt.Errorf("choosing service err %w", err)
}
return svcName, nil
}

View File

@@ -1,5 +1,3 @@
//nolint:golint
// TODO add lint back
package commands
import (
@@ -13,6 +11,7 @@ import (
"github.com/spf13/cobra"
)
// NewWorkloadsCommand creates `workloads` command
func NewWorkloadsCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
var syncCluster bool
ctx := context.Background()