Align airshipui with airshipctl on the linting setup

Brought over the .golangci.yaml file from airshipctl
Made necessiary corrections based on it

The goimports section in .golangi.yaml will need to be addressed,
not currently working for airshipui

Change-Id: I43973224703408a3320e43a59b4639d6d3edd1ca
This commit is contained in:
Schiefelbein, Andrew 2020-03-23 13:28:48 -05:00
parent 3ed7d1f3f6
commit 55f07e1b25
16 changed files with 199 additions and 136 deletions

View File

@ -1,5 +1,5 @@
# This file contains all available configuration options
# with their default values.
# with their documentation
# options for analysis running
run:
@ -7,7 +7,7 @@ run:
concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 5m
timeout: 5m
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
@ -61,35 +61,88 @@ output:
# all available settings of specific linters
linters-settings:
errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: false
check-type-assertions: true
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false
check-blank: true
# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
# exclude: /path/to/file.txt
govet:
# report about shadowed variables
check-shadowing: true
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
goconst:
# minimal length of string constant, 3 by default
min-len: 4
# minimal occurrences count to trigger, 3 by default
min-occurrences: 5
gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.
enabled-checks:
- appendAssign
- appendCombine
- assignOp
- captLocal
- caseOrder
- commentedOutCode
- commentedOutImport
- defaultCaseOrder
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- elseif
- equalFold
- flagDeref
- ifElseChain
- regexpMust
- singleCaseSwitch
- sloppyLen
- switchTrue
- typeAssertChain
- typeSwitchVar
- underef
- unlambda
- unslice
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
# disabled-checks:
# - regexpMust
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
# enabled-tags:
# - performance
settings: # settings passed to gocritic
captLocal:
paramsOnly: false
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 15
dupl:
# tokens count to trigger issue, 150 by default
threshold: 100
goconst:
# minimal length of string constant, 3 by default
min-len: 3
# minimal occurrences count to trigger, 3 by default
min-occurrences: 3
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
#local-prefixes: opendev.org/airship/airshipui
govet:
# report about shadowed variables
check-shadowing: true
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
@ -97,46 +150,44 @@ linters-settings:
locale: US
# ignore-words:
# - someword
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 10
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 120
# tab width in spaces. Default to 1.
tab-width: 1
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
unparam:
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 10
prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdirectory of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
linters:
disable-all: true
enable:
- dupl # Tool for code clone detection
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- goconst # Finds repeated strings that could be replaced by a constant
- gocritic # The most opinionated Go source code linter
- gocyclo # Computes and checks the cyclomatic complexity of functions
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
- gosec # Inspects source code for security problems
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # Detects when assignments to existing variables are not used
- interfacer # Linter that suggests narrower interface types
- lll # Reports long lines
- misspell # Finds commonly misspelled English words in comments
@ -145,3 +196,6 @@ linters:
- scopelint # Scopelint checks for unpinned variables in go programs
- unconvert # Remove unnecessary type conversions
- unparam # Reports unused function parameters
- unused # Checks Go code for unused constants, variables, functions and types
- varcheck # Finds unused global variables and constants
- whitespace # Tool for detection of leading and trailing whitespace NOTE(howell): This linter does _not_ check for trailing whitespace in multiline strings

View File

@ -19,7 +19,7 @@ func main() {
// Use the plugin service helper to register this plugin.
p, err := plugin.Register(pluginName, description)
if err != nil {
log.Fatal("Unable to start %s", pluginName, err)
log.Fatal("Unable to start ", pluginName, err)
}
// The plugin can log and the log messages will show up in Octant.

View File

@ -19,7 +19,7 @@ func main() {
// Use the plugin service helper to register this plugin.
p, err := plugin.Register(pluginName, description)
if err != nil {
log.Fatal("Unable to start %s", pluginName, err)
log.Fatal("Unable to start ", pluginName, err)
}
// The plugin can log and the log messages will show up in Octant.

7
go.mod
View File

@ -8,11 +8,10 @@ require (
github.com/gophercloud/gophercloud v0.9.0
github.com/spf13/cobra v0.0.6
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
github.com/vmware-tanzu/octant v0.11.0
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
opendev.org/airship/airshipctl v0.0.0-20200326153008-ffacc190e95c
k8s.io/api v0.17.4
k8s.io/apimachinery v0.17.4
opendev.org/airship/airshipctl v0.0.0-20200324160507-db6217f011b9
)
replace k8s.io/client-go => k8s.io/client-go v0.0.0-20191114101535-6c5935290e33

18
go.sum
View File

@ -421,11 +421,8 @@ github.com/vmware-tanzu/octant v0.10.2-0.20200302175445-a52392c6f48e h1:nayXBqq/
github.com/vmware-tanzu/octant v0.10.2-0.20200302175445-a52392c6f48e/go.mod h1:ree4Qu6ULumg1MlGrAG7avEQx3+NjWPc0Zs4nQWOmQE=
github.com/vmware-tanzu/octant v0.10.2-0.20200320182255-15a53b6af867 h1:KdLbukBYm0E0yuo6TQ2m5v/zHLlLoxaTF2crGCxqB4U=
github.com/vmware-tanzu/octant v0.10.2-0.20200320182255-15a53b6af867/go.mod h1:ree4Qu6ULumg1MlGrAG7avEQx3+NjWPc0Zs4nQWOmQE=
github.com/vmware-tanzu/octant v0.10.2 h1:sqXei1wyxhajUt90HGHPEyRTv12T8Mwv6vyKKdLUYg4=
github.com/vmware-tanzu/octant v0.10.2/go.mod h1:ree4Qu6ULumg1MlGrAG7avEQx3+NjWPc0Zs4nQWOmQE=
github.com/vmware-tanzu/octant v0.11.0 h1:1ganDAIiswCL2QDu/C0pczWoraSMIWMtq79GOCqnrr8=
github.com/vmware-tanzu/octant v0.11.0/go.mod h1:ree4Qu6ULumg1MlGrAG7avEQx3+NjWPc0Zs4nQWOmQE=
github.com/vmware/govmomi v0.20.1/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
@ -482,6 +479,8 @@ golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a h1:+HHJiFUXVOIS9mr1ThqkQD1N8vpFCfCShqADBM12KTc=
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -545,6 +544,7 @@ golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBn
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a h1:mEQZbbaBjWyLNy0tmZmgEuQAR8XOQ3hL8GYi3J/NG64=
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/tools v0.0.0-20191203134012-c197fd4bf371/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@ -614,8 +614,8 @@ k8s.io/api v0.0.0-20191114100352-16d7abae0d2a h1:86XISgFlG7lPOWj6wYLxd+xqhhVt/WQ
k8s.io/api v0.0.0-20191114100352-16d7abae0d2a/go.mod h1:qetVJgs5i8jwdFIdoOZ70ks0ecgU+dYwqZ2uD1srwOU=
k8s.io/api v0.17.3 h1:XAm3PZp3wnEdzekNkcmj/9Y1zdmQYJ1I4GKSBBZ8aG0=
k8s.io/api v0.17.3/go.mod h1:YZ0OTkuw7ipbe305fMpIdf3GLXZKRigjtZaV5gzC2J0=
k8s.io/api v0.18.0 h1:lwYk8Vt7rsVTwjRU6pzEsa9YNhThbmbocQlKvNBB4EQ=
k8s.io/api v0.18.0/go.mod h1:q2HRQkfDzHMBZL9l/y9rH63PkQl4vae0xRT+8prbrK8=
k8s.io/api v0.17.4 h1:HbwOhDapkguO8lTAE8OX3hdF2qp8GtpC9CW/MQATXXo=
k8s.io/api v0.17.4/go.mod h1:5qxx6vjmwUVG2nHQTKGlLts8Tbok8PzHl4vHtVFuZCA=
k8s.io/apiextensions-apiserver v0.0.0-20181213153335-0fe22c71c476 h1:Ws9zfxsgV19Durts9ftyTG7TO0A/QLhmu98VqNWLiH8=
k8s.io/apiextensions-apiserver v0.0.0-20181213153335-0fe22c71c476/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
@ -625,8 +625,8 @@ k8s.io/apimachinery v0.0.0-20191028221656-72ed19daf4bb h1:ZUNsbuPdXWrj0rZziRfCWc
k8s.io/apimachinery v0.0.0-20191028221656-72ed19daf4bb/go.mod h1:llRdnznGEAqC3DcNm6yEj472xaFVfLM7hnYofMb12tQ=
k8s.io/apimachinery v0.17.3 h1:f+uZV6rm4/tHE7xXgLyToprg6xWairaClGVkm2t8omg=
k8s.io/apimachinery v0.17.3/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g=
k8s.io/apimachinery v0.18.0 h1:fuPfYpk3cs1Okp/515pAf0dNhL66+8zk8RLbSX+EgAE=
k8s.io/apimachinery v0.18.0/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.17.4 h1:UzM+38cPUJnzqSQ+E1PY4YxMHIzQyCg29LOoGfo79Zw=
k8s.io/apimachinery v0.17.4/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g=
k8s.io/cli-runtime v0.0.0-20191114110141-0a35778df828 h1:g5LpwfPTlzVksjrqp3EuSFg2ihl9LZVaRhnMas5sB/s=
k8s.io/cli-runtime v0.0.0-20191114110141-0a35778df828/go.mod h1:r9ARs2FUnSgInbeN4+mo9nFzf7oqUtRZ3tcuEcoelR4=
k8s.io/client-go v0.0.0-20191114101535-6c5935290e33 h1:07mhG/2oEoo3N+sHVOo0L9PJ/qvbk3N5n2dj8IWefnQ=
@ -666,8 +666,8 @@ modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs
modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I=
opendev.org/airship/airshipctl v0.0.0-20200319213630-b2a602fa07e0 h1:PPW+Zyjw96vwdnrKUnlpOjtajihO/1unrOe8C5bH1ok=
opendev.org/airship/airshipctl v0.0.0-20200319213630-b2a602fa07e0/go.mod h1:2Ox64Dscbq8HGJjP9s3Mvpfgcn+lRxBKP7n1vD/RnwE=
opendev.org/airship/airshipctl v0.0.0-20200326153008-ffacc190e95c h1:mZYOp/L+7WWlxr6Epq1v7Hi5t6RKm/gt15pEj2R2bPA=
opendev.org/airship/airshipctl v0.0.0-20200326153008-ffacc190e95c/go.mod h1:ILbbxTS02MO4yh7C5iMtz0KzxYFYwSRgiyPhYQ4tWsY=
opendev.org/airship/airshipctl v0.0.0-20200324160507-db6217f011b9 h1:0zG4z8113K+eWcWwGJuLv6YhupuoW87ugYZQjr0cW6s=
opendev.org/airship/airshipctl v0.0.0-20200324160507-db6217f011b9/go.mod h1:2Ox64Dscbq8HGJjP9s3Mvpfgcn+lRxBKP7n1vD/RnwE=
opendev.org/airship/go-redfish v0.0.0-20200110185254-3ab47e28bae8 h1:wIvgHcZH/l7H/eTIjZXGfqurtarlaAv2CtnO/8xYCis=
opendev.org/airship/go-redfish v0.0.0-20200110185254-3ab47e28bae8/go.mod h1:FEjYcb3bYBWGpQIqtvVM0NrT5eyjlCOCj5JNf4lI+6s=
opendev.org/airship/go-redfish v0.0.0-20200318103738-db034d1d753a h1:4ggAMTwpfu/w3ZXOIJ9tfYF37JIYn+eNCA4O10NduZ0=

View File

@ -19,7 +19,6 @@ import (
var verboseLevel int
func RunOctantWithOptions(kubeConfigPath string, args []string) {
// cobra command processing has already taken place and has processed and removed all flags and
// their options from args. Since this is a temporary workaround it is not worth the effort to
// extract all of these flags back out of cmd and reconstruct the original command line. But
@ -81,7 +80,10 @@ func RunOctantWithOptions(kubeConfigPath string, args []string) {
if stat.PID > 0 {
proc, err := os.FindProcess(stat.PID)
if err == nil {
proc.Kill()
err = proc.Kill()
if err != nil {
fmt.Printf("error trying to kill process: %s\n", err)
}
}
}
}()

View File

@ -1,15 +1,19 @@
/*
Copyright (c) 2019 the Octant contributors. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package commands
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"opendev.org/airship/airshipctl/pkg/config"
ctlenv "opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipui/internal/environment"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
var (

View File

@ -13,7 +13,6 @@ import (
)
func newVersionCmd() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Show version",

View File

@ -92,7 +92,7 @@ func getArgoUIURL(request service.Request) (u *url.URL, err error) {
end := &v1.Endpoints{}
if o != nil {
err := runtime.DefaultUnstructuredConverter.FromUnstructured(o.Object, end)
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.Object, end)
if err != nil {
return u, err
}

View File

@ -1,32 +1,12 @@
package plugin
import (
"context"
"fmt"
"testing"
"github.com/golang/mock/gomock"
"github.com/vmware-tanzu/octant/pkg/plugin/service"
"github.com/vmware-tanzu/octant/pkg/plugin/service/fake"
)
type fakeRequest struct {
ctrl *gomock.Controller
path, title string
}
func (f *fakeRequest) DashboardClient() service.Dashboard {
return fake.NewMockDashboard(f.ctrl)
}
func (f *fakeRequest) Path() string {
return ""
}
func (f *fakeRequest) Context() context.Context {
return context.TODO()
}
func TestRegister(t *testing.T) {
plugin, err := Register("argo-ui", "Argo UI test version")
if err != nil {

View File

@ -24,13 +24,12 @@ import (
func getFlavors(osp *OpenstackPlugin) component.Component {
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
flavors.ListDetail(computeClientHelper(osp), flavors.ListOpts{AccessType: flavors.AllAccess}).EachPage(
err := flavors.ListDetail(computeClientHelper(osp), flavors.ListOpts{AccessType: flavors.AllAccess}).EachPage(
func(page pagination.Page) (bool, error) {
flavorList, err := flavors.ExtractFlavors(page)
if err != nil {
log.Fatalf("compute flavor Error: %s\n", err)
log.Printf("compute flavor Error: %s\n", err)
}
for _, flavor := range flavorList {
@ -52,6 +51,10 @@ func getFlavors(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("compute flavor list error: %s\n", err)
}
return component.NewTableWithRows(
"Flavors",
"No flavors found",
@ -65,13 +68,12 @@ func getFlavors(osp *OpenstackPlugin) component.Component {
func getImages(osp *OpenstackPlugin) component.Component {
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
images.ListDetail(computeClientHelper(osp), images.ListOpts{}).EachPage(
err := images.ListDetail(computeClientHelper(osp), images.ListOpts{}).EachPage(
func(page pagination.Page) (bool, error) {
list, err := images.ExtractImages(page)
if err != nil {
log.Fatalf("Image list error: %s\n", err)
log.Printf("Image list error: %s\n", err)
return false, err
}
@ -89,6 +91,10 @@ func getImages(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("compute image list error: %s\n", err)
}
return component.NewTableWithRows(
"Images",
"No images found",
@ -100,8 +106,7 @@ func getImages(osp *OpenstackPlugin) component.Component {
func getVMs(osp *OpenstackPlugin) component.Component {
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
servers.List(computeClientHelper(osp), servers.ListOpts{AllTenants: true}).EachPage(
err := servers.List(computeClientHelper(osp), servers.ListOpts{AllTenants: true}).EachPage(
func(page pagination.Page) (bool, error) {
list, err := servers.ExtractServers(page)
@ -143,6 +148,10 @@ func getVMs(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("compute server list error: %s\n", err)
}
return component.NewTableWithRows(
"Servers",
"No servers found",

View File

@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0
package plugin
import (
"encoding/json"
"log"
"strconv"
@ -22,13 +23,12 @@ import (
func getDomains(osp *OpenstackPlugin) component.Component {
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
domains.List(identityClientHelper(osp), domains.ListOpts{}).EachPage(
err := domains.List(identityClientHelper(osp), domains.ListOpts{}).EachPage(
func(page pagination.Page) (bool, error) {
domainList, err := domains.ExtractDomains(page)
if err != nil {
log.Fatalf("Broken at user list %v\n", err)
log.Printf("Broken at domain list %v\n", err)
return false, err
}
@ -45,6 +45,10 @@ func getDomains(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("identity domain list error: %s\n", err)
}
return component.NewTableWithRows(
"Domains",
"No domains found",
@ -56,13 +60,12 @@ func getDomains(osp *OpenstackPlugin) component.Component {
func getProjects(osp *OpenstackPlugin) component.Component {
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
projects.List(identityClientHelper(osp), projects.ListOpts{}).EachPage(
err := projects.List(identityClientHelper(osp), projects.ListOpts{}).EachPage(
func(page pagination.Page) (bool, error) {
projectList, err := projects.ExtractProjects(page)
if err != nil {
log.Fatalf("Broken at project list %v\n", err)
log.Printf("Broken at project list %v\n", err)
return false, err
}
@ -80,6 +83,10 @@ func getProjects(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("identity project list error: %s\n", err)
}
return component.NewTableWithRows(
"Projects",
"No projects found",
@ -91,20 +98,24 @@ func getProjects(osp *OpenstackPlugin) component.Component {
func getUsers(osp *OpenstackPlugin) component.Component {
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
users.List(identityClientHelper(osp), users.ListOpts{}).EachPage(
err := users.List(identityClientHelper(osp), users.ListOpts{}).EachPage(
func(page pagination.Page) (bool, error) {
networkList, err := users.ExtractUsers(page)
if err != nil {
log.Fatalf("Broken at user list %v\n", err)
log.Printf("Broken at user list %v\n", err)
return false, err
}
for _, user := range networkList {
email := ""
if user.Extra["email"] != nil {
email = user.Extra["email"].(string)
var email string
emailInterface, ok := user.Extra["email"]
if ok && emailInterface != nil {
b, err := json.Marshal(emailInterface)
if err != nil {
log.Printf("Error getting email %v\n", err)
}
email = string(b)
}
rows = append(rows, component.TableRow{
@ -119,6 +130,10 @@ func getUsers(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("identity user list error: %s\n", err)
}
return component.NewTableWithRows(
"Users",
"No users found",

View File

@ -23,13 +23,12 @@ import (
func getNetworks(osp *OpenstackPlugin) component.Component {
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
networks.List(networkClientHelper(osp), networks.ListOpts{}).EachPage(
err := networks.List(networkClientHelper(osp), networks.ListOpts{}).EachPage(
func(page pagination.Page) (bool, error) {
networkList, err := networks.ExtractNetworks(page)
if err != nil {
log.Fatalf("Network retrival error: %s\n", err)
log.Printf("Network retrival error: %s\n", err)
return false, err
}
@ -63,6 +62,10 @@ func getNetworks(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("network list error: %s\n", err)
}
return component.NewTableWithRows(
"Networks",
"No networks found",
@ -76,13 +79,12 @@ func getNetworks(osp *OpenstackPlugin) component.Component {
func getSubnets(osp *OpenstackPlugin) component.Component {
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
subnets.List(networkClientHelper(osp), subnets.ListOpts{}).EachPage(
err := subnets.List(networkClientHelper(osp), subnets.ListOpts{}).EachPage(
func(page pagination.Page) (bool, error) {
networkList, err := subnets.ExtractSubnets(page)
if err != nil {
log.Fatalf("Subnet list error: %s\n", err)
log.Printf("Subnet list error: %s\n", err)
return false, err
}
@ -102,6 +104,9 @@ func getSubnets(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("network subnet list error: %s\n", err)
}
return component.NewTableWithRows(
"Subnets",
"No subnets found",

View File

@ -124,10 +124,18 @@ func getOptsFromFile() (gophercloud.AuthOptions, error) {
log.Printf("Error opening file %s\n", err)
}
byteValue, _ := ioutil.ReadAll(jsonFile)
byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
log.Printf("Error reading file %s\n", err)
}
var tmp optJSON
json.Unmarshal(byteValue, &tmp)
err = json.Unmarshal(byteValue, &tmp)
if err != nil {
log.Printf("Error unmarshalling file %s\n", err)
}
opts := gophercloud.AuthOptions{
IdentityEndpoint: tmp.IdentityEndpoint,

View File

@ -5,32 +5,12 @@ SPDX-License-Identifier: Apache-2.0
package plugin
import (
"context"
"fmt"
"testing"
"github.com/golang/mock/gomock"
"github.com/vmware-tanzu/octant/pkg/plugin/service"
"github.com/vmware-tanzu/octant/pkg/plugin/service/fake"
)
type fakeRequest struct {
ctrl *gomock.Controller
path, title string
}
func (f *fakeRequest) DashboardClient() service.Dashboard {
return fake.NewMockDashboard(f.ctrl)
}
func (f *fakeRequest) Path() string {
return ""
}
func (f *fakeRequest) Context() context.Context {
return context.TODO()
}
func TestRegister(t *testing.T) {
plugin, err := Register("openstack", "OpenStack test version")
if err != nil {

View File

@ -19,21 +19,14 @@ import (
// gets OpenStack volumes viewable by the tenant
// https://docs.openstack.org/cinder/latest/
func getVolumes(osp *OpenstackPlugin) component.Component {
client, err := openstack.NewBlockStorageV2(osp.provider, gophercloud.EndpointOpts{})
if err != nil {
log.Fatalf("NewIdentityV3 error: %v", err)
}
rows := []component.TableRow{}
// TODO: Determine if the error needs to be handled from this function
volumes.List(client, volumes.ListOpts{}).EachPage(
err := volumes.List(volumeClientHelper(osp), volumes.ListOpts{}).EachPage(
func(page pagination.Page) (bool, error) {
volumeList, err := volumes.ExtractVolumes(page)
if err != nil {
log.Fatalf("Broken at volume list %v\n", err)
log.Printf("Broken at volume list %v\n", err)
return false, err
}
@ -61,9 +54,24 @@ func getVolumes(osp *OpenstackPlugin) component.Component {
return true, nil
})
if err != nil {
log.Printf("volume list error: %s\n", err)
}
return component.NewTableWithRows(
"Volumes",
"No volumes found",
component.NewTableCols("Name", "Description", "Size", "Status", "Group", "Type", "Attached To",
"Availability Zone", "Bootable", "Encrypted"), rows)
}
// helper function to create an volume specific gophercloud client
func volumeClientHelper(osp *OpenstackPlugin) *gophercloud.ServiceClient {
client, err := openstack.NewBlockStorageV2(osp.provider, gophercloud.EndpointOpts{})
if err != nil {
log.Fatalf("NewIdentityV3 error: %v", err)
}
return client
}