-
Notifications
You must be signed in to change notification settings - Fork 11
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 logging configuration to firewall #7
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: nnbu The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @nnbu. Thanks for your PR. I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
/test networkfirewall-kind-e2e |
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.
Hi @nnbu , looks like you need to update the commit hash in tests/e2e/requirements.txt
it's the reason it's causing tests to fail
ea18a4e
to
f07bb81
Compare
/retest |
I will check the errors further. These are related to my code. The e2e tests run fine when I run it though. Need to see what is different in upstream. |
f07bb81
to
3dbd2f6
Compare
/test networkfirewall-kind-e2e |
1 similar comment
/test networkfirewall-kind-e2e |
@nnbu could you also add a recommended IAM policy? it will help with networkfirewall-recommended-policy-test |
yes. I have not gotten a chance to look into where and what to add regarding the policy. I will check that |
/test networkfirewall-kind-e2e |
3dbd2f6
to
d231327
Compare
@a-hilaly Thank you. Tests are passing now. |
Gentle request to review when possible |
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.
@nnbu Nice, thanks a lot!
I have few questions/comments bellow. Feel free to ping me for questions or discussing any point.
/hold |
4d045bf
to
606428a
Compare
/test all |
pkg/resource/firewall/hook.go
Outdated
logDestinationConfigMap := make(map[string]*svcapitypes.LogDestinationConfig) | ||
|
||
for _, cfg := range logDestinationConfig { | ||
logDestinationConfigMap[makeLogDestinationConfigMapKey(cfg)] = cfg | ||
} |
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.
nit suggestion:
logDestinationConfigMap := make(map[string]*svcapitypes.LogDestinationConfig) | |
for _, cfg := range logDestinationConfig { | |
logDestinationConfigMap[makeLogDestinationConfigMapKey(cfg)] = cfg | |
} | |
// since we only want to use this map to check for object existance | |
logDestinationConfigMap := make(map[string]*struct{}) | |
for _, cfg := range logDestinationConfig { | |
logDestinationConfigMap[makeLogDestinationConfigMapKey(cfg)] = nil | |
} |
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 am using the map value 'cfg' in compareLoggingDestinationConfigs function, so we can not make value of the map as nil.
Let me explain the purpose of this map.
In compareLoggingDestinationConfigs() , we have to compare arrays of type []*svcapitypes.LogDestinationConfig. LogDestinationConfig
in itself is complex type which has a map (LogDestination
) as one of its fields. This makes comparison of these 2 arrays difficult.
So, to compare these arrays, I convert the array into a map, because map comparisons are easier to handle based on map keys. So, to convert each array object into a map entry, we need to have a key corresponding to that array object. makeLogDestinationConfigMapKey
creates this key from each array object. The value associated with this key is the array object itself, so that it is easier to retrieve the array object.
So, in summary,
makeLogDestinationConfigMapKey
gives unique key for each array entry of type*svcapitypes.LogDestinationConfig
.makeLogDestinationConfigMap
creates map with its key provided bymakeLogDestinationConfigMapKey
and its value as the array entry of typesvcapitypes.LogDestinationConfig
- In
compareLoggingDestinationConfigs
, we create 2 maps. One that represents what is desired logging configuration and one that represents what is existing logging configuration.
Now that, we have 2 maps, we iterate overdesired
map and check if the keys are present inlatest
map. If they are not present, we append thevalue
of that map (which is*svcapitypes.LogDestinationConfig
) into the list of configs to beadded
. Same case to determine list of configs to bedeleted
.
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 understand the problem, this is something we've seen with other APIs, but had to handle with some custom comparison/update functions. But in your case looks like it's a bit different.
I'm going to clone your branch and play a little bit with the implementation exploring the complexity of this case.
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.
Let me know if you got a chance to check more on this one.
pkg/resource/firewall/hook.go
Outdated
keys := make([]string, 0, len(cfg.LogDestination)) | ||
for k := range cfg.LogDestination { | ||
keys = append(keys, k) | ||
} | ||
sort.Strings(keys) | ||
|
||
key := "LogDestination:" | ||
for _, k := range keys { | ||
v := *cfg.LogDestination[k] | ||
key += fmt.Sprintf("%s:%s,", k, v) | ||
} | ||
|
||
if cfg.LogDestinationType != nil { | ||
key += fmt.Sprintf("LogDestinationType:%s,", *cfg.LogDestinationType) | ||
} | ||
if cfg.LogType != nil { | ||
key += fmt.Sprintf("LogType:%s", *cfg.LogType) | ||
} | ||
return key |
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.
My two cents: to avoid building strings manually with hard coded stuff, we can use json.Marshal
to transform the map in into a "sorted" map - checkout https://go.dev/src/encoding/json/encode.go#L344
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.
We dont really need to 'sort' the map here. So, I am not sure how I can make use of marshaling here. I explained the logic of compareLoggingDestinationConfigs
and associated functions below. Please let me know if you have suggestions.
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.
But i believe that you're calling sort.Strings(keys)
to have deterministic output.. because of the hash map random access pattern... right? the idea was instead of manually building your "string" that is just a way of representating of the object, how about:
b1, err := json.Marshall(cfg1)
b2, err := json.Marshall(cfg2)
then you case use string(b1), string(b2) as a key for the map discussed below
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 for the suggestion. I made a change to use json.Marshall
606428a
to
4d8e1d5
Compare
@a-hilaly Please let me know if any additional information is needed from my end. |
gentle reminder to review this one |
pkg/resource/firewall/hook.go
Outdated
keys := make([]string, 0, len(cfg.LogDestination)) | ||
for k := range cfg.LogDestination { | ||
keys = append(keys, k) | ||
} | ||
sort.Strings(keys) | ||
|
||
key := "LogDestination:" | ||
for _, k := range keys { | ||
v := *cfg.LogDestination[k] | ||
key += fmt.Sprintf("%s:%s,", k, v) | ||
} | ||
|
||
if cfg.LogDestinationType != nil { | ||
key += fmt.Sprintf("LogDestinationType:%s,", *cfg.LogDestinationType) | ||
} | ||
if cfg.LogType != nil { | ||
key += fmt.Sprintf("LogType:%s", *cfg.LogType) | ||
} | ||
return key |
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.
But i believe that you're calling sort.Strings(keys)
to have deterministic output.. because of the hash map random access pattern... right? the idea was instead of manually building your "string" that is just a way of representating of the object, how about:
b1, err := json.Marshall(cfg1)
b2, err := json.Marshall(cfg2)
then you case use string(b1), string(b2) as a key for the map discussed below
pkg/resource/firewall/hook.go
Outdated
logDestinationConfigMap := make(map[string]*svcapitypes.LogDestinationConfig) | ||
|
||
for _, cfg := range logDestinationConfig { | ||
logDestinationConfigMap[makeLogDestinationConfigMapKey(cfg)] = cfg | ||
} |
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 understand the problem, this is something we've seen with other APIs, but had to handle with some custom comparison/update functions. But in your case looks like it's a bit different.
I'm going to clone your branch and play a little bit with the implementation exploring the complexity of this case.
@nnbu I didn't forget about this PR, i will experiment few things and get back to you.. |
4d8e1d5
to
542a518
Compare
Issue (aws-controllers-k8s/community#1553) Description of changes: Adds support for logging configuration to firwall spec By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
542a518
to
6257eeb
Compare
@a-hilaly I made the change to use |
Issues go stale after 180d of inactivity. |
@nnbu: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Issue (aws-controllers-k8s/community#1553)
Description of changes:
Adds support for logging configuration to firwall spec
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.