Skip to content

Commit 541e858

Browse files
authored
feat: function name matches KService name (#317)
* feat: function name matches KService name Signed-off-by: Zbynek Roubalik <zroubali@redhat.com> * fix typo Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
1 parent 36926ac commit 541e858

15 files changed

+117
-208
lines changed

client.go

-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ type ListItem struct {
7979
Namespace string `json:"namespace" yaml:"namespace"`
8080
Runtime string `json:"runtime" yaml:"runtime"`
8181
URL string `json:"url" yaml:"url"`
82-
KService string `json:"kservice" yaml:"kservice"`
8382
Ready string `json:"ready" yaml:"ready"`
8483
}
8584

@@ -108,7 +107,6 @@ type Describer interface {
108107
type Description struct {
109108
Name string `json:"name" yaml:"name"`
110109
Image string `json:"image" yaml:"image"`
111-
KService string `json:"kservice" yaml:"kservice"`
112110
Namespace string `json:"namespace" yaml:"namespace"`
113111
Routes []string `json:"routes" yaml:"routes"`
114112
Subscriptions []Subscription `json:"subscriptions" yaml:"subscriptions"`

cmd/create.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ kn func create --trigger events myfunc
5252
}
5353

5454
func runCreate(cmd *cobra.Command, args []string) error {
55-
config := newCreateConfig(args).Prompt()
55+
config := newCreateConfig(args)
56+
57+
if err := utils.ValidateFunctionName(config.Name); err != nil {
58+
return err
59+
}
60+
61+
config = config.Prompt()
5662

5763
function := bosonFunc.Function{
5864
Name: config.Name,
@@ -131,12 +137,21 @@ func (c createConfig) Prompt() createConfig {
131137
return c
132138
}
133139

134-
derivedName, derivedPath := deriveNameAndAbsolutePathFromPath(prompt.ForString("Project path", c.Path, prompt.WithRequired(true)))
140+
var derivedName, derivedPath string
141+
for {
142+
derivedName, derivedPath = deriveNameAndAbsolutePathFromPath(prompt.ForString("Project path", c.Path, prompt.WithRequired(true)))
143+
err := utils.ValidateFunctionName(derivedName)
144+
if err == nil {
145+
break
146+
}
147+
fmt.Println("Error:", err)
148+
}
149+
135150
return createConfig{
136151
Name: derivedName,
137152
Path: derivedPath,
138153
Runtime: prompt.ForString("Runtime", c.Runtime),
139154
Trigger: prompt.ForString("Trigger", c.Trigger),
140-
// Templates intentiopnally omitted from prompt for being an edge case.
155+
// Templates intentionally omitted from prompt for being an edge case.
141156
}
142157
}

cmd/describe.go

-3
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ func (d description) Human(w io.Writer) error {
116116
fmt.Fprintf(w, " %v\n", d.Name)
117117
fmt.Fprintln(w, "Function is built in image:")
118118
fmt.Fprintf(w, " %v\n", d.Image)
119-
fmt.Fprintln(w, "Function is deployed as Knative Service:")
120-
fmt.Fprintf(w, " %v\n", d.KService)
121119
fmt.Fprintln(w, "Function is deployed in namespace:")
122120
fmt.Fprintf(w, " %v\n", d.Namespace)
123121
fmt.Fprintln(w, "Routes:")
@@ -138,7 +136,6 @@ func (d description) Human(w io.Writer) error {
138136
func (d description) Plain(w io.Writer) error {
139137
fmt.Fprintf(w, "Name %v\n", d.Name)
140138
fmt.Fprintf(w, "Image %v\n", d.Image)
141-
fmt.Fprintf(w, "Knative Service %v\n", d.KService)
142139
fmt.Fprintf(w, "Namespace %v\n", d.Namespace)
143140

144141
for _, route := range d.Routes {

cmd/list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ func (items listItems) Plain(w io.Writer) error {
117117
tabWriter := tabwriter.NewWriter(w, 0, 8, 2, ' ', 0)
118118
defer tabWriter.Flush()
119119

120-
fmt.Fprintf(tabWriter, "%s\t%s\t%s\t%s\t%s\t%s\n", "NAME", "NAMESPACE", "RUNTIME", "URL", "KSERVICE", "READY")
120+
fmt.Fprintf(tabWriter, "%s\t%s\t%s\t%s\t%s\n", "NAME", "NAMESPACE", "RUNTIME", "URL", "READY")
121121
for _, item := range items {
122-
fmt.Fprintf(tabWriter, "%s\t%s\t%s\t%s\t%s\t%s\n", item.Name, item.Namespace, item.Runtime, item.URL, item.KService, item.Ready)
122+
fmt.Fprintf(tabWriter, "%s\t%s\t%s\t%s\t%s\n", item.Name, item.Namespace, item.Runtime, item.URL, item.Ready)
123123
}
124124
return nil
125125
}

docs/guides/commands.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Creates a new Function project at _`path`_. If _`path`_ is unspecified, assumes the current directory. If _`path`_ does not exist, it will be created. The function name is the name of the leaf directory at path. The user can specify the runtime and trigger with flags.
66

7+
Function name must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?').
8+
79
Similar `kn` command: none.
810

911
```console

docs/guides/developers_tutorial.md

+24-18
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ The unit of deployment in Boson Functions is an [OCI](https://opencontainers.org
4545
container image, typically referred to as a Docker container image.
4646

4747
In order for the `func` CLI to manage these containers, you'll need to be
48-
logged in to a container registry. For example, `docker.io/lanceball`
48+
logged in to a container registry. For example, `docker.io/developer`
4949

5050

5151
```bash
5252
# Typically, this will log you in to docker hub if you
5353
# omit <registry.url>. If you are using a registry
5454
# other than Docker hub, provide that for <registry.url>
55-
docker login -u lanceball -p [redacted] <registry.url>
55+
docker login -u developer -p [redacted] <registry.url>
5656
```
5757

5858
> Note: many of the `func` CLI commands take a `--registry` argument.
@@ -62,20 +62,21 @@ docker login -u lanceball -p [redacted] <registry.url>
6262
```bash
6363
# This should be set to a registry that you have write permission
6464
# on and you have logged into in the previous step.
65-
export FUNC_REGISTRY=docker.io/lanceball
65+
export FUNC_REGISTRY=docker.io/developer
6666
```
6767

6868
## Creating a Project
6969

7070
With your Knative enabled cluster up and running, you can now create a new
71-
Function Project. Let's start by creating a project directory. Function names
72-
in `func` correspond to URLs at the moment, and there are some finicky cases
73-
at the moment. To ensure that everything works as it should, create a project
74-
directory consisting of three URL parts. Here is a good one.
71+
Function Project. Let's start by creating a project directory. Function name
72+
must consist of lower case alphanumeric characters or '-',
73+
and must start and end with an alphanumeric character
74+
(e.g. 'my-name', or '123-abc', regex used for validation is `[a-z0-9]([-a-z0-9]*[a-z0-9])?`).
75+
7576

7677
```bash
77-
mkdir fn.example.io
78-
cd fn.example.io
78+
mkdir fn-example-io
79+
cd fn-example-io
7980
```
8081

8182
Now, we will create the project files, build a container, and
@@ -84,7 +85,6 @@ deploy the function as a Knative service.
8485

8586
```bash
8687
func create -l node
87-
func build
8888
func deploy
8989
```
9090

@@ -93,9 +93,15 @@ all of the defaults inferred from your environment, for example`$FUNC_REGISTRY`.
9393
When the command has completed, you can see the deployed function.
9494

9595
```bash
96-
kn service list
97-
NAME URL LATEST AGE CONDITIONS READY REASON
98-
fn-example-io http://fn-example-io.func.127.0.0.1.nip.io fn-example-io-ngswh-1 24s 3 OK / 3 True
96+
func describe
97+
Function name:
98+
fn-example-io
99+
Function is built in image:
100+
docker.io/developer/fn-example-io:latest
101+
Function is deployed in namespace:
102+
default
103+
Routes:
104+
http://fn-example-io-default.apps.functions.my-cluster.com
99105
```
100106

101107
Clicking on the URL will take you to the running function in your cluster. You
@@ -108,7 +114,7 @@ should see a simple response.
108114
You can add query parameters to the request to see those echoed in return.
109115

110116
```console
111-
curl "http://fn-example-io.func.127.0.0.1.nip.io?name=tiger"
117+
curl "http://fn-example-io-default.apps.functions.my-cluster.com?name=tiger"
112118
{"query":{"name":"tiger"},"name":"tiger"}
113119
```
114120

@@ -150,7 +156,7 @@ You might see a message such as this.
150156
Error: remover failed to delete the service: timeout: service 'fn-example-io' not ready after 30 seconds.
151157
```
152158

153-
If you do, just run `kn service list` to see if the function is still deployed.
159+
If you do, just run `func list` to see if the function is still deployed.
154160
It might just take a little time for it to be removed.
155161

156162
Now, let's clean up the current directory.
@@ -168,9 +174,9 @@ cluster, use the `create` command.
168174
func create -l node -t http
169175
```
170176

171-
You can also create a Quarkus or a Golang project by providing `quarkus` or `go`
172-
respectively to the `-l` flag. To create a project with a template for
173-
CloudEvents, provide `events` to the `-t` flag.
177+
You can also create a Quarkus, SpringBoot, Python or a Golang project by providing
178+
`quarkus`, `springboot`, `python` or `go` respectively to the `-l` flag.
179+
To create a project with a template for CloudEvents, provide `events` to the `-t` flag.
174180

175181
### `func build`
176182

k8s/names.go

-77
This file was deleted.

k8s/names_test.go

-58
This file was deleted.

0 commit comments

Comments
 (0)