Skip to content

Commit

Permalink
feat!: remove create cli subcommand (knative#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland committed Nov 6, 2020
1 parent ddbb95b commit 57e1236
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 368 deletions.
63 changes: 23 additions & 40 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 @@ -247,20 +237,14 @@ func WithRegistry(registry string) Option {
}
}

// Create a Function.
// Includes Initialization, Building, and Deploying.
func (c *Client) Create(cfg Function) (err error) {
c.progressListener.SetTotal(4)
// New Function.
// Use Create, Build and Deploy independently for lower level control.
func (c *Client) New(cfg Function) (err error) {
c.progressListener.SetTotal(3)
defer c.progressListener.Done()

// Initialize, writing out a template implementation and a config file.
// TODO: the Function's Initialize parameters are slightly different than
// the Initializer interface, and can thus cause confusion (one passes an
// optional name the other passes root path). This could easily cause
// confusion and thus we may want to rename Initalizer to the more specific
// task it performs: ContextTemplateWriter or similar.
c.progressListener.Increment("Initializing new Function project")
err = c.Initialize(cfg)
// Create local template
err = c.Create(cfg)
if err != nil {
return
}
Expand Down Expand Up @@ -290,7 +274,7 @@ func (c *Client) Create(cfg Function) (err error) {
return
}

c.progressListener.Complete("Create complete")
c.progressListener.Complete("Done")

// TODO: use the knative client during deployment such that the actual final
// route can be returned from the deployment step, passed to the DNS Router
Expand All @@ -301,9 +285,9 @@ func (c *Client) Create(cfg Function) (err error) {
return
}

// Initialize creates a new Function project locally using the settings
// provided on a Function object.
func (c *Client) Initialize(cfg Function) (err error) {
// Create a new Function project locally using the settings provided on a
// Function object.
func (c *Client) Create(cfg Function) (err error) {

// Create project root directory, if it doesn't already exist
if err = os.MkdirAll(cfg.Root, 0755); err != nil {
Expand All @@ -322,9 +306,8 @@ func (c *Client) Initialize(cfg Function) (err error) {
return
}

// Map requested fields to the newly created function.
f.Image = cfg.Image

// Set the name to that provided.
f.Name = cfg.Name

// Assert runtime was provided, or default.
Expand Down
Loading

0 comments on commit 57e1236

Please sign in to comment.