Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var APICmd = &cobra.Command{ Use: "api", Short: "Scaffold a Kubernetes API", Long: `Scaffold a Kubernetes API by creating a Resource definition and / or a Controller. api will prompt the user for if it should scaffold the Resource and / or Controller. To only scaffold a Controller for an existing Resource, select "n" for Resource. To only define the schema for a Resource without writing a Controller, select "n" for Controller. After the scaffold is written, api will run make on the project. `, Example: ` # Create a frigates API with Group: ship, Version: v1beta1 and Kind: Frigate controller-scaffold api --group ship --version v1beta1 --kind Frigate # Edit the API Scheme nano pkg/apis/ship/v1beta1/frigate_types.go # Edit the Controller nano pkg/controller/frigate/frigate_controller.go # Edit the Controller Test nano pkg/controller/frigate/frigate_controller_test.go # Install CRDs into the Kubernetes cluster using kubectl apply make install # Regenerate code and run against the Kubernetes cluster configured by ~/.kube/config make run `, Run: func(cmd *cobra.Command, args []string) { DieIfNoProject() if !resourceFlag.Changed { fmt.Println("Create Resource under pkg/apis [y/n]?") doResource = yesno() } if !controllerFlag.Changed { fmt.Println("Create Controller under pkg/controller [y/n]?") doController = yesno() } fmt.Println("Writing scaffold for you to edit...") if doResource { fmt.Println(filepath.Join("pkg", "apis", r.Group, r.Version, fmt.Sprintf("%s_types.go", strings.ToLower(r.Kind)))) fmt.Println(filepath.Join("pkg", "apis", r.Group, r.Version, fmt.Sprintf("%s_types_test.go", strings.ToLower(r.Kind)))) err := (&scaffold.Scaffold{}).Execute(input.Options{}, &resource.Register{Resource: r}, &resource.Types{Resource: r}, &resource.VersionSuiteTest{Resource: r}, &resource.TypesTest{Resource: r}, &resource.Doc{Resource: r}, &resource.Group{Resource: r}, &resource.AddToScheme{Resource: r}, &resource.CRDSample{Resource: r}, ) if err != nil { log.Fatal(err) } } if doController { fmt.Println(filepath.Join("pkg", "controller", strings.ToLower(r.Kind), fmt.Sprintf("%s_controller.go", strings.ToLower(r.Kind)))) fmt.Println(filepath.Join("pkg", "apis", strings.ToLower(r.Kind), fmt.Sprintf("%s_controller_test.go", strings.ToLower(r.Kind)))) err := (&scaffold.Scaffold{}).Execute(input.Options{}, &controller.Controller{Resource: r}, &controller.AddController{Resource: r}, &controller.Test{Resource: r}, &controller.SuiteTest{Resource: r}, ) if err != nil { log.Fatal(err) } } if doMake { fmt.Println("Running make...") cm := exec.Command("make") cm.Stderr = os.Stderr cm.Stdout = os.Stdout if err := cm.Run(); err != nil { log.Fatal(err) } } }, }
APICmd represents the resource command
View Source
var ProjectCmd = &cobra.Command{ Use: "project", Short: "Scaffold a new project.", Long: `Scaffold a project. Writes the following files: - a boilerplate license file - a PROJECT file with the domain and repo - a Makefile to build the project - a Gopkg.toml with project dependencies - a Kustomization.yaml for customizating manifests - a Patch file for customizing image for manager manifests - a cmd/manager/main.go to run project will prompt the user to run 'dep ensure' after writing the project files. `, Example: `# Scaffold a project using the apache2 license with "The Kubernetes authors" as owners controller-scaffold project --domain k8s.io --license apache2 --owner "The Kubernetes authors" `, Run: func(cmd *cobra.Command, args []string) { s := &scaffold.Scaffold{ BoilerplateOptional: true, ProjectOptional: true, } p, err := prj.GetInput() if err != nil { log.Fatal(err) } b, err := bp.GetInput() if err != nil { log.Fatal(err) } err = s.Execute(input.Options{ProjectPath: p.Path, BoilerplatePath: b.Path}, prj, bp) if err != nil { log.Fatal(err) } s = &scaffold.Scaffold{} err = s.Execute(input.Options{ProjectPath: p.Path, BoilerplatePath: b.Path}, gopkg, mrg, mkFile, dkr, &manager.APIs{}, &manager.Controller{}, &manager.Config{Image: imgName}, &project.GitIgnore{}, &project.Kustomize{}, &project.KustomizeImagePatch{}) if err != nil { log.Fatal(err) } if !depFlag.Changed { fmt.Println("Run `dep ensure` to fetch dependencies (Recommended) [y/n]?") dep = yesno() } if dep { c := exec.Command("dep", "ensure") c.Stderr = os.Stderr c.Stdout = os.Stdout fmt.Println(strings.Join(c.Args, " ")) if err := c.Run(); err != nil { log.Fatal(err) } fmt.Println("Running make...") c = exec.Command("make") c.Stderr = os.Stderr c.Stdout = os.Stdout fmt.Println(strings.Join(c.Args, " ")) if err := c.Run(); err != nil { log.Fatal(err) } } else { fmt.Println("Skipping `dep ensure`. Dependencies will not be fetched.") } }, }
ProjectCmd represents the project command
Functions ¶
func BoilerplateForFlags ¶
func BoilerplateForFlags(f *flag.FlagSet) *project.Boilerplate
BoilerplateForFlags registers flags for Boilerplate fields and returns the Boilerplate
func DieIfNoProject ¶
func DieIfNoProject()
DieIfNoProject checks to make sure the command is run from a directory containing a project file.
func Execute ¶
func Execute()
Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.
func MakefileForFlags ¶
MakefileForFlags registers flags for Makefile fields and returns the Makefile
func ProjectForFlags ¶
ProjectForFlags registers flags for Project fields and returns the Project
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.