Skip to content

Commit

Permalink
Add dapr annotate command (#873)
Browse files Browse the repository at this point in the history
* Add dapr inject command

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Add additional opts

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Update comment regarding injection

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* fix some linting issues (more to go)

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* use existing const in tests

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* fix some more linting

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* fix some more linting

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* udpate tests

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* udpate tests

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* add option to run against a URL

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* refactor cmd/inject.go slightly

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* update example text

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* autogenerate appid if not present

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Update comment

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Add support for target namespace

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Update comment

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* Add warning about app id generation to usage

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* fix linting issues

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* rename inject to annotate

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* go mod tidy

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* fix lint

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* update --help URL

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

* add README.md seciton

Signed-off-by: Joni Collinge <jonathancollinge@live.com>

Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
  • Loading branch information
jjcollinge and yaron2 authored Jun 2, 2022
1 parent 8e9c675 commit 0630996
Show file tree
Hide file tree
Showing 24 changed files with 2,658 additions and 4 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,40 @@ The default is `false`.

For more details, please run the command and check the examples to apply to your shell.

### Annotate a Kubernetes manifest

To add or modify dapr annotations on an existing Kubernetes manifest, use the `dapr annotate` command:

```bash
dapr annotate [flags] mydeployment.yaml
```

This will add the `dapr.io/enabled` and the `dapr.io/app-id` annotations. The dapr app id will be genereated using the format `<namespace>-<kind>-<name>` where the values are taken from the existing Kubernetes object metadata.

To provide your own dapr app id, provide the flag `--app-id`.

All dapr annotations are available to set if a value is provided for the appropriate flag on the `dapr annotate` command.

You can also provide the Kubernetes manifest via stdin:

```bash
kubectl get deploy mydeploy -o yaml | dapr annotate - | kubectl apply -f -
```

Or you can provide the Kubernetes manifest via a URL:

```bash
dapr annotate --log-level debug https://raw.githubusercontent.com/dapr/quickstarts/master/tutorials/hello-kubernetes/deploy/node.yaml | kubectl apply -f -
```

If the input contains multiple manifests then the command will search for the first appropriate one to apply the annotations. If you'd rather it applied to a specific manifest then you can provide the `--resource` flag with the value set to the name of the object you'd like to apply the annotations to. If you have a conflict between namespaces you can also provide the namespace via the `--namespace` flag to isolate the manifest you wish to target.

If you want to annotate multiple manifests, you can chain together the `dapr annotate` commands with each applying the annotation to a specific manifest.

```bash
kubectl get deploy -o yaml | dapr annotate -r nodeapp --log-level debug - | dapr annotate --log-level debug -r pythonapp - | kubectl apply -f -
```

## Reference for the Dapr CLI

See the [Reference Guide](https://docs.dapr.io/reference/cli/) for more information about individual Dapr commands.
Expand Down
Loading

0 comments on commit 0630996

Please sign in to comment.