Skip to content

Commit

Permalink
Removing Kubectl command for now (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Sipe <[email protected]>
  • Loading branch information
kensipe authored Mar 25, 2020
1 parent d28e406 commit 889c2a9
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 41 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ endif
download:
go mod download

.PHONY: generate
# Generate code
generate:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$$(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools)
endif
controller-gen crd paths=./pkg/apis/... output:crd:dir=config/crds output:stdout
./hack/update_codegen.sh

.PHONY: generate-clean
generate-clean:
rm -rf hack/code-gen

.PHONY: cli
# Build CLI
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/gorilla/mux v1.6.2 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kudobuilder/kudo v0.11.1 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
Expand Down
48 changes: 48 additions & 0 deletions go.sum

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions hack/update_codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

# The following solution for making code generation work with go modules is
# borrowed and modified from https://github.com/heptio/contour/pull/1010.
# it has been modified to enable caching.
export GO111MODULE=on
version_and_repo=$(go list -f '{{if .Replace}}{{.Replace.Version}} {{.Replace.Path}}{{else}}{{.Version}} {{.Path}}{{end}}' -m k8s.io/code-generator)
VERSION="$(echo "${version_and_repo}" | cut -d' ' -f 1 | rev | cut -d"-" -f1 | rev)"
CODEGEN_REPO="$(echo "${version_and_repo}" | cut -d' ' -f 2)"
REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"
CODE_GEN_DIR="${REPO_ROOT}/hack/code-gen/$VERSION"

if [[ -d ${CODE_GEN_DIR} ]]; then
echo "Using cached code generator version: $VERSION"
else
echo "Cloning code-generator from ${CODEGEN_REPO}"
git clone https://${CODEGEN_REPO}.git "${CODE_GEN_DIR}"
git -C "${CODE_GEN_DIR}" reset --hard "${VERSION}"
fi

# Fake being in a $GOPATH until kubernetes fully supports modules
# https://github.com/kudobuilder/kudo/issues/1252
FAKE_GOPATH="$(mktemp -d)"
trap 'chmod -R u+rwX ${FAKE_GOPATH} && rm -rf ${FAKE_GOPATH}' EXIT
FAKE_REPOPATH="${FAKE_GOPATH}/src/github.com/kudobuilder/kuttl"
mkdir -p "$(dirname "${FAKE_REPOPATH}")" && ln -s "${REPO_ROOT}" "${FAKE_REPOPATH}"
export GOPATH="${FAKE_GOPATH}"
cd "${FAKE_REPOPATH}"

"${CODE_GEN_DIR}"/generate-groups.sh \
deepcopy \
github.com/kudobuilder/kuttl/pkg/client \
github.com/kudobuilder/kuttl/pkg/apis \
"testharness:v1beta1" \
--go-header-file hack/boilerplate.go.txt # must be last for some reason
5 changes: 0 additions & 5 deletions pkg/apis/testharness/v1beta1/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ type TestSuite struct {
Parallel int `json:"parallel"`
// The directory to output artifacts to (current working directory if not specified).
ArtifactsDir string `json:"artifactsDir"`
// Kubectl commands to run before running any tests.
Kubectl []string `json:"kubectl"`
// Commands to run prior to running the tests.
Commands []Command `json:"commands"`
}
Expand All @@ -68,9 +66,6 @@ type TestStep struct {
// Indicates that this is a unit test - safe to run without a real Kubernetes cluster.
UnitTest bool `json:"unitTest"`

// Kubectl commands to run at the start of the test
Kubectl []string `json:"kubectl"`

// Commands to run prior at the beginning of the test step.
Commands []Command `json:"commands"`

Expand Down
10 changes: 0 additions & 10 deletions pkg/apis/testharness/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,6 @@ func (h *Harness) Setup() {
h.T.Log("fatal error running commands")
h.fatal(errs)
}

if errs := testutils.RunKubectlCommands(h.GetLogger(), "default", h.TestSuite.Kubectl, ""); len(errs) > 0 {
h.T.Log("fatal error running kubectl commands")
h.fatal(errs)
}
}

// Stop the test environment and clean up the harness.
Expand Down
4 changes: 0 additions & 4 deletions pkg/test/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,6 @@ func (s *Step) Run(namespace string) []error {
if _, errors := testutils.RunCommands(s.Logger, namespace, "", s.Step.Commands, s.Dir); errors != nil {
testErrors = append(testErrors, errors...)
}

if errors := testutils.RunKubectlCommands(s.Logger, namespace, s.Step.Kubectl, s.Dir); errors != nil {
testErrors = append(testErrors, errors...)
}
}

testErrors = append(testErrors, s.Create(namespace)...)
Expand Down
5 changes: 3 additions & 2 deletions pkg/test/test_data/cli-test/00-create-pod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apiVersion: kudo.dev/v1beta1
kind: TestStep
kubectl:
- apply -f ./test_data/pod.yaml
commands:
- command: kubectl apply -f ./test_data/pod.yaml
namespaced: true
15 changes: 0 additions & 15 deletions pkg/test/utils/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,21 +1027,6 @@ func RunCommands(logger Logger, namespace string, command string, commands []har
return bgs, errs
}

// RunKubectlCommands runs a set of kubectl commands, returning any errors.
func RunKubectlCommands(logger Logger, namespace string, commands []string, workdir string) []error {
apiCommands := []harness.Command{}

for _, cmd := range commands {
apiCommands = append(apiCommands, harness.Command{
Command: cmd,
Namespaced: true,
})
}
// ignore background processes as kubectl commands are not allowed to have them
_, errs := RunCommands(logger, namespace, "kubectl", apiCommands, workdir)
return errs
}

// Kubeconfig converts a rest.Config into a YAML kubeconfig and writes it to w
func Kubeconfig(cfg *rest.Config, w io.Writer) error {
var authProvider *api.AuthProviderConfig
Expand Down

0 comments on commit 889c2a9

Please sign in to comment.