-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
2,425 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## kn domain create | ||
|
||
Create a domain mapping | ||
|
||
``` | ||
kn domain create FQDN | ||
``` | ||
|
||
### 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 name. | ||
``` | ||
|
||
### 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## kn domain delete | ||
|
||
Delete a domain mapping | ||
|
||
``` | ||
kn domain delete FQDN | ||
``` | ||
|
||
### 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 FQDN | ||
``` | ||
|
||
### 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## kn domain update | ||
|
||
Update a domain mapping | ||
|
||
``` | ||
kn domain update FQDN | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Update a domain mappings 'hello.example.com' for Knative service 'hello' | ||
kn domain create hello.example.com --ref 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 name. | ||
``` | ||
|
||
### 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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" | ||
"knative.dev/client/pkg/kn/commands/flags" | ||
clientv1alpha1 "knative.dev/client/pkg/serving/v1alpha1" | ||
) | ||
|
||
// NewDomainMappingCreateCommand to create event channels | ||
func NewDomainMappingCreateCommand(p *commands.KnParams) *cobra.Command { | ||
var refFlags flags.SinkFlags | ||
cmd := &cobra.Command{ | ||
Use: "create FQDN", | ||
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 | ||
} | ||
destination, err := refFlags.ResolveSink(dynamicClient, namespace) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
builder := clientv1alpha1.NewDomainMappingBuilder(name). | ||
Namespace(namespace). | ||
Reference(*destination.Ref) | ||
|
||
client, err := p.NewServingV1alpha1Client(namespace) | ||
if err != nil { | ||
return err | ||
} | ||
err = client.CreateDomainMapping(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.AddWithFlagName(cmd, "ref", "") | ||
cmd.Flag("ref").Usage = "Addressable target reference for Domain Mapping. You can specify a Knative Service name." | ||
cmd.MarkFlagRequired("ref") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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 ( | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
|
||
dynamicfake "knative.dev/client/pkg/dynamic/fake" | ||
"knative.dev/client/pkg/serving/v1alpha1" | ||
"knative.dev/client/pkg/util" | ||
) | ||
|
||
func TestDomainMappingCreate(t *testing.T) { | ||
client := v1alpha1.NewMockKnServiceClient(t) | ||
dynamicClient := dynamicfake.CreateFakeKnDynamicClient(client.Namespace(), createService("foo")) | ||
|
||
servingRecorder := client.Recorder() | ||
servingRecorder.CreateDomainMapping(createDomainMapping("foo.bar", createServiceRef("foo", "default")), nil) | ||
|
||
out, err := executeDomainCommand(client, dynamicClient, "create", "foo.bar", "--ref", "foo") | ||
assert.NilError(t, err, "Domain mapping should be created") | ||
assert.Assert(t, util.ContainsAll(out, "Domain", "mapping", "foo.bar", "created", "namespace", "default")) | ||
|
||
servingRecorder.Validate() | ||
} | ||
func TestDomainMappingCreateWithError(t *testing.T) { | ||
client := v1alpha1.NewMockKnServiceClient(t) | ||
dynamicClient := dynamicfake.CreateFakeKnDynamicClient(client.Namespace(), createService("foo")) | ||
|
||
// No call should be recorded | ||
servingRecorder := client.Recorder() | ||
|
||
_, err := executeDomainCommand(client, dynamicClient, "create", "--ref", "foo") | ||
assert.ErrorContains(t, err, "domain create") | ||
assert.Assert(t, util.ContainsAll(err.Error(), "domain create", "requires", "name", "argument")) | ||
|
||
_, err = executeDomainCommand(client, dynamicClient, "create", "bar") | ||
assert.ErrorContains(t, err, "required flag") | ||
assert.Assert(t, util.ContainsAll(err.Error(), "required", "flag", "not", "set")) | ||
|
||
_, err = executeDomainCommand(client, dynamicClient, "create", "foo.bar", "--ref", "bar") | ||
assert.ErrorContains(t, err, "not found") | ||
assert.Assert(t, util.ContainsAll(err.Error(), "services", "\"bar\"", "not", "found")) | ||
|
||
servingRecorder.Validate() | ||
} |
Oops, something went wrong.