Skip to content

Commit

Permalink
Add some logging to envtest
Browse files Browse the repository at this point in the history
This adds some logging to envtest, to make it easier to debug oddities
with a testing environment.
  • Loading branch information
DirectXMan12 committed Jan 9, 2019
1 parent 549f806 commit 6101f69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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
9 changes: 9 additions & 0 deletions 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,6 +187,7 @@ 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: %v", numTries, err)
Expand Down

0 comments on commit 6101f69

Please sign in to comment.