-
Notifications
You must be signed in to change notification settings - Fork 779
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
feat: implement AssignImage mutator #2429
feat: implement AssignImage mutator #2429
Conversation
Codecov ReportBase: 53.92% // Head: 53.51% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #2429 +/- ##
==========================================
- Coverage 53.92% 53.51% -0.42%
==========================================
Files 116 120 +4
Lines 10287 10635 +348
==========================================
+ Hits 5547 5691 +144
- Misses 4314 4512 +198
- Partials 426 432 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
fcbcc9b
to
7950dae
Compare
Have not gone thru all changes yet.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this LGTM! Just some small questions. There's also a chance to use require
for testing if you want to; that's just a non blocking suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting very close. Just the error testing and hardening the validation of the mutator parameters a bit more.
3ceb9a1
to
ad1dc17
Compare
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
@maxsmythe and @davis-haba any updates on this change? apiVersion: mutations.gatekeeper.sh/v1alpha1
kind: AssignImage
metadata:
name: defaultimageregistry
spec:
applyTo:
- groups: [ "" ]
kinds: [ "Pod" ]
versions: [ "v1" ]
location: "spec.containers[name:*].image"
parameters:
assignDomain: "1234567.dkr.ecr.us-east-1.amazonaws.com"
match:
source: "All"
scope: Cluster # (Cluster, Namespaced)
kinds:
- apiGroups: [ "*" ]
kinds: [ "Pod" ]
excludedNamespaces: ["excl-ns-1"] And if I do this, will it work for cases where domain is defined and not defined? I'm happy to test if you can provide guidance. |
@tahirraza the PR is still being worked on, but has been dormant for a bit due to the holidays. The PR should work exactly as you describe! I think it should be functional as-is (most of the back-and-forth is about safety and ensuring convergence IIRC). If you have the cycles and want to run a test build of the code, let us know how it goes! |
Okay. I'll take a jab at it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of testing and wording nits, but basically LGTM (will LGTM after nit fix)
…nt error. Signed-off-by: davis-haba <davishaba@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after nit fixes!
Signed-off-by: davis-haba <davishaba@google.com>
Signed-off-by: davis-haba <davishaba@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! LGTM
Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Davis Haba <52938648+davis-haba@users.noreply.github.com>
Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Davis Haba <52938648+davis-haba@users.noreply.github.com>
Signed-off-by: davis-haba <davishaba@google.com>
61da4ed
to
09389e3
Compare
Signed-off-by: davis-haba <davishaba@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Implement AssignImage mutator Signed-off-by: davis-haba <davishaba@google.com> * fix tests Signed-off-by: davis-haba <davishaba@google.com> * fix controller gen setup Signed-off-by: davis-haba <davishaba@google.com> * fix helm manifest generation Signed-off-by: davis-haba <davishaba@google.com> * WIP assignimage byPod status Signed-off-by: davis-haba <davishaba@google.com> * mutator pod status working for assignimage Signed-off-by: davis-haba <davishaba@google.com> * e2e test assignimage mutator deleted Signed-off-by: davis-haba <davishaba@google.com> * old kubectl run Signed-off-by: davis-haba <davishaba@google.com> * address comments. domain must have '.' unless localhost Signed-off-by: davis-haba <davishaba@google.com> * appease linter Signed-off-by: davis-haba <davishaba@google.com> * fix gator tests Signed-off-by: davis-haba <davishaba@google.com> * add test domain ending in colon still converges Signed-off-by: davis-haba <davishaba@google.com> * docs for assignimage Signed-off-by: davis-haba <davishaba@google.com> * remove newline Signed-off-by: davis-haba <davishaba@google.com> * address comments Signed-off-by: davis-haba <davishaba@google.com> * appease linter Signed-off-by: davis-haba <davishaba@google.com> * cleanup dead code branch Signed-off-by: davis-haba <davishaba@google.com> * validateDomain to use splitDomain Signed-off-by: davis-haba <davishaba@google.com> * future-proof validateImageParts. Add custom error types. Signed-off-by: davis-haba <davishaba@google.com> * fix readiness tracker test Signed-off-by: davis-haba <davishaba@google.com> * make manifests Signed-off-by: davis-haba <davishaba@google.com> * validate that splitting a valid tag never returns a path Signed-off-by: davis-haba <davishaba@google.com> * degenerate cases for unit tests. do not expose regex on image component error. Signed-off-by: davis-haba <davishaba@google.com> * test missing image field. update error copy. Signed-off-by: davis-haba <davishaba@google.com> * tag error copy Signed-off-by: davis-haba <davishaba@google.com> * Update pkg/expansion/system_test.go Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Davis Haba <52938648+davis-haba@users.noreply.github.com> * Update pkg/mutation/mutators/assignimage/assignimage_mutator.go Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Davis Haba <52938648+davis-haba@users.noreply.github.com> * errors.As instead of type casting in unit tests Signed-off-by: davis-haba <davishaba@google.com> * fix error type checking Signed-off-by: davis-haba <davishaba@google.com> Signed-off-by: Davis Haba <52938648+davis-haba@users.noreply.github.com> Co-authored-by: Sertaç Özercan <852750+sozercan@users.noreply.github.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com>
Signed-off-by: davis-haba davishaba@google.com
Implements the new
AssignImage
mutator, which is designed for setting docker image strings. The mutator allows setting thedomain
,path
, andtag
separately. #2381An image string is parsed into its components using mostly the same logic used by docker, the difference being we do not impose any defaults (e.g. we do not assume any empty domain should be interpreted as "docker.io", or that an empty tag is "latest").
To ensure an
AssignImage
cannot define a non convergent mutator, we perform validation on the 3 component fields. Each component is validated separately using similar validation used by docker. This prevents users from putting tokens we use to split the image string into components where they do not belong. For example, without validation, setting thetag
to/abc/def
on the stringnginx:latest
would change it tonginx/abc/def
on the first round, but since no tag is parsed out of this string, the next round would producenginx/abc/def/abc/def
and so on.In addition to validating each component individually, we also require that the path is not set to a "domain-like" value if domain is not set. Since docker domains can have
/
and.
, it would otherwise be possible to set a path likeabc.io/repo/app
to modify an image string likenginx:latest
, which would causeabc.io
to be parsed as part of the domain on the second round of mutation, resulting in non convergence.