Modifies Makefile to support multiple plugins

Introduces new convention for plugins that fixes
multi plugin support

Each plugin name will exist at :
- cmd/<plugin name>/main.go
  Definitions to call plugin registration

- internal/plugin/<plugin name>
  Implementations for Navigation, Tab and Print as appropriate

Change-Id: I6f5e71900eb90b26917216ebd1a2749acc4f5a52
This commit is contained in:
jezogwza 2019-11-06 16:51:05 +00:00 committed by Rodolfo Pacheco
parent e4e14c891a
commit b273aab419
3 changed files with 26 additions and 20 deletions

View File

@ -8,6 +8,7 @@ GIT_VERSION=$(shell git describe --match 'v*' --always)
# Override the value of the version variable in main.go # Override the value of the version variable in main.go
LD_FLAGS= '-X main.version=$(GIT_VERSION)' LD_FLAGS= '-X main.version=$(GIT_VERSION)'
GO_FLAGS= -ldflags=$(LD_FLAGS) GO_FLAGS= -ldflags=$(LD_FLAGS)
PLUGINS:= $(shell ls cmd)
ifdef XDG_CONFIG_HOME ifdef XDG_CONFIG_HOME
OCTANT_PLUGINSTUB_DIR ?= ${XDG_CONFIG_HOME}/octant/plugins OCTANT_PLUGINSTUB_DIR ?= ${XDG_CONFIG_HOME}/octant/plugins
@ -20,11 +21,16 @@ endif
DIRS = internal pkg DIRS = internal pkg
RECURSIVE_DIRS = $(addsuffix /...,$(DIRS)) RECURSIVE_DIRS = $(addsuffix /...,$(DIRS))
#.PHONY: install-plugin
#install-plugin:
# mkdir -p $(OCTANT_PLUGINSTUB_DIR)
# go build -o $(OCTANT_PLUGINSTUB_DIR)/airship-ui-plugin $(GO_FLAGS) opendev.org/airship/airshipui/cmd/airshipui
.PHONY: install-plugin .PHONY: install-plugins
install-plugin: install-plugins: $(PLUGINS)
$(PLUGINS):
mkdir -p $(OCTANT_PLUGINSTUB_DIR) mkdir -p $(OCTANT_PLUGINSTUB_DIR)
go build -o $(OCTANT_PLUGINSTUB_DIR)/airship-ui-plugin $(GO_FLAGS) opendev.org/airship/airshipui/cmd/airshipui go build -o $(OCTANT_PLUGINSTUB_DIR)/$@-plugin $(GO_FLAGS) opendev.org/airship/airshipui/cmd/$@
.PHONY: test .PHONY: test
test: generate test: generate

View File

@ -1,31 +1,31 @@
package main package main
import ( import (
"fmt" "fmt"
"log" "log"
"opendev.org/airship/airshipui/internal/plugin" "opendev.org/airship/airshipui/internal/plugin/airshipui"
) )
var ( var (
pluginName = "airship-ui" pluginName = "airship-ui"
// version will be overriden by ldflags supplied in Makefile // version will be overriden by ldflags supplied in Makefile
version = "(dev-version)" version = "(dev-version)"
) )
// This is a sample plugin showing the features of Octant's plugin API. // This is a sample plugin showing the features of Octant's plugin API.
func main() { func main() {
// Remove the prefix from the go logger since Octant will print logs with timestamps. // Remove the prefix from the go logger since Octant will print logs with timestamps.
log.SetPrefix("") log.SetPrefix("")
description := fmt.Sprintf("Airship UI version %s", version) description := fmt.Sprintf("Airship UI version %s", version)
// Use the plugin service helper to register this plugin. // Use the plugin service helper to register this plugin.
p, err := plugin.Register(pluginName, description) p, err := plugin.Register(pluginName, description)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
// The plugin can log and the log messages will show up in Octant. // The plugin can log and the log messages will show up in Octant.
log.Printf("%s is starting", pluginName) log.Printf("%s is starting", pluginName)
p.Serve() p.Serve()
} }