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

connectivity: Ability to add custom annotations to test deployment #1687

Merged
merged 3 commits into from
Jun 6, 2023

Conversation

gandro
Copy link
Member

@gandro gandro commented Jun 1, 2023

connectivity: Ability to add custom annotations to test deployment

This commit adds the ability to add custom namespace and pod annotations
to the cilium connectivity test deployment. The two flags are
--deployment-pod-annotations and --namespace-annotations.

For the pod annotations, we accept a JSON map which contains the
deployment name as the key, and the annotations as a string-to-string
map. For the namespace annotation, we simply expect a string-to-string
map.

We could have used Viper's StringToString map for the namespace
annotations, but not for the pod annotations, since there we would need
a "StringToStringToString" map. Therefore, to remain consistent
between the two flags, both flags exclusively JSON syntax.

If the deployment name in the annotations map ends with a * symbol,
then we perform a longest prefix match.

The flags are currently hidden, since we are not fully commited to this
command-line syntax yet and it might still change in the future.

Example:

$ cilium connectivity test \
    --namespace-annotations='{"foo":"bar"}' \
    --deployment-pod-annotations='{"client":{"baz":"qux"},"echo-*":{"quux":"corge"}}'

@gandro gandro temporarily deployed to ci June 1, 2023 15:47 — with GitHub Actions Inactive
Copy link
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! Maybe provide a working example command using these flags in the commit message and/or PR description?

@gandro
Copy link
Member Author

gandro commented Jun 5, 2023

Some of the CI failures look legitimate: connectivity test failed: unable to create namespace cilium-test: namespaces "cilium-test" already exists. Not sure how that could happen. Looking into it!

This commit adds the ability to add labels or annotations to a newly
created namespace. This commit itself does not contain any changes in
functional behavior, the ability to add annotations will be used in a
subsequent commit.

Signed-off-by: Sebastian Wicki <[email protected]>
@gandro gandro force-pushed the pr/gandro/connectivity-test-annotations branch from 689056e to 08452db Compare June 5, 2023 15:24
@gandro gandro force-pushed the pr/gandro/connectivity-test-annotations branch from 08452db to 90c0189 Compare June 5, 2023 15:26
@gandro gandro force-pushed the pr/gandro/connectivity-test-annotations branch from 90c0189 to 8fc2027 Compare June 5, 2023 15:27
@gandro gandro temporarily deployed to ci June 5, 2023 15:27 — with GitHub Actions Inactive
@gandro
Copy link
Member Author

gandro commented Jun 5, 2023

Some of the CI failures look legitimate: connectivity test failed: unable to create namespace cilium-test: namespaces "cilium-test" already exists. Not sure how that could happen. Looking into it!

Fixes. Issue was a copy-paste error in the namespace (dst vs src context) refactor commit.

@gandro gandro marked this pull request as ready for review June 5, 2023 15:28
@gandro gandro requested review from a team as code owners June 5, 2023 15:28
@gandro gandro requested review from youngnick and squeed June 5, 2023 15:28
@squeed
Copy link
Contributor

squeed commented Jun 6, 2023

Looks good. One question: is there any need for setting annotations on all pods? Something like --deployment-pod-annotations='{"*":{"foo":"bar"}}'

@gandro
Copy link
Member Author

gandro commented Jun 6, 2023

Looks good. One question: is there any need for setting annotations on all pods? Something like --deployment-pod-annotations='{"*":{"foo":"bar"}}'

Oh that's a nice suggestion. Yeah I think supporting a wildcard match would be nice.

gandro added 2 commits June 6, 2023 15:34
This type will be used in a subsequent commit to specify the wanted
annotations for a specific deployment or namespace. Unit tests are added
to ensure the wildcard matching behavior.

Signed-off-by: Sebastian Wicki <[email protected]>
This commit adds the ability to add custom namespace and pod annotations
to the `cilium connectivity test` deployment. The two flags are
`--deployment-pod-annotations` and `--namespace-annotations`.

For the pod annotations, we accept a JSON map which contains the
deployment name as the key, and the annotations as a string-to-string
map. For the namespace annotation, we simply expect a string-to-string
map.

We could have used Viper's `StringToString` map for the namespace
annotations, but not for the pod annotations, since there we would need
a "`StringToStringToString`" map. Therefore, to remain consistent
between the two flags, both flags exclusively JSON syntax.

If the deployment name in the annotations map ends with a `*` symbol,
then we perform a longest prefix match.

The flags are currently hidden, since we are not fully commited to this
command-line syntax yet and it might still change in the future.

Example:

```
$ cilium connectivity test \
    --namespace-annotations='{"foo":"bar"}' \
    --deployment-pod-annotations='{"client":{"baz":"qux"},"echo-*":{"quux":"corge"}}'
```

Signed-off-by: Sebastian Wicki <[email protected]>
@gandro gandro force-pushed the pr/gandro/connectivity-test-annotations branch from 8fc2027 to 0329c76 Compare June 6, 2023 13:37
@gandro gandro temporarily deployed to ci June 6, 2023 13:37 — with GitHub Actions Inactive
@gandro
Copy link
Member Author

gandro commented Jun 6, 2023

Added the ability to support simple (i.e. prefix only) wildcard matches via echo-* or *. See unit tests or PR description for an example.

@gandro gandro removed the request for review from youngnick June 6, 2023 14:28
@gandro gandro added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 6, 2023
@gandro gandro merged commit fe18d0f into main Jun 6, 2023
@gandro gandro deleted the pr/gandro/connectivity-test-annotations branch June 6, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants