Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DomainMapping CRUD commands #1267

Merged
merged 6 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
| 🎁
| Add context.Context parameter to API function
| https://github.com/knative/client/pull/1274[#1274]

| 🎁
| Add `kn domain` commands to manage DomainMapping
| https://github.com/knative/client/pull/1267[#1267]

|===

## v0.21.0 (2021-02-23)
Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ kn is the command line interface for managing Knative Serving and Eventing resou
* [kn broker](kn_broker.md) - Manage message brokers
* [kn channel](kn_channel.md) - Manage event channels
* [kn completion](kn_completion.md) - Output shell completion code
* [kn domain](kn_domain.md) - Manage domain mappings
* [kn options](kn_options.md) - Print the list of flags inherited by all commands
* [kn plugin](kn_plugin.md) - Manage kn plugins
* [kn revision](kn_revision.md) - Manage service revisions
Expand Down
33 changes: 33 additions & 0 deletions docs/cmd/kn_domain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## kn domain

Manage domain mappings

```
kn domain COMMAND
```

### Options

```
-h, --help help for domain
```

### Options inherited from parent commands

```
--cluster string name of the kubeconfig cluster to use
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--context string name of the kubeconfig context to use
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn](kn.md) - kn manages Knative Serving and Eventing resources
* [kn domain create](kn_domain_create.md) - Create a domain mapping
* [kn domain delete](kn_domain_delete.md) - Delete a domain mapping
* [kn domain describe](kn_domain_describe.md) - Show details of a domain mapping
* [kn domain list](kn_domain_list.md) - List domain mappings
* [kn domain update](kn_domain_update.md) - Update a domain mapping

38 changes: 38 additions & 0 deletions docs/cmd/kn_domain_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## kn domain create

Create a domain mapping

```
kn domain create NAME
```

### Examples

```

# Create a domain mappings 'hello.example.com' for Knative service 'hello'
kn domain create hello.example.com --ref hello
```

### Options

```
-h, --help help for create
-n, --namespace string Specify the namespace to operate in.
--ref string Addressable target reference for Domain Mapping. You can specify a Knative service, a Knative route. Examples: '--ref' ksvc:hello' or simply '--ref hello' for a Knative service 'hello', '--ref' kroute:hello' for a Knative route 'hello'. '--ref ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', If a prefix is not provided, it is considered as a Knative service in the current namespace. If referring to a Knative service in another namespace, 'ksvc:name:namespace' combination must be provided explicitly.
```

### Options inherited from parent commands

```
--cluster string name of the kubeconfig cluster to use
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--context string name of the kubeconfig context to use
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn domain](kn_domain.md) - Manage domain mappings

37 changes: 37 additions & 0 deletions docs/cmd/kn_domain_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## kn domain delete

Delete a domain mapping

```
kn domain delete NAME
```

### Examples

```

# Delete domain mappings 'hello.example.com'
kn domain delete hello.example.com
```

### Options

```
-h, --help help for delete
-n, --namespace string Specify the namespace to operate in.
```

### Options inherited from parent commands

```
--cluster string name of the kubeconfig cluster to use
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--context string name of the kubeconfig context to use
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn domain](kn_domain.md) - Manage domain mappings

33 changes: 33 additions & 0 deletions docs/cmd/kn_domain_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## kn domain describe

Show details of a domain mapping

```
kn domain describe NAME
```

### Options

```
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
-h, --help help for describe
-n, --namespace string Specify the namespace to operate in.
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file|url.
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
-v, --verbose More output.
```

### Options inherited from parent commands

```
--cluster string name of the kubeconfig cluster to use
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--context string name of the kubeconfig context to use
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn domain](kn_domain.md) - Manage domain mappings

45 changes: 45 additions & 0 deletions docs/cmd/kn_domain_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## kn domain list

List domain mappings

```
kn domain list
```

### Examples

```

# List all domain mappings
kn domain list

# List all domain mappings in JSON output format
kn revision list -o json
```

### Options

```
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
-h, --help help for list
-n, --namespace string Specify the namespace to operate in.
--no-headers When using the default output format, don't print headers (default: print headers).
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file.
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
```

### Options inherited from parent commands

```
--cluster string name of the kubeconfig cluster to use
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--context string name of the kubeconfig context to use
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn domain](kn_domain.md) - Manage domain mappings

38 changes: 38 additions & 0 deletions docs/cmd/kn_domain_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## kn domain update

Update a domain mapping

```
kn domain update NAME
```

### Examples

```

# Update a domain mappings 'hello.example.com' for Knative service 'hello'
kn domain create hello.example.com --refFlags hello
```

### Options

```
-h, --help help for update
-n, --namespace string Specify the namespace to operate in.
--ref string Addressable target reference for Domain Mapping. You can specify a Knative service, a Knative route. Examples: '--ref' ksvc:hello' or simply '--ref hello' for a Knative service 'hello', '--ref' kroute:hello' for a Knative route 'hello'. '--ref ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', If a prefix is not provided, it is considered as a Knative service in the current namespace. If referring to a Knative service in another namespace, 'ksvc:name:namespace' combination must be provided explicitly.
```

### Options inherited from parent commands

```
--cluster string name of the kubeconfig cluster to use
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--context string name of the kubeconfig context to use
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn domain](kn_domain.md) - Manage domain mappings

3 changes: 3 additions & 0 deletions pkg/dynamic/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package fake

import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
dynamicfake "k8s.io/client-go/dynamic/fake"
Expand All @@ -28,7 +29,9 @@ import (
// CreateFakeKnDynamicClient gives you a dynamic client for testing containing the given objects.
func CreateFakeKnDynamicClient(testNamespace string, objects ...runtime.Object) dynamic.KnDynamicClient {
scheme := runtime.NewScheme()
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"}, &v1.Service{})
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "serving.knative.dev", Version: "v1", Kind: "Service"}, &servingv1.Service{})
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "serving.knative.dev", Version: "v1", Kind: "Route"}, &servingv1.Route{})
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1beta1", Kind: "Broker"}, &eventingv1beta1.Broker{})
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1beta1", Kind: "Subscription"}, &messagingv1beta1.Subscription{})
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "Channel"}, &messagingv1beta1.Channel{})
Expand Down
77 changes: 77 additions & 0 deletions pkg/kn/commands/domain/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright © 2021 The Knative Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package domain

import (
"errors"
"fmt"

"github.com/spf13/cobra"

knerrors "knative.dev/client/pkg/errors"
"knative.dev/client/pkg/kn/commands"
clientv1alpha1 "knative.dev/client/pkg/serving/v1alpha1"
)

// NewDomainMappingCreateCommand to create event channels
func NewDomainMappingCreateCommand(p *commands.KnParams) *cobra.Command {
var refFlags RefFlags
cmd := &cobra.Command{
Use: "create NAME",
Short: "Create a domain mapping",
Example: `
# Create a domain mappings 'hello.example.com' for Knative service 'hello'
kn domain create hello.example.com --ref hello`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
if len(args) != 1 {
return errors.New("'kn domain create' requires the domain name given as single argument")
}
name := args[0]
namespace, err := p.GetNamespace(cmd)
if err != nil {
return err
}

dynamicClient, err := p.NewDynamicClient(namespace)
if err != nil {
return err
}
reference, err := refFlags.Resolve(cmd.Context(), dynamicClient, namespace)
if err != nil {
return err
}

builder := clientv1alpha1.NewDomainMappingBuilder(name).
Namespace(namespace).
Reference(*reference)

client, err := p.NewServingV1alpha1Client(namespace)
if err != nil {
return err
}
err = client.CreateDomainMapping(cmd.Context(), builder.Build())
if err != nil {
return knerrors.GetError(err)
}

fmt.Fprintf(cmd.OutOrStdout(), "Domain mapping '%s' created in namespace '%s'.\n", name, namespace)
return nil
},
}
commands.AddNamespaceFlags(cmd.Flags(), false)
refFlags.Add(cmd)
cmd.MarkFlagRequired("ref")
return cmd
}
Loading