Ian Howell 6fb4af06a1 Fix the make cover target
This change has multiple benefits:

* Allows testing/coverage Makefile flags to be set from the command
  line. This allows a dev to easily test both correctness and coverage of
  a subset of packages by simply providing a value for the `PKG` make
  variable.

* Fixes an issue where an error message was being printed to stderr on
  each Zuul run, since the `COVER_PKG` variable required that Go is
  installed, and yet we don't install Go to the Zuul VM.

* Fixes an issue where Zuul VMs were crashing due to an Out Of Memory
  error. This was happening because of the way that the `coverpkg` flag
  works, which caused tests to occasionally require more than 8G of
  memory, exceeding the amount of memory on each Zuul VM.

* Cleans up the output when running `make cover`. Previously, the list
  of all packages was printed for coverage for each package, creating a
  lot of noise on the console.

However, it has the following negative:

* With the removal of the `coverpkg` flag, the `go test` command will no
  longer check coverage of packages which do not include any `_test.go`
  files. This puts the responsibility of assuring that coverage is
  correctly reflected onto the shoulders of developers and reviewers.

Change-Id: I7fef1dd26ef19b5f2ab4cf2d1be223bf82210492
2019-11-01 15:28:56 -05:00
2019-10-24 00:34:20 -05:00
2019-10-02 15:18:56 -05:00
2019-06-06 09:30:51 -05:00
2019-06-25 08:11:57 -05:00
2019-10-04 15:31:45 +00:00
2019-10-24 00:34:20 -05:00
2019-11-01 15:28:56 -05:00

airshipctl

Custom Plugins Tutorial

This tutorial walks through a very basic plugin for airshipctl. For a more involved example, see Plugin Support

The following steps will get you started with a very rudimentary example plugin for airshipctl. First, create a directory for your project outside of the GOPATH:

mkdir /tmp/example
cd /tmp/example

This project will need to be a go module. You can initialize a module named example with the following:

go mod init example

Note that modules are a relatively new feature added to Go, so you'll need to be running Go1.11 or greater. Also note that most modules will follow a naming schema that matches the remote version control system. A more realistice module name might look something like opendev.org/airship/exampleplugin.

Next, create a file main.go and populate it with the following:

package main

import (
	"fmt"
	"os"

	"opendev.org/airship/airshipctl/cmd"
	"github.com/spf13/cobra"
)

func main() {
	rootCmd, _, err := cmd.NewRootCmd(os.Stdout)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create root airshipctl command: %s\n", err.Error())
		os.Exit(1)
	}

	exampleCmd := &cobra.Command{
		Use:   "example",
		Short: "an example plugin",
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Fprintln(os.Stdout, "Hello airshipctl!")
		},
	}

	rootCmd.AddCommand(exampleCmd)
	if err := rootCmd.Execute(); err != nil {
		fmt.Fprintf(os.Stderr, "Failure during execution: %s\n", err.Error())
		os.Exit(1)
	}
}

And finally, run the build command to download and compile airshipctl:

go build -o airshipctl

Now that you've built airshipctl, you can access your plugin with the following command:

./airshipctl example

You may have noticed that this example ignores the second return value from cmd.NewRootCmd. This value is a pointer to the AirshipCTLSettings, which contains various configuration details, such as the debug flag and the path to the config file*. A useful paradigm involves embedding this object into a custom ExampleSettings struct. This can be seen in the demo repo.

For a more involved example, see Plugin Support

* Work in progress

Description
A CLI for managing declarative infrastructure.
Readme 380 MiB
Languages
Go 85.7%
Shell 9.6%
Dockerfile 1.4%
Jinja 1.3%
Makefile 1.2%
Other 0.8%