Skip to content

Commit

Permalink
Merge pull request #287 from DirectXMan12/refactor/envtest-err-style-…
Browse files Browse the repository at this point in the history
…tweak

✨ Fix up error reporting and logging in envtest
  • Loading branch information
k8s-ci-robot committed Jan 9, 2019
2 parents 3913bdc + 6101f69 commit d681ff8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/envtest/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func CreateCRDs(config *rest.Config, crds []*apiextensionsv1beta1.CustomResource

// Create each CRD
for _, crd := range crds {
log.V(1).Info("installing CRD", "crd", crd)
if _, err := cs.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd); err != nil {
return err
}
Expand All @@ -186,6 +187,7 @@ func readCRDs(path string) ([]*apiextensionsv1beta1.CustomResourceDefinition, er
// Get the CRD files
var files []os.FileInfo
var err error
log.V(1).Info("reading CRDs from path", "path", path)
if files, err = ioutil.ReadDir(path); err != nil {
return nil, err
}
Expand Down Expand Up @@ -215,6 +217,7 @@ func readCRDs(path string) ([]*apiextensionsv1beta1.CustomResourceDefinition, er
continue
}

log.V(1).Info("read CRD from file", "file", file)
crds = append(crds, crd)
}
return crds, nil
Expand Down
11 changes: 10 additions & 1 deletion pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ import (
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/testing_frameworks/integration"

logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)

var log = logf.KBLog.WithName("test-env")

// Default binary path for test framework
const (
envKubeAPIServerBin = "TEST_ASSET_KUBE_APISERVER"
Expand Down Expand Up @@ -117,9 +121,11 @@ func (te Environment) getAPIServerFlags() []string {
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
func (te *Environment) Start() (*rest.Config, error) {
if te.UseExistingCluster {
log.V(1).Info("using existing cluster")
if te.Config == nil {
// we want to allow people to pass in their own config, so
// only load a config if it hasn't already been set.
log.V(1).Info("automatically acquiring client configuration")

var err error
te.Config, err = config.GetConfig()
Expand Down Expand Up @@ -153,6 +159,7 @@ func (te *Environment) Start() (*rest.Config, error) {
te.ControlPlane.APIServer.StartTimeout = te.ControlPlaneStartTimeout
te.ControlPlane.APIServer.StopTimeout = te.ControlPlaneStopTimeout

log.V(1).Info("starting control plane", "api server flags", te.ControlPlane.APIServer.Args)
if err := te.startControlPlane(); err != nil {
return nil, err
}
Expand All @@ -163,6 +170,7 @@ func (te *Environment) Start() (*rest.Config, error) {
}
}

log.V(1).Info("installing CRDs")
_, err := InstallCRDs(te.Config, CRDInstallOptions{
Paths: te.CRDDirectoryPaths,
CRDs: te.CRDs,
Expand All @@ -179,9 +187,10 @@ func (te *Environment) startControlPlane() error {
if err == nil {
break
}
log.Error(err, "unable to start the controlplane", "tries", numTries)
}
if numTries == maxRetries {
return fmt.Errorf("failed to start the controlplane. retried %d times: %s", numTries, err.Error())
return fmt.Errorf("failed to start the controlplane. retried %d times: %v", numTries, err)
}
return nil
}
Expand Down

0 comments on commit d681ff8

Please sign in to comment.