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 command group for ContainerSource #1016

Merged
merged 6 commits into from
Dec 2, 2020
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
1 change: 1 addition & 0 deletions docs/cmd/kn_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ kn source SOURCE|COMMAND
* [kn](kn.md) - kn manages Knative Serving and Eventing resources
* [kn source apiserver](kn_source_apiserver.md) - Manage Kubernetes api-server sources
* [kn source binding](kn_source_binding.md) - Manage sink bindings
* [kn source container](kn_source_container.md) - Manage container sources
* [kn source list](kn_source_list.md) - List event sources
* [kn source list-types](kn_source_list-types.md) - List event source types
* [kn source ping](kn_source_ping.md) - Manage ping sources
Expand Down
35 changes: 35 additions & 0 deletions docs/cmd/kn_source_container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## kn source container

Manage container sources

### Synopsis

Manage container sources

```
kn source container create|delete|update|list|describe
```

### Options

```
-h, --help help for container
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source](kn_source.md) - Manage event sources
* [kn source container create](kn_source_container_create.md) - Create a container source
* [kn source container delete](kn_source_container_delete.md) - Delete a container source
* [kn source container describe](kn_source_container_describe.md) - Show details of a container source
* [kn source container list](kn_source_container_list.md) - List container sources
* [kn source container update](kn_source_container_update.md) - Update a container source

53 changes: 53 additions & 0 deletions docs/cmd/kn_source_container_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## kn source container create

Create a container source

### Synopsis

Create a container source

```
kn source container create NAME --image IMAGE --sink SINK
```

### Examples

```

# Create a ContainerSource 'src' to start a container with image 'docker.io/sample/image' and send messages to service 'mysvc'
kn source container create src --image docker.io/sample/image --sink ksvc:mysvc
```

### Options

```
--arg stringArray Add argument to the container command. Example: --arg myArg1 --arg --myArg2 --arg myArg3=3. You can use this flag multiple times.
--cmd string Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd /app/start --arg myArg to pass additional arguments.
-e, --env stringArray Environment variable to set. NAME=value; you may provide this flag any number of times to set multiple environment variables. To unset, specify the environment variable name followed by a "-" (e.g., NAME-).
--env-from stringArray Add environment variables from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret:). Example: --env-from cm:myconfigmap or --env-from secret:mysecret. You can use this flag multiple times. To unset a ConfigMap/Secret reference, append "-" to the name, e.g. --env-from cm:myconfigmap-.
-h, --help help for create
--image string Image to run.
--limit strings The resource requirement limits for this Service. For example, 'cpu=100m,memory=256Mi'. You can use this flag multiple times. To unset a resource limit, append "-" to the resource name, e.g. '--limit memory-'.
--mount stringArray Mount a ConfigMap (prefix cm: or config-map:), a Secret (prefix secret: or sc:), or an existing Volume (without any prefix) on the specified directory. Example: --mount /mydir=cm:myconfigmap, --mount /mydir=secret:mysecret, or --mount /mydir=myvolume. When a configmap or a secret is specified, a corresponding volume is automatically generated. You can use this flag multiple times. For unmounting a directory, append "-", e.g. --mount /mydir-, which also removes any auto-generated volume.
-n, --namespace string Specify the namespace to operate in.
-p, --port string The port where application listens on, in the format 'NAME:PORT', where 'NAME' is optional. Examples: '--port h2c:8080' , '--port 8080'.
--pull-secret string Image pull secret to set. An empty argument ("") clears the pull secret. The referenced secret must exist in the service's namespace.
--request strings The resource requirement requests for this Service. For example, 'cpu=100m,memory=256Mi'. You can use this flag multiple times. To unset a resource request, append "-" to the resource name, e.g. '--request cpu-'.
--service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace.
-s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service.
--user int The user ID to run the container (e.g., 1001).
--volume stringArray Add a volume from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret: or sc:). Example: --volume myvolume=cm:myconfigmap or --volume myvolume=secret:mysecret. You can use this flag multiple times. To unset a ConfigMap/Secret reference, append "-" to the name, e.g. --volume myvolume-.
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source container](kn_source_container.md) - Manage container sources

39 changes: 39 additions & 0 deletions docs/cmd/kn_source_container_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## kn source container delete

Delete a container source

### Synopsis

Delete a container source

```
kn source container delete NAME
```

### Examples

```

# Delete a ContainerSource 'containersrc' in default namespace
kn source container delete containersrc
```

### Options

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

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source container](kn_source_container.md) - Manage container sources

40 changes: 40 additions & 0 deletions docs/cmd/kn_source_container_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## kn source container describe

Show details of a container source

### Synopsis

Show details of a container source

```
kn source container describe NAME
```

### Examples

```

# Describe a container source with name 'k8sevents'
kn source container describe k8sevents
```

### Options

```
-h, --help help for describe
-n, --namespace string Specify the namespace to operate in.
-v, --verbose More output.
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source container](kn_source_container.md) - Manage container sources

47 changes: 47 additions & 0 deletions docs/cmd/kn_source_container_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## kn source container list

List container sources

### Synopsis

List container sources

```
kn source container list
```

### Examples

```

# List all Container sources
kn source container list

# List all Container sources in YAML format
kn source apiserver list -o yaml
```

### 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-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

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source container](kn_source_container.md) - Manage container sources

53 changes: 53 additions & 0 deletions docs/cmd/kn_source_container_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## kn source container update

Update a container source

### Synopsis

Update a container source

```
kn source container update NAME --image IMAGE
```

### Examples

```

# Update a ContainerSource 'src' with a different image uri 'docker.io/sample/newimage'
kn source container update src --image docker.io/sample/newimage
```

### Options

```
--arg stringArray Add argument to the container command. Example: --arg myArg1 --arg --myArg2 --arg myArg3=3. You can use this flag multiple times.
--cmd string Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd /app/start --arg myArg to pass additional arguments.
-e, --env stringArray Environment variable to set. NAME=value; you may provide this flag any number of times to set multiple environment variables. To unset, specify the environment variable name followed by a "-" (e.g., NAME-).
--env-from stringArray Add environment variables from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret:). Example: --env-from cm:myconfigmap or --env-from secret:mysecret. You can use this flag multiple times. To unset a ConfigMap/Secret reference, append "-" to the name, e.g. --env-from cm:myconfigmap-.
-h, --help help for update
--image string Image to run.
--limit strings The resource requirement limits for this Service. For example, 'cpu=100m,memory=256Mi'. You can use this flag multiple times. To unset a resource limit, append "-" to the resource name, e.g. '--limit memory-'.
--mount stringArray Mount a ConfigMap (prefix cm: or config-map:), a Secret (prefix secret: or sc:), or an existing Volume (without any prefix) on the specified directory. Example: --mount /mydir=cm:myconfigmap, --mount /mydir=secret:mysecret, or --mount /mydir=myvolume. When a configmap or a secret is specified, a corresponding volume is automatically generated. You can use this flag multiple times. For unmounting a directory, append "-", e.g. --mount /mydir-, which also removes any auto-generated volume.
-n, --namespace string Specify the namespace to operate in.
-p, --port string The port where application listens on, in the format 'NAME:PORT', where 'NAME' is optional. Examples: '--port h2c:8080' , '--port 8080'.
--pull-secret string Image pull secret to set. An empty argument ("") clears the pull secret. The referenced secret must exist in the service's namespace.
--request strings The resource requirement requests for this Service. For example, 'cpu=100m,memory=256Mi'. You can use this flag multiple times. To unset a resource request, append "-" to the resource name, e.g. '--request cpu-'.
--service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace.
-s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service.
--user int The user ID to run the container (e.g., 1001).
--volume stringArray Add a volume from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret: or sc:). Example: --volume myvolume=cm:myconfigmap or --volume myvolume=secret:mysecret. You can use this flag multiple times. To unset a ConfigMap/Secret reference, append "-" to the name, e.g. --volume myvolume-.
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source container](kn_source_container.md) - Manage container sources

68 changes: 68 additions & 0 deletions pkg/kn/commands/source/container/container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright 2020 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 container

import (
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
"knative.dev/client/pkg/kn/commands"
"knative.dev/client/pkg/sources/v1alpha2"
clientv1alpha2 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha2"
)

// NewContainerCommand for managing Container source
func NewContainerCommand(p *commands.KnParams) *cobra.Command {
containerSourceCmd := &cobra.Command{
Use: "container create|delete|update|list|describe",
Short: "Manage container sources",
}
containerSourceCmd.AddCommand(NewContainerCreateCommand(p))
containerSourceCmd.AddCommand(NewContainerDeleteCommand(p))
containerSourceCmd.AddCommand(NewContainerUpdateCommand(p))
containerSourceCmd.AddCommand(NewContainerListCommand(p))
containerSourceCmd.AddCommand(NewContainerDescribeCommand(p))
return containerSourceCmd
}

var containerSourceClientFactory func(config clientcmd.ClientConfig, namespace string) (v1alpha2.KnContainerSourcesClient, error)

func newContainerSourceClient(p *commands.KnParams, cmd *cobra.Command) (v1alpha2.KnContainerSourcesClient, error) {
namespace, err := p.GetNamespace(cmd)
if err != nil {
return nil, err
}

if containerSourceClientFactory != nil {
config, err := p.GetClientConfig()
if err != nil {
return nil, err
}
return containerSourceClientFactory(config, namespace)
}

clientConfig, err := p.RestConfig()
if err != nil {
return nil, err
}

client, err := clientv1alpha2.NewForConfig(clientConfig)
if err != nil {
return nil, err
}

return v1alpha2.NewKnSourcesClient(client, namespace).ContainerSourcesClient(), nil
}
Loading