-
Notifications
You must be signed in to change notification settings - Fork 61
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: add v1alpha3 api with RuntimeSpec configuration #922
feat: add v1alpha3 api with RuntimeSpec configuration #922
Conversation
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
8e25e74
to
4fdf322
Compare
Signed-off-by: ashnamehrotra <[email protected]>
…erridden Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
ea576fd
to
5d939a4
Compare
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
api/v1alpha3/config/config.go
Outdated
cfg *v1alpha3.EraserConfig | ||
} | ||
|
||
func (m *Manager) Read() (v1alpha3.EraserConfig, error) { |
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.
I believe you can remove these Read
and Update
methods and the NewManager
function. Only the unversioned
package needs those. For example, the corresponding functions from the v1alpha2/config
package are not actually called anywhere.
I think the functions aren't even needed for the conversion generation either. You can remove these, and the corresponding ones in v1alpha1
and v1alpha2
as well.
return rs, nil | ||
} | ||
|
||
func (td *Duration) UnmarshalJSON(b []byte) error { |
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.
I'd also like to have a unit test to prevent this from regressing. The unmarshaling is important because it catches errors, and we need to have tests to prove it fails when it is supposed to and doesn't when it's not.
api/v1alpha3/custom_conversions.go
Outdated
// TODO: change this to use unversioned.RuntimeSpec when unversioned is updated | ||
// | ||
//nolint:revive | ||
func autoConvert_unversioned_Runtime_To_v1alpha3_RuntimeSpec(in *unversioned.Runtime, out *RuntimeSpec, _ conversion.Scope) error { |
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 shouldn't be named autoConvert...
, since it's manually written, right?
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 PR isn't quite complete. We need to replace the unversioned.EraserConfig
with the v1alpha3
version. The unversioned
should always be the latest stable version. Since none of our EraserConfig
versions are stable, it should always just be the latest.
This will have effects on some of the code here, since it won't be necessary to have conversion functions between v1alpha3
and unversioned
. But you will need converters for 1 -> unversioned and 2 -> unversioned.
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
On second thought, it's best to keep the |
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
api/v1alpha3/eraserconfig_types.go
Outdated
func ConvertRuntimeToRuntimeSpec(r Runtime) (RuntimeSpec, error) { | ||
var rs RuntimeSpec | ||
|
||
switch rt := r; rt { |
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.
Just switch r
here
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
be2eb15
to
ddeaecb
Compare
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
d3c6745
to
0409e51
Compare
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
3fe226d
to
c8e2dc7
Compare
api/v1alpha3/eraserconfig_types.go
Outdated
type ( | ||
Duration time.Duration | ||
Runtime string | ||
RuntimeAddress string |
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.
Why the newtype for RuntimeAddress
? Why not just use a string?
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.
changed to string only Runtime has its own type
api/v1alpha3/runtime_spec_test.go
Outdated
|
||
tests := map[string]testCase{ | ||
"ValidContainerd": { | ||
input: []byte(`{"Name": "containerd", "Address": "unix:///run/containerd/containerd.sock"}`), |
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.
The keys should all be lowercase, i.e. name
and not Name
. If the test is passing as-is, it is a false positive and we need to find out why.
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.
And by keys I mean the keys in the JSON byte string.
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.
changed keys to lowercase! it says here it accepts case-insensitive match for the keys: https://pkg.go.dev/encoding/json#Unmarshal
pkg/scanners/trivy/helpers.go
Outdated
@@ -12,12 +12,14 @@ func loadConfig(filename string) (Config, error) { | |||
|
|||
b, err := os.ReadFile(filename) | |||
if err != nil { | |||
log.Info("LOADCONFIG unable to read file") |
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.
Maybe log.Error
here, and remove the LOADCONFIG
-- the logger should give us more info on where the error is occurring.
api/v1alpha3/runtime_spec_test.go
Outdated
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
var rs RuntimeSpec | ||
err := rs.UnmarshalJSON(test.input) |
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.
I think we shouldn't call UnmarshalJSON
directly but rather just err := json.Unmarshal(test.input, &rs)
. That's because json.Unmarshal
will ultimately call rs.UnmarshalJSON
. That's how it ends up getting used in our code, so that's what we should test.
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
Signed-off-by: ashnamehrotra <[email protected]>
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, thanks!
Signed-off-by: ashnamehrotra <[email protected]>
What this PR does / why we need it:
Part 1 of adding RuntimeSpec configuration. Adds v1alpha3 api with RuntimeSpec field and relevant conversion functions.
Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when the PR gets merged):Fixes #
Special notes for your reviewer: