Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrt committed Jun 30, 2022
1 parent 455acb7 commit d0cbd36
Show file tree
Hide file tree
Showing 19 changed files with 2,406 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
openshift-provider-cert
kubeconfig
.idea/
8 changes: 4 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Apache License

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

Expand Down Expand Up @@ -178,15 +179,15 @@ Apache License
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -199,4 +200,3 @@ Apache License
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Ensure go modules are enabled:
export GO111MODULE=on

# Disable CGO so that we always generate static binaries:
export CGO_ENABLED=0

VERSION=$(shell git rev-parse HEAD)
RELEASE_TAG ?= "0.0.0"

GO_BUILD_FLAGS := -ldflags '-X github.com/openshift/provider-certification-tool/version.commit=$(VERSION) -X github.com/openshift/provider-certification-tool/version.version=$(RELEASE_TAG)'

# Unset GOFLAG for CI and ensure we've got nothing accidently set
unexport GOFLAGS

.PHONY: build
build:
go build -o openshift-provider-cert $(GO_BUILD_FLAGS)

.PHONY: cross-build-windows-amd64
cross-build-windows-amd64:
GOOS=windows GOARCH=amd64 go build -o openshift-provider-cert.exe $(GO_BUILD_FLAGS)

.PHONY: cross-build-darwin-amd64
cross-build-darwin-amd64:
GOOS=darwin GOARCH=amd64 go build -o openshift-provider-cert $(GO_BUILD_FLAGS)

.PHONY: cross-build-darwin-arm64
cross-build-darwin-arm64:
GOOS=darwin GOARCH=arm64 go build -o openshift-provider-cert $(GO_BUILD_FLAGS)


.PHONY: test
test:
go test ./...

.PHONY: vet
vet:
go vet ./...


.PHONY: clean
clean:
rm -rf \
openshift-provider-cert
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# openshift-provider-certification
# OpenShift Provider Certification Tool

OpenShift Provider Certification Tool
OpenShift Provider Certification Tool is used to evaluate an OpenShift installation on a provider or hardware is in conformance

```shell
Usage:
openshift-provider-cert [command]

Available Commands:
completion Generate the autocompletion script for the specified shell
destroy Destroy current Certification Environment
help Help about any command
results Summary of certification results archive
retrieve Collect results from certification environment
run Run the suite of tests for provider certification
sonobuoy Generate reports on your Kubernetes cluster by running plugins
status Show the current status of the certification tool

Flags:
-h, --help help for openshift-provider-cert
--kubeconfig string kubeconfig for target OpenShift cluster
-v, --version version for openshift-provider-cert

Use "openshift-provider-cert [command] --help" for more information about a command.
```

## Building

- Go 1.17+ is needed.
- To build openshift provider cert tool invoke `make`.
- Cross build make targets are also available for Windows and MacOS. See [Makefile](./Makefile) for more on this.

## Dependencies

Dependencies are managed through Go Modules. When updating any dependency the suggested workflow is:

```shell
go mod tidy
go mod vendor
```
82 changes: 82 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cmd

import (
"fmt"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vmware-tanzu/sonobuoy/cmd/sonobuoy/app"
"github.com/vmware-tanzu/sonobuoy/pkg/client"
sonodynamic "github.com/vmware-tanzu/sonobuoy/pkg/dynamic"
"k8s.io/client-go/tools/clientcmd"

"github.com/openshift/provider-certification-tool/pkg"
"github.com/openshift/provider-certification-tool/pkg/destroy"
"github.com/openshift/provider-certification-tool/pkg/results"
"github.com/openshift/provider-certification-tool/pkg/retrieve"
"github.com/openshift/provider-certification-tool/pkg/run"
"github.com/openshift/provider-certification-tool/pkg/status"
"github.com/openshift/provider-certification-tool/version"
)

var (
config = &pkg.Config{}
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "openshift-provider-cert",
Short: "OpenShift Provider Certification Tool",
Long: `OpenShift Provider Certification Tool is used to evaluate an OpenShift installation on a provider or hardware is in conformance`,
Version: version.Version.String(),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var err error

config.Kubeconfig = viper.GetString("kubeconfig")
config.ClientConfig, err = clientcmd.BuildConfigFromFlags("", config.Kubeconfig)
if err != nil {
return err
}

skc, err := sonodynamic.NewAPIHelperFromRESTConfig(config.ClientConfig)
if err != nil {
return errors.Wrap(err, "couldn't get sonobuoy api helper")
}

config.SonobuoyClient, err = client.NewSonobuoyClient(config.ClientConfig, skc)

return nil
},
}

// 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 Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().String("kubeconfig", "", "kubeconfig for target OpenShift cluster")
viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig"))

// Link in child commands
rootCmd.AddCommand(destroy.NewCmdDestroy(config))
rootCmd.AddCommand(results.NewCmdResults(config))
rootCmd.AddCommand(retrieve.NewCmdRetrieve(config))
rootCmd.AddCommand(run.NewCmdRun(config))
rootCmd.AddCommand(status.NewCmdStatus(config))

rootCmd.AddCommand(app.NewSonobuoyCommand())
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
viper.AutomaticEnv() // read in environment variables that match
}
63 changes: 63 additions & 0 deletions doc/dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Provider Certification Tool
## Development Notes

This tool builds heavily on
[Sonobuoy](https://sonobuoy.io) therefore at least
some high level knowledge of Sonobuoy is needed to really understand this tool. A
good place to start with Sonobuoy is [its product docs](https://sonobuoy.io/docs).

The OpenShift provider certification tool extends Sonobuoy in two places:

- Command line interface (CLI)
- Plugins

### Command Line Interface

Sonobuoy provides its own CLI but it has a considerable number of flags and options
which can be overwhelming. This isn't an issue with Sonobuoy, it's just a symptom
of being a very flexible tool. However, for simplicity sake, the OpenShift
certification tool extends the Sonobuoy CLI with some strong opinions specific
to the realm certifying OpenShift on new infrastructure.

#### Integration with Sonobuoy CLI
The OpenShift provider certification tool's CLI is written in Golang so that extending
Sonobuoy could be done easily. Sonobuoy has two specific areas on which we build:

- Cobra commands (e.g. [sonobuoy run](https://github.com/vmware-tanzu/sonobuoy/blob/87e26ab7d2113bd32832a7bd70c2553ec31b2c2e/cmd/sonobuoy/app/run.go#L47-L62))
- Sonobuoy Client ([source code](https://github.com/vmware-tanzu/sonobuoy/blob/87e26ab7d2113bd32832a7bd70c2553ec31b2c2e/pkg/client/interfaces.go#L246-L250))

Some of this tool's commands will interact with the Sonobuoy Client directly
(this is ideal) but in some situations, like with this tools' `run` command,
the similar Cobra command in Sonobuoy is used. This adds some odd interaction but
is necessarily as some complex code is present in Sonobuoy's Run command
implementation.

This direct usage of Sonobuoy's Cobra commands should be avoided since that
creates and odd development experience and the ability to cleanly set Sonobuoy's
flags is muddied by code like this:

```golang
// Not Great
runCmd.Flags().Set("dns-namespace", "openshift-dns")
runCmd.Flags().Set("kubeconfig", r.config.Kubeconfig)
```

Once there is more confidence or just understanding of the Sonobuoy Client code
then the OpenShift provider certification tool's commands should all be using it.
Like this:

```golang
// Great
reader, ec, err := config.SonobuoyClient.RetrieveResults(&client.RetrieveConfig{
Namespace: "sonobuoy",
Path: config2.AggregatorResultsPath,
})
```

### Sonobuoy Plugins

*TODO* (Cert tool's plugin development is still in POC phase)

### Diagrams

*TODO* (These will be completed after code review and CLI structure is more finalized)
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/openshift/provider-certification-tool

go 1.16

require (
github.com/adrg/xdg v0.4.0
github.com/openshift/api v0.0.0-20210910062324-a41d3573a3ba // indirect
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.11.0
github.com/vmware-tanzu/sonobuoy v0.56.5
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
k8s.io/api v0.23.6
k8s.io/apimachinery v0.23.6
k8s.io/client-go v0.23.6
)

0 comments on commit d0cbd36

Please sign in to comment.