cmd

package
v0.0.0-...-c143c6f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const KANPortalVersion = "0.39.0-main-603f4b9-amd64"
View Source
const SymphonyAPIVersion = "0.48.22"

The version is auto updated by the release pipeline, do not change it manually

Variables

View Source
var CheckCmd = &cobra.Command{
	Use:   "check",
	Short: "Check Symphony prerequisits",
	Run: func(cmd *cobra.Command, args []string) {
		b := utils.CheckDocker(cVerbose)
		b = utils.CheckKubectl(cVerbose) && b
		_, r := utils.CheckK8sConnection(cVerbose)
		b = r && b
		b = utils.CheckHelm(verbose) && b
		if b {
			fmt.Printf("\n%s  All Prerequisites are met!%s\n\n", utils.ColorCyan(), utils.ColorReset())
		}
	},
}
View Source
var DescribeCmd = &cobra.Command{
	Use:   "describe",
	Short: "describe a Symphony sample",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			fmt.Printf("\n%sPlease specify one sample name%s\n\n", utils.ColorRed(), utils.ColorReset())
			return
		}
		sampleManifest, err := listSamples()
		if err != nil {
			fmt.Printf("\n%s%s%s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
			return
		}
		if len(sampleManifest.Samples) == 0 {
			fmt.Println("no samples found")
			fmt.Printf("\n%s  No samples found. %s\n\n", utils.ColorRed(), utils.ColorReset())
			return
		}
		for _, sample := range sampleManifest.Samples {
			if sample.Name == args[0] {
				if sample.LongDescription != "" {
					str := strings.ReplaceAll(sample.LongDescription, "<C>", utils.ColorCyan())
					str = strings.ReplaceAll(str, "</C>", utils.ColorReset())
					str = strings.ReplaceAll(str, "<G>", utils.ColorGreen())
					str = strings.ReplaceAll(str, "</G>", utils.ColorReset())
					fmt.Printf("\n%s\n\n", str)
					return
				}
				fmt.Printf("\n%s\n\n", sample.Description)
				return
			}
		}
		fmt.Printf("\n%sSample '%s' is not found, please use maestro samples list to check available samples%s\n", utils.ColorRed(), args[0], utils.ColorReset())
	},
}
View Source
var GetCmd = &cobra.Command{
	Use:   "get",
	Short: "Query Symphony objects",
	Run: func(cmd *cobra.Command, args []string) {
		c := config.GetMaestroConfig(configFile)
		ctx := c.DefaultContext
		if configContext != "" {
			ctx = configContext
		}

		if ctx == "" {
			ctx = "default"
		}

		for _, a := range args {
			list, err := utils.Get(
				c.Contexts[ctx].Url,
				c.Contexts[ctx].User,
				c.Contexts[ctx].Secret,
				a,
				jsonPath,
				docType,
				objectName)
			if err != nil {
				fmt.Printf("\n%s  %s%s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
				return
			}
			outputList(list, a, jsonPath)
		}
	},
}
View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "list Symphony samples",
	Run: func(cmd *cobra.Command, args []string) {
		sampleManifest, err := listSamples()
		if err != nil {
			fmt.Printf("\n%s%s%s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
			return
		}
		if len(sampleManifest.Samples) == 0 {
			fmt.Printf("\n%sNo samples found%s\n\n", utils.ColorRed(), utils.ColorReset())
			return
		}
		t := table.NewWriter()
		t.SetOutputMirror(os.Stdout)
		t.AppendHeader(table.Row{"Name", "Description", "Requires"})
		for _, sample := range sampleManifest.Samples {
			row := table.Row{sample.Name, sample.Description, strings.Join(sample.Requires, ", ")}
			t.AppendRow(row)
		}
		t.SetStyle(table.StyleColoredBright)
		t.Render()
	},
}
View Source
var RemoveCmd = &cobra.Command{
	Use:   "remove",
	Short: "remove a Symphony sample",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			fmt.Printf("\n%sPlease specify one sample name%s\n\n", utils.ColorRed(), utils.ColorReset())
			return
		}
		sampleManifest, err := listSamples()
		if err != nil {
			fmt.Printf("\n%s%s%s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
			return
		}
		if len(sampleManifest.Samples) == 0 {
			fmt.Println("no samples found")
			fmt.Printf("\n%s  No samples found. %s\n\n", utils.ColorRed(), utils.ColorReset())
			return
		}
		for _, sample := range sampleManifest.Samples {
			if sample.Name == args[0] {
				for i := len(sample.Artifacts) - 1; i >= 0; i-- {
					err := removeArtifact(sample.Artifacts[i])
					if err != nil {
						fmt.Printf("\n%s  Failed to remove sample: %s %s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
						return
					}
					if i > 0 {
						time.Sleep(3 * time.Second)
					}
				}
				return
			}
		}
		fmt.Printf("Sample '%s' is not found, please use maestro samples list to check available samples\n", args[0])
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "maestro",
	Short: "maestro",
	Long: `
                           _              
     /\/\   __ _  ___  ___| |_ _ __ ___  
    /    \ / _' |/ _ \/ __| __| '__/ _ \ 
   / /\/\ \ (_| |  __/\__ \ |_| | | (_) |
   \/    \/\__,_|\___||___/\__|_|  \___/ 

   Jumpstart your Edge Journey
	`,
	Run: func(cmd *cobra.Command, args []string) {
	},
}
View Source
var RunCmd = &cobra.Command{
	Use:   "run",
	Short: "run a Symphony sample",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			fmt.Printf("\n%sPlease specify one sample name%s\n\n", utils.ColorRed(), utils.ColorReset())
			return
		}
		sampleManifest, err := listSamples()
		if err != nil {
			fmt.Printf("\n%s%s%s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
			return
		}
		if len(sampleManifest.Samples) == 0 {
			fmt.Println("no samples found")
			fmt.Printf("\n%s  No samples found. %s\n\n", utils.ColorRed(), utils.ColorReset())
			return
		}
		for _, sample := range sampleManifest.Samples {
			if sample.Name == args[0] {
				paramMap, err := setSwitchToMap()
				if err != nil {
					fmt.Println(err)
					return
				}
				for i, artifact := range sample.Artifacts {
					err := runArtifact(sample.Path, artifact, paramMap)
					if err != nil {
						fmt.Printf("\n%s  Failed to run sample: %s %s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
						return
					}
					if i < len(sample.Artifacts)-1 {
						time.Sleep(3 * time.Second)
					}
				}
				xArg := ""
				for _, action := range sample.PostActions {
					if xArg != "" {
						for i, _ := range action.Args {

							action.Args[i] = strings.ReplaceAll(action.Args[i], "$(1)", strings.Trim(xArg, `'"`))
						}
					}
					errOutput := ""
					xArg, errOutput, err = utils.RunCommandWithRetry("", "", verbose, debug, action.Command, action.Args...)
					if err != nil {
						fmt.Printf("\n%s  Failed to execute post deployment script: %s %s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
						fmt.Printf("\n%s  Detailed Messages: %s %s\n\n", utils.ColorRed(), errOutput, utils.ColorReset())
						return
					}
				}
				if xArg != "" {
					fmt.Printf("  %sNOTE%s: %s\n", utils.ColorGreen(), utils.ColorReset(), xArg)
				}
				return
			}
		}
		fmt.Printf("\n%sSample '%s' is not found, please use maestro samples list to check available samples%s\n", utils.ColorRed(), args[0], utils.ColorReset())
	},
}
View Source
var SamplesCmd = &cobra.Command{
	Use:   "samples",
	Short: "Symphony samples",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf("\n%sPlease use either 'samples run' or 'samples list'%s\n\n", utils.ColorRed(), utils.ColorReset())
	},
}
View Source
var UpCmd = &cobra.Command{
	Use:   "up",
	Short: "Install Symphony on a Kubernetes cluster, or run Symphony locally",
	Run: func(cmd *cobra.Command, args []string) {

		u, err := user.Current()
		if err != nil {
			fmt.Printf("\n%s  Failed: %s%s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
			return
		}
		if noK8s {
			if !updateSymphonyContext("no-k8s", "localhost") {
				return
			}
			_, err := utils.RunCommandNoCapture("Launching Symphony in standalone mode", "done", filepath.Join(u.HomeDir, ".symphony/symphony-api"), "-c", filepath.Join(u.HomeDir, ".symphony/symphony-api-no-k8s.json"), "-l", "Debug")
			if err != nil {
				fmt.Printf("\n%s  Failed: %s%s\n\n", utils.ColorRed(), err.Error(), utils.ColorReset())
				return
			}
		} else {

			if !handleKubectl() {
				return
			}
			k8sContext, ret := handleK8sConnection()
			if !ret {
				return
			}
			_, errOutput, err := utils.RunCommand("Installing cert manager", "done", verbose, "kubectl", "apply", "-f", "https://github.com/jetstack/cert-manager/releases/download/v1.4.0/cert-manager.yaml")
			if err != nil {
				fmt.Printf("\n%s  Failed.%s\n\n", utils.ColorRed(), utils.ColorReset())
				fmt.Printf("\n%s  Detailed Messages: %s%s\n\n", utils.ColorRed(), errOutput, utils.ColorReset())
				return
			}
			if !handleHelm() {
				return
			}
			if !handleSymphony(noRestApi) {
				return
			}
			var tunnelCMD *exec.Cmd
			if !noRestApi {

				if k8sContext == "minikube" {
					tunnelCMD, err = handleMinikubeTunnel()
					if err != nil {
						return
					}
				}

				ret, apiAddress := checkSymphonyAddress()
				if !ret {
					return
				}

				if !updateSymphonyContext(k8sContext, apiAddress) {
					return
				}

				fmt.Printf("  %sSymphony API:%s %s%s\n", utils.ColorGreen(), utils.ColorWhite(), "http://"+apiAddress+":8080/v1alpha2/greetings", utils.ColorReset())
				fmt.Println()

				if k8sContext == "minikube" {
					fmt.Printf("  %sKeeping minikube tunnel for API use. Press CTRL + C to stop the tunnel and quit.%s\n", utils.ColorGreen(), utils.ColorReset())
					fmt.Println()
					tunnelCMD.Wait()
				}
			}

			fmt.Printf("\n%s  Done!%s\n\n", utils.ColorCyan(), utils.ColorReset())

			if noRestApi {
				fmt.Printf("  %sREST API is turned off in no-rest-api Mode and you can interact with Symphony using kubectl.%s\n", utils.ColorYellow(), utils.ColorReset())
			}
			fmt.Println()

		}
	},
}
View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Get CLI version",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf("\n%s  Maestro Version: %s%s\n\n", utils.ColorPurple(), SymphonyAPIVersion, utils.ColorReset())

	},
}

Functions

func Execute

func Execute(versiong string)

Types

type ActionSpec

type ActionSpec struct {
	Command string   `json:"command"`
	Args    []string `json:"args,omitempty"`
}

type ArtifactSpec

type ArtifactSpec struct {
	File       string          `json:"file"`
	Type       string          `json:"type"`
	Name       string          `json:"name"`
	Parameters []ParameterSpec `json:"parameters,omitempty"`
}

type Catalog

type Catalog struct {
	Metadata model.ObjectMeta    `json:"metadata,omitempty"`
	Spec     model.CatalogSpec   `json:"spec,omitempty"`
	Status   model.CatalogStatus `json:"status,omitempty"`
}

type Device

type Device struct {
	Metadata model.ObjectMeta   `json:"metadata,omitempty"`
	Spec     model.DeviceSpec   `json:"spec,omitempty"`
	Status   model.DeviceStatus `json:"status,omitempty"`
}

type Instance

type Instance struct {
	Metadata model.ObjectMeta     `json:"metadata,omitempty"`
	Spec     model.InstanceSpec   `json:"spec,omitempty"`
	Status   model.InstanceStatus `json:"status,omitempty"`
}

type ParameterSpec

type ParameterSpec struct {
	Name    string `json:"name"`
	Value   string `json:"value,omitempty"`
	Replace string `json:"replace"`
}

type SampleManifest

type SampleManifest struct {
	Package string       `json:"package"`
	Version string       `json:"version"`
	Samples []SampleSpec `json:"samples"`
}

type SampleSpec

type SampleSpec struct {
	Name            string         `json:"name"`
	Path            string         `json:"path"`
	Artifacts       []ArtifactSpec `json:"artifacts"`
	Description     string         `json:"description"`
	LongDescription string         `json:"description-long,omitempty"`
	Requires        []string       `json:"requires"`
	PostActions     []ActionSpec   `json:"postActions,omitempty"`
}

type Solution

type Solution struct {
	Metadata model.ObjectMeta   `json:"metadata,omitempty"`
	Spec     model.SolutionSpec `json:"spec,omitempty"`
	Status   map[string]string  `json:"status,omitempty"`
}

type Target

type Target struct {
	Metadata model.ObjectMeta   `json:"metadata,omitempty"`
	Spec     model.TargetSpec   `json:"spec,omitempty"`
	Status   model.TargetStatus `json:"status,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL