Skip to content

Commit

Permalink
src: remove vestigial domain search limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland committed Nov 5, 2020
1 parent 93a192a commit 5dedbba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 58 deletions.
42 changes: 15 additions & 27 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ const (

// Client for managing Function instances.
type Client struct {
verbose bool // print verbose logs
builder Builder // Builds a runnable image from Function source
pusher Pusher // Pushes the image assocaited with a Function.
deployer Deployer // Deploys or Updates a Function
runner Runner // Runs the Function locally
remover Remover // Removes remote services
lister Lister // Lists remote services
describer Describer
dnsProvider DNSProvider // Provider of DNS services
templates string // path to extensible templates
registry string // default registry for OCI image tags
domainSearchLimit int // max recursion when deriving domain
progressListener ProgressListener // progress listener
verbose bool // print verbose logs
builder Builder // Builds a runnable image from Function source
pusher Pusher // Pushes the image assocaited with a Function.
deployer Deployer // Deploys or Updates a Function
runner Runner // Runs the Function locally
remover Remover // Removes remote services
lister Lister // Lists remote services
describer Describer
dnsProvider DNSProvider // Provider of DNS services
templates string // path to extensible templates
registry string // default registry for OCI image tags
progressListener ProgressListener // progress listener
}

// Builder of Function source to runnable image.
Expand Down Expand Up @@ -219,15 +218,6 @@ func WithDNSProvider(provider DNSProvider) Option {
}
}

// WithDomainSearchLimit sets the maximum levels of upward recursion used when
// attempting to derive effective DNS name from root path. Ignored if DNS was
// explicitly set via WithName.
func WithDomainSearchLimit(limit int) Option {
return func(c *Client) {
c.domainSearchLimit = limit
}
}

// WithTemplates sets the location to use for extensible templates.
// Extensible templates are additional templates that exist on disk and are
// not built into the binary.
Expand All @@ -248,14 +238,12 @@ func WithRegistry(registry string) Option {
}

// New Function.
// Complete creation of a Function. Creates a new deployed, available Function.
// Invokes Create, Build and Deploy.
// Use Create, Build and Deploy independently for lower level control.
func (c *Client) New(cfg Function) (err error) {
c.progressListener.SetTotal(4)
c.progressListener.SetTotal(3)
defer c.progressListener.Done()

// Create local source, writing out a template and a config file.
c.progressListener.Increment("Creating Function locally")
// Create local template
err = c.Create(cfg)
if err != nil {
return
Expand Down
33 changes: 3 additions & 30 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,6 @@ func TestExtensibleTemplates(t *testing.T) {
}
}

// TestCreateUnderivableName ensures that attempting to create a new Function
// when the name is underivable (and no explicit name is provided) generates
// an error.
func TestUnderivableName(t *testing.T) {
root := "testdata/example.com/testUnderivableName"
if err := os.MkdirAll(root, 0700); err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root)

// Instantiation without an explicit service name, but no derivable service
// name (because of limiting path recursion) should fail.
client := faas.New(faas.WithDomainSearchLimit(0))

// create a Function with a missing name, but when the name is
// underivable (in this case due to limited recursion, but would equally
// apply if run from /tmp or similar)
if err := client.New(faas.Function{Root: root}); err == nil {
t.Fatal("did not receive error creating with underivable name")
}
}

// TestUnsupportedRuntime generates an error.
func TestUnsupportedRuntime(t *testing.T) {
// Create a directory for the Function
Expand Down Expand Up @@ -264,7 +242,7 @@ func TestNamed(t *testing.T) {
}
}

// TestBuildRegistryRequired ensures that a registry is required, and is
// TestRegistryRequired ensures that a registry is required, and is
// prepended with the DefaultRegistry if a single token.
// Registry is the namespace at the container image registry.
// If not prepended with the registry, it will be defaulted:
Expand Down Expand Up @@ -681,13 +659,8 @@ func TestList(t *testing.T) {
func TestListOutsideRoot(t *testing.T) {
lister := mock.NewLister()

// Instantiate in the current working directory, with no name, and explicitly
// disallowing name path inferrence by limiting recursion. This emulates
// running the client (and subsequently list) from some arbitrary location
// without a derivable funciton context.
client := faas.New(
faas.WithDomainSearchLimit(0),
faas.WithLister(lister))
// Instantiate in the current working directory, with no name.
client := faas.New(faas.WithLister(lister))

if _, err := client.List(); err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func runCreate(cmd *cobra.Command, args []string) error {
faas.WithTemplates(config.Templates),
faas.WithVerbose(config.Verbose))

return client.Initialize(function)
return client.Create(function)
}

type createConfig struct {
Expand Down

0 comments on commit 5dedbba

Please sign in to comment.