Skip to content

Conversation

@vakalapa
Copy link
Contributor

@vakalapa vakalapa commented Nov 24, 2021

Reason for Change:

Windows NPM dataplane does not support negative matches and named ports, so adding these two translation feature gates to warn user in controllers.

Issue Fixed:

Requirements:

Notes:

@vakalapa
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

var members []string
switch op := req.Operator; op {
op := req.Operator
if invalidWindowsOperatorLimitation(op) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: slightly better unsupportedOpsInWindows instead of invalidWindowsOperatorLimitation
no strong opinion.

var (
errUnknownPortType = errors.New("unknown port Type")
// ErrUnsupportedTranslationFeature is returned when translation feature is not supported.
ErrUnsupportedTranslationFeature = errors.New("unsupported Windows translation feature")
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: slightly better to have specific error message which features do not support.
For example,

ErrUnsupportedNamedPort = errors.New("unsupported namedport on windows ")
ErrUnsupportedNegativeMatch= errors.New("unsupported NotExist on windows ")

no strong opinion.

// So, start translating egress policy.
for i, rule := range egress {
translateRule(npmNetPol, policies.Egress, policies.DstMatch, i, rule.Ports, rule.To)
err := translateRule(npmNetPol, policies.Egress, policies.DstMatch, i, rule.Ports, rule.To)
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: may be better to isolate err variable in if statement.

if err := ingressPolicy(npmNetPol, npObj.Spec.Ingress); err != nil {
     return nil, err
}

No strong opinion.

@JungukCho
Copy link
Contributor

In the future, validatingadmissionwebhook will be useful - https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#validatingadmissionwebhook to filter unsupported network policy submission.

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

just some nitpicks

}

func invalidWindowsOperatorLimitation(op metav1.LabelSelectorOperator) bool {
if isWindows() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick:
return isWindows() && (op == ... || op == ...)

return npmNetPol, nil
}

func invalidWindowsOperatorLimitation(op metav1.LabelSelectorOperator) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: looks like we just use this in parseSelector.go. Can we put it in that file?

return false
}

func isWindows() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: we use isWindows() in this file but use runtime.GOOS == "windows" in pod controller. To keep consistency, can we either make isWindows a util func and use in pod controller or just use the boolean in all places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moving this to util as IsWindowsDP.

@huntergregory huntergregory added the npm Related to NPM. label Dec 1, 2021
@vakalapa
Copy link
Contributor Author

vakalapa commented Dec 5, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

return nil
}
klog.Errorf("Failed to translate podSelector in NetworkPolicy %s in namespace %s: %s", netPolObj.ObjectMeta.Name, netPolObj.ObjectMeta.Namespace, err.Error())
return errNetPolTranslationFailure
Copy link
Contributor

Choose a reason for hiding this comment

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

no preference: should we wrap the translatiion error for better context?
npmerrors.SimpleErrorWrapper("failed to translate network policy", err)

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 mean we can see this error message in logs anyway. I did not want to spam the same message multiple times.

@vakalapa vakalapa merged commit 2ea1387 into master Dec 7, 2021
@vakalapa vakalapa deleted the vakr/winnpmtranslationgate branch December 7, 2021 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

npm Related to NPM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants