
This implementation creates named references between an airship config file , and a user specified or system default kubeconfig file airshipconfig location can be specified via an envirnment variable or via --airshipconf string Path to file for airshipctl configuration. (default ".airship/config") kubeconfig has to be explicitly stated using the argument below --kubeconfig string Path to kubeconfig associated with airshipctl configuration. (default ".airship/kubeconfig") if the argument is not specified a default empty kubeconfig will be used using the default ".airship/kubeconfig" All subcommands exposed via airshipctl config will update airship config and airship related kubeconfig when appropriate. This patchset adds : - Config Struct (type) - config cmd and pkg - get_cluster : List a specific name cluster or List all clusters if no name is provided. - set-cluster : Create or Modify an existing cluster. Review comment fixes as of Pathset 19 - Moved core functionality from cmd to pkg - Encapsulate cmd needs in pck in nw files cmds, cmds_types and cmds_test . Expectation is that other functions will need func an structs there. - added test for GetCluster - Added GetCluster method to config object to be used by get_cluster command - Change ClusterNames func as per review suggestion - Change TestEmpty Cluster to avoid pointing to non test kubecnfig by default - Change constant AirshipConfigFilePath to AirshipConfigDir - Renamed config_utils to utils - Added config cmd output tests - Changes to settings_test.go to clean after itself. - Created new pkg/config/testdata/GoldenString for struct data comparison values to avoid confusion - Fix small get_cluster no name issue when empty config - Fix issue when reconciling a cluster info that only exists in airship config and not in kubeconfig Increased coverage to: SUCCESS: Test coverage is at 84.2%, Started to move all testdata to a single place under pkg/config for now. Change-Id: I7aae1f15afaebc99407f7fabccecf86ab0923bc3
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