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

Add logging configuration to firewall #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nnbu
Copy link

@nnbu nnbu commented Aug 31, 2023

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.

@ack-prow
Copy link

ack-prow bot commented Aug 31, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-prow ack-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 31, 2023
@ack-prow
Copy link

ack-prow bot commented Aug 31, 2023

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@a-hilaly
Copy link
Member

/ok-to-test

@ack-prow ack-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 31, 2023
@nnbu
Copy link
Author

nnbu commented Sep 1, 2023

/test networkfirewall-kind-e2e

Copy link
Member

@a-hilaly a-hilaly left a 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

@nnbu
Copy link
Author

nnbu commented Sep 1, 2023

/retest

@nnbu
Copy link
Author

nnbu commented Sep 1, 2023

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.

@nnbu
Copy link
Author

nnbu commented Sep 1, 2023

/test networkfirewall-kind-e2e

1 similar comment
@a-hilaly
Copy link
Member

a-hilaly commented Sep 1, 2023

/test networkfirewall-kind-e2e

@a-hilaly
Copy link
Member

a-hilaly commented Sep 1, 2023

@nnbu could you also add a recommended IAM policy? it will help with networkfirewall-recommended-policy-test

@nnbu
Copy link
Author

nnbu commented Sep 1, 2023

yes. I have not gotten a chance to look into where and what to add regarding the policy. I will check that

@a-hilaly
Copy link
Member

a-hilaly commented Sep 1, 2023

@a-hilaly
Copy link
Member

a-hilaly commented Sep 1, 2023

/test networkfirewall-kind-e2e

@nnbu
Copy link
Author

nnbu commented Sep 5, 2023

@nnbu
Copy link
Author

nnbu commented Sep 7, 2023

Gentle request to review when possible

Copy link
Member

@a-hilaly a-hilaly left a 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.

apis/v1alpha1/ack-generate-metadata.yaml Show resolved Hide resolved
templates/common/sdk_file_end.go.tpl Outdated Show resolved Hide resolved
pkg/resource/firewall/hook.go Outdated Show resolved Hide resolved
pkg/resource/firewall/hook.go Show resolved Hide resolved
pkg/resource/firewall/hook.go Show resolved Hide resolved
test/e2e/requirements.txt Outdated Show resolved Hide resolved
test/e2e/service_bootstrap.py Outdated Show resolved Hide resolved
test/e2e/tests/test_references.pytest Outdated Show resolved Hide resolved
test/e2e/tests/test_firewall.py Outdated Show resolved Hide resolved
test/e2e/tests/test_firewall.py Show resolved Hide resolved
@a-hilaly
Copy link
Member

a-hilaly commented Sep 7, 2023

/hold

@ack-prow ack-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 7, 2023
@nnbu nnbu force-pushed the logging-config-1 branch 3 times, most recently from 4d045bf to 606428a Compare September 9, 2023 05:11
@a-hilaly
Copy link
Member

/test all

Comment on lines 187 to 177
logDestinationConfigMap := make(map[string]*svcapitypes.LogDestinationConfig)

for _, cfg := range logDestinationConfig {
logDestinationConfigMap[makeLogDestinationConfigMapKey(cfg)] = cfg
}
Copy link
Member

Choose a reason for hiding this comment

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

nit suggestion:

Suggested change
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
}

Copy link
Author

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,

  1. makeLogDestinationConfigMapKey gives unique key for each array entry of type *svcapitypes.LogDestinationConfig.
  2. makeLogDestinationConfigMap creates map with its key provided by makeLogDestinationConfigMapKey and its value as the array entry of type svcapitypes.LogDestinationConfig
  3. 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 over desired map and check if the keys are present in latest map. If they are not present, we append the value of that map (which is *svcapitypes.LogDestinationConfig) into the list of configs to be added. Same case to determine list of configs to be deleted.

Copy link
Member

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.

Copy link
Author

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.

Comment on lines 165 to 183
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
Copy link
Member

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

Copy link
Author

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.

Copy link
Member

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

Copy link
Author

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

test/e2e/conftest.py Outdated Show resolved Hide resolved
test/e2e/resources/firewall.yaml Outdated Show resolved Hide resolved
@nnbu
Copy link
Author

nnbu commented Sep 18, 2023

@a-hilaly Please let me know if any additional information is needed from my end.

@nnbu
Copy link
Author

nnbu commented Sep 25, 2023

gentle reminder to review this one

pkg/resource/firewall/hook.go Outdated Show resolved Hide resolved
Comment on lines 165 to 183
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
Copy link
Member

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

Comment on lines 187 to 177
logDestinationConfigMap := make(map[string]*svcapitypes.LogDestinationConfig)

for _, cfg := range logDestinationConfig {
logDestinationConfigMap[makeLogDestinationConfigMapKey(cfg)] = cfg
}
Copy link
Member

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.

@a-hilaly
Copy link
Member

@nnbu I didn't forget about this PR, i will experiment few things and get back to you..

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.
@nnbu
Copy link
Author

nnbu commented Oct 30, 2023

@a-hilaly I made the change to use b1, err := json.Marshall(cfg1).
Do you mind reviewing this one please?

@ack-bot
Copy link
Collaborator

ack-bot commented Apr 27, 2024

Issues go stale after 180d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 60d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Provide feedback via https://github.com/aws-controllers-k8s/community.
/lifecycle stale

@ack-prow ack-prow bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 27, 2024
@a-hilaly a-hilaly removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 4, 2024
Copy link

ack-prow bot commented Aug 30, 2024

@nnbu: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
networkfirewall-verify-attribution 6257eeb link true /test networkfirewall-verify-attribution

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants