Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ type (
Arg = process.Arg
)

var (
// EmptyArguments constructs a new set of flags with nothing set.
//
// This is mostly useful for testing helper methods -- you'll want to call
// Configure on the APIServer (or etcd) to configure their arguments.
EmptyArguments = process.EmptyArguments
)
// EmptyArguments constructs a new set of flags with nothing set.
//
// This is mostly useful for testing helper methods -- you'll want to call
// Configure on the APIServer (or etcd) to configure their arguments.
var EmptyArguments = process.EmptyArguments

// Environment creates a Kubernetes test environment that will start / stop the Kubernetes control plane and
// install extension APIs.
Expand Down Expand Up @@ -341,8 +339,10 @@ func (te *Environment) Start() (*rest.Config, error) {

// Call PrepWithoutInstalling to setup certificates first
// and have them available to patch CRD conversion webhook as well.
if err := te.WebhookInstallOptions.PrepWithoutInstalling(); err != nil {
return nil, err
if webhooksNeeded(te) {
if err := te.WebhookInstallOptions.PrepWithoutInstalling(); err != nil {
return nil, err
}
}

log.V(1).Info("installing CRDs")
Expand All @@ -366,6 +366,18 @@ func (te *Environment) Start() (*rest.Config, error) {
return te.Config, nil
}

func webhooksNeeded(te *Environment) bool {
for _, crd := range te.CRDs {
if crd.Spec.Conversion != nil &&
crd.Spec.Conversion.Webhook != nil {
return true
}
}

return len(te.WebhookInstallOptions.ValidatingWebhooks) > 0 ||
len(te.WebhookInstallOptions.MutatingWebhooks) > 0
}

// AddUser provisions a new user for connecting to this Environment. The user will
// have the specified name & belong to the specified groups.
//
Expand Down
Loading