Skip to content

Commit d681ff8

Browse files
authored
Merge pull request #287 from DirectXMan12/refactor/envtest-err-style-tweak
✨ Fix up error reporting and logging in envtest
2 parents 3913bdc + 6101f69 commit d681ff8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/envtest/crd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func CreateCRDs(config *rest.Config, crds []*apiextensionsv1beta1.CustomResource
174174

175175
// Create each CRD
176176
for _, crd := range crds {
177+
log.V(1).Info("installing CRD", "crd", crd)
177178
if _, err := cs.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd); err != nil {
178179
return err
179180
}
@@ -186,6 +187,7 @@ func readCRDs(path string) ([]*apiextensionsv1beta1.CustomResourceDefinition, er
186187
// Get the CRD files
187188
var files []os.FileInfo
188189
var err error
190+
log.V(1).Info("reading CRDs from path", "path", path)
189191
if files, err = ioutil.ReadDir(path); err != nil {
190192
return nil, err
191193
}
@@ -215,6 +217,7 @@ func readCRDs(path string) ([]*apiextensionsv1beta1.CustomResourceDefinition, er
215217
continue
216218
}
217219

220+
log.V(1).Info("read CRD from file", "file", file)
218221
crds = append(crds, crd)
219222
}
220223
return crds, nil

pkg/envtest/server.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ import (
2626
"k8s.io/client-go/rest"
2727
"sigs.k8s.io/controller-runtime/pkg/client/config"
2828
"sigs.k8s.io/testing_frameworks/integration"
29+
30+
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
2931
)
3032

33+
var log = logf.KBLog.WithName("test-env")
34+
3135
// Default binary path for test framework
3236
const (
3337
envKubeAPIServerBin = "TEST_ASSET_KUBE_APISERVER"
@@ -117,9 +121,11 @@ func (te Environment) getAPIServerFlags() []string {
117121
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
118122
func (te *Environment) Start() (*rest.Config, error) {
119123
if te.UseExistingCluster {
124+
log.V(1).Info("using existing cluster")
120125
if te.Config == nil {
121126
// we want to allow people to pass in their own config, so
122127
// only load a config if it hasn't already been set.
128+
log.V(1).Info("automatically acquiring client configuration")
123129

124130
var err error
125131
te.Config, err = config.GetConfig()
@@ -153,6 +159,7 @@ func (te *Environment) Start() (*rest.Config, error) {
153159
te.ControlPlane.APIServer.StartTimeout = te.ControlPlaneStartTimeout
154160
te.ControlPlane.APIServer.StopTimeout = te.ControlPlaneStopTimeout
155161

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

173+
log.V(1).Info("installing CRDs")
166174
_, err := InstallCRDs(te.Config, CRDInstallOptions{
167175
Paths: te.CRDDirectoryPaths,
168176
CRDs: te.CRDs,
@@ -179,9 +187,10 @@ func (te *Environment) startControlPlane() error {
179187
if err == nil {
180188
break
181189
}
190+
log.Error(err, "unable to start the controlplane", "tries", numTries)
182191
}
183192
if numTries == maxRetries {
184-
return fmt.Errorf("failed to start the controlplane. retried %d times: %s", numTries, err.Error())
193+
return fmt.Errorf("failed to start the controlplane. retried %d times: %v", numTries, err)
185194
}
186195
return nil
187196
}

0 commit comments

Comments
 (0)