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

Followup Antctl Tranform Code Move #6062

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

qiyueyao
Copy link
Contributor

@qiyueyao qiyueyao commented Mar 5, 2024

This solution refactors the transform functions for antctl networkpolicy to the same place, but indicates request and response difference. (base on this discussion)
Also adds some additional unit tests.

Comment on lines 86 to 90
var npList = &cpv1beta.NetworkPolicyList{
Items: []cpv1beta.NetworkPolicy{npA, npC, npB},
}

var npListK8s = &cpv1beta.NetworkPolicyList{
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I understand the naming here, why is one list called npList and the other npListK8s, as opposed to npList1 and npList2? What does the K8s suffix stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking npList2 has K8s NPs to test the sort, which npList1 hasn't. I have indicated this difference in the test case names instead, and changed to npList1 and npList2.

Comment on lines 40 to 41
// NewNetworkPolicyEvaluation transforms the arguments in the formats defined by antctl
// usages, to NetworkPolicyEvaluation format required for client resource request.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd suggest the following instead

NewNetworkPolicyEvaluation creates a new NetworkPolicyEvaluation resource request from the command-line arguments provided to antctl.

@antoninbas antoninbas requested a review from tnqn March 6, 2024 01:33
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package parameter
package networkpolicy
Copy link
Member

Choose a reason for hiding this comment

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

Should the file name be request.go given this is already under transform package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the name. I noticed that all the files under transform/* package are named transform.go, does it matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

you could rename all the other files response.go if you wanted to be consistent

Copy link
Member

Choose a reason for hiding this comment

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

I noticed that all the files under transform/* package are named transform.go, does it matter?

It doesn't matter that a file has the name as its package. It's actually quite common when there is only 1 file in the package. Normally the file having the same name as the package is considered the "main" file containing the core interface, struct and functions, and other files normally contain structs and functions assisting the core ones. It would be redundant to prepend the package name to all these files.

Unifying other packages to reponse.go also sounds good.

tnqn
tnqn previously approved these changes Mar 7, 2024
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

This solution refactors the transform functions
for antctl networkpolicy to indicate request and
response. Also adds some additional unit tests.

Signed-off-by: Qiyue Yao <yaoq@vmware.com>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

@antoninbas
Copy link
Contributor

/skip-all

@antoninbas antoninbas merged commit 85a9e2d into antrea-io:main Mar 8, 2024
50 of 55 checks passed
@qiyueyao qiyueyao deleted the antctl-followup branch March 8, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants