Skip to content

Commit

Permalink
Merge branch 'main' into lkingland/client-config-options
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland committed Mar 24, 2022
2 parents 1819efe + 9a6aaa5 commit 9f6bdd1
Show file tree
Hide file tree
Showing 86 changed files with 18,953 additions and 17,944 deletions.
3 changes: 3 additions & 0 deletions CODE-OF-CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Knative Community Code of Conduct

The [Knative Community Code of Conduct](https://github.com/knative/community/blob/main/CODE-OF-CONDUCT.md) is defined in the [Knative community repository](https://github.com/knative/community).
17 changes: 17 additions & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,21 @@ aliases:
- devguyio
- lionelvillard
eventing-writers:
- aliok
- devguyio
- lionelvillard
- matzew
- odacremolbap
- pierDipi
- vaikas
func-tastic-approvers:
- lance
- lkingland
- matejvasek
- nainaz
- omerbensaadon
- salaboy
- zroubalik
homebrew-kn-plugins-approvers:
- dsimansk
- maximilien
Expand Down Expand Up @@ -234,8 +247,12 @@ aliases:
- chizhg
productivity-writers:
- cardil
- chaodaiG
- chizhg
- coryrc
- kvmware
- psschwei
- upodroid
security-wg-leads:
- evankanderson
- julz
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (builder *Builder) Build(ctx context.Context, f fn.Function) (err error) {
return
} else if !builder.verbose {
// If the builder was not showing logs, embed the full logs in the error.
err = fmt.Errorf("%v\noutput: %s\n", err, logWriter.(*bytes.Buffer).String())
err = fmt.Errorf("failed to build the function (output: %q): %w", logWriter.(*bytes.Buffer).String(), err)
}
}

Expand Down
10 changes: 6 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func ConfigPath() (path string) {

// RepositoriesPath accesses the currently effective repositories path,
// which defaults to [ConfigPath]/repositories but can be set explicitly using
// the WithRepositories option when creating the client..
// the WithRepositoriesPath option when creating the client..
// The path will be created if it does not already exist.
func (c *Client) RepositoriesPath() (path string) {
path = c.repositories.Path()
Expand All @@ -256,7 +256,7 @@ func (c *Client) RepositoriesPath() (path string) {

// RepositoriesPath is a convenience method for accessing the default path to
// repositories that will be used by new instances of a Client unless options
// such as WithRepositories are used to override.
// such as WithRepositoriesPath are used to override.
// The path will be created if it does not already exist.
func RepositoriesPath() string {
return New().RepositoriesPath()
Expand Down Expand Up @@ -342,10 +342,10 @@ func WithDNSProvider(provider DNSProvider) Option {
}
}

// WithRepositories sets the location to use for extensible template
// WithRepositoriesPath sets the location on disk to use for extensible template
// repositories. Extensible template repositories are additional templates
// that exist on disk and are not built into the binary.
func WithRepositories(path string) Option {
func WithRepositoriesPath(path string) Option {
return func(c *Client) {
c.repositoriesPath = path
}
Expand Down Expand Up @@ -700,13 +700,15 @@ func (c *Client) RunPipeline(ctx context.Context, path string, git Git) (err err

f, err := NewFunction(path)
if err != nil {
err = fmt.Errorf("failed to laod function: %w", err)
return
}
f.Git = git

// Build and deploy function using Pipeline
err = c.pipelinesProvider.Run(ctx, f)
if err != nil {
err = fmt.Errorf("failed to run pipeline: %w", err)
return
}

Expand Down
14 changes: 7 additions & 7 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,17 @@ func TestClient_New_HiddenFilesIgnored(t *testing.T) {
// using a custom path to template repositories on disk. The custom repositories
// location is not defined herein but expected to be provided because, for
// example, a CLI may want to use XDG_CONFIG_HOME. Assuming a repository path
// $FUNC_REPOSITORIES, a Go template named 'json' which is provided in the
// $FUNC_REPOSITORIES_PATH, a Go template named 'json' which is provided in the
// repository 'boson', would be expected to be in the location:
// $FUNC_REPOSITORIES/boson/go/json
// $FUNC_REPOSITORIES_PATH/boson/go/json
// See the CLI for full details, but a standard default location is
// $HOME/.config/func/repositories/boson/go/json
func TestClient_New_RepositoriesExtensible(t *testing.T) {
root := "testdata/example.com/testRepositoriesExtensible"
defer Using(t, root)()

client := fn.New(
fn.WithRepositories("testdata/repositories"),
fn.WithRepositoriesPath("testdata/repositories"),
fn.WithRegistry(TestRegistry))

// Create a Function specifying a template which only exists in the extensible set
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestClient_New_RuntimeNotFoundCustom(t *testing.T) {

// Create a new client with path to the extensible templates
client := fn.New(
fn.WithRepositories("testdata/repositories"),
fn.WithRepositoriesPath("testdata/repositories"),
fn.WithRegistry(TestRegistry))

// Create a Function specifying a runtime, 'python' that does not exist
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestClient_New_TemplateNotFoundCustom(t *testing.T) {

// Create a new client with path to extensible templates
client := fn.New(
fn.WithRepositories("testdata/repositories"),
fn.WithRepositoriesPath("testdata/repositories"),
fn.WithRegistry(TestRegistry))

// An invalid template, but a valid custom provider
Expand Down Expand Up @@ -1005,7 +1005,7 @@ func TestClient_Runtimes(t *testing.T) {
// TODO: test when a specific repo override is indicated
// (remote repo which takes precidence over embedded and extended)

client := fn.New(fn.WithRepositories("testdata/repositories"))
client := fn.New(fn.WithRepositoriesPath("testdata/repositories"))

runtimes, err := client.Runtimes()
if err != nil {
Expand Down Expand Up @@ -1112,7 +1112,7 @@ func TestClient_Invoke_HTTP(t *testing.T) {
}
s := http.Server{Handler: handler}
go func() {
if err = s.Serve(l); err != nil && err != http.ErrServerClosed {
if err = s.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) {
fmt.Fprintf(os.Stderr, "error serving: %v", err)
}
}()
Expand Down
6 changes: 3 additions & 3 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func ValidNamespaceAndRegistry(path string) survey.Validator {
_, err := fn.DerivedImage(path, val.(string)) //image can be derived without any error

if err != nil {
return fmt.Errorf("Invalid registry [%s] %v", val.(string), err)
return fmt.Errorf("invalid registry [%q]: %w", val.(string), err)
}
return nil
}
Expand All @@ -83,7 +83,7 @@ func ValidNamespaceAndRegistry(path string) survey.Validator {
func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err error) {
config, err := newBuildConfig().Prompt()
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand Down Expand Up @@ -118,7 +118,7 @@ func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err erro
&survey.Input{Message: "Registry for Function images:"},
&config.Registry, survey.WithValidator(ValidNamespaceAndRegistry(config.Path)))
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand Down
7 changes: 4 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -29,7 +30,7 @@ type standardLoaderSaver struct{}
func (s standardLoaderSaver) Load(path string) (fn.Function, error) {
f, err := fn.NewFunction(path)
if err != nil {
return fn.Function{}, err
return fn.Function{}, fmt.Errorf("failed to create new function (path: %q): %w", path, err)
}
if !f.Initialized() {
return fn.Function{}, fmt.Errorf("the given path '%v' does not contain an initialized function", path)
Expand Down Expand Up @@ -101,7 +102,7 @@ func runConfigCmd(cmd *cobra.Command, args []string) (err error) {

err = survey.Ask(qs, &answers)
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand Down Expand Up @@ -163,7 +164,7 @@ func initConfigCommand(args []string, loader functionLoader) (fn.Function, error

function, err := loader.Load(config.Path)
if err != nil {
return fn.Function{}, err
return fn.Function{}, fmt.Errorf("failed to load the function (path: %q): %w", config.Path, err)
}

return function, nil
Expand Down
17 changes: 9 additions & 8 deletions cmd/config_envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -132,7 +133,7 @@ func runAddEnvsPrompt(ctx context.Context, f fn.Function) (err error) {
}
err = survey.AskOne(prompt, &selectedEnv)
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand All @@ -147,11 +148,11 @@ func runAddEnvsPrompt(ctx context.Context, f fn.Function) (err error) {
}

// SECTION - select the type of Environment variable to be added
secrets, err := k8s.ListSecretsNames(ctx, f.Namespace)
secrets, err := k8s.ListSecretsNamesIfConnected(ctx, f.Namespace)
if err != nil {
return
}
configMaps, err := k8s.ListConfigMapsNames(ctx, f.Namespace)
configMaps, err := k8s.ListConfigMapsNamesIfConnected(ctx, f.Namespace)
if err != nil {
return
}
Expand Down Expand Up @@ -181,7 +182,7 @@ func runAddEnvsPrompt(ctx context.Context, f fn.Function) (err error) {
Options: options,
}, &selectedOption)
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand Down Expand Up @@ -212,7 +213,7 @@ func runAddEnvsPrompt(ctx context.Context, f fn.Function) (err error) {

err = survey.Ask(qs, &answers)
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand Down Expand Up @@ -244,7 +245,7 @@ func runAddEnvsPrompt(ctx context.Context, f fn.Function) (err error) {

err = survey.Ask(qs, &answers)
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand All @@ -266,7 +267,7 @@ func runAddEnvsPrompt(ctx context.Context, f fn.Function) (err error) {
Options: configMaps,
}, &selectedResource)
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand Down Expand Up @@ -308,7 +309,7 @@ func runAddEnvsPrompt(ctx context.Context, f fn.Function) (err error) {

err = survey.Ask(qs, &answers)
if err != nil {
if err == terminal.InterruptErr {
if errors.Is(err, terminal.InterruptErr) {
return nil
}
return
Expand Down
4 changes: 2 additions & 2 deletions cmd/config_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func listVolumes(f fn.Function) {

func runAddVolumesPrompt(ctx context.Context, f fn.Function) (err error) {

secrets, err := k8s.ListSecretsNames(ctx, f.Namespace)
secrets, err := k8s.ListSecretsNamesIfConnected(ctx, f.Namespace)
if err != nil {
return
}
configMaps, err := k8s.ListConfigMapsNames(ctx, f.Namespace)
configMaps, err := k8s.ListConfigMapsNamesIfConnected(ctx, f.Namespace)
if err != nil {
return
}
Expand Down
Loading

0 comments on commit 9f6bdd1

Please sign in to comment.