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 nodeportisolation filter in yurthub #1209

Merged

Conversation

rambohe-ch
Copy link
Member

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:
/kind bug
/kind documentation
/kind enhancement
/kind good-first-issue
/kind feature
/kind question
/kind design
/sig ai
/sig iot
/sig network
/sig storage

/kind feature

What this PR does / why we need it:

add a new filter named nodeportisolation in yurthub in order to make only nodes in specified nodepool can listen on nodePort of service.

Which issue(s) this PR fixes:

Fixes #1183

Special notes for your reviewer:

Does this PR introduce a user-facing change?


other Note

@openyurt-bot
Copy link
Collaborator

@rambohe-ch: GitHub didn't allow me to assign the following users: your_reviewer.

Note that only openyurtio members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:
/kind bug
/kind documentation
/kind enhancement
/kind good-first-issue
/kind feature
/kind question
/kind design
/sig ai
/sig iot
/sig network
/sig storage

/kind feature

What this PR does / why we need it:

add a new filter named nodeportisolation in yurthub in order to make only nodes in specified nodepool can listen on nodePort of service.

Which issue(s) this PR fixes:

Fixes #1183

Special notes for your reviewer:

Does this PR introduce a user-facing change?


other Note

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.

@openyurt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rambohe-ch

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@openyurt-bot openyurt-bot added approved approved size/XL size/XL: 500-999 labels Feb 8, 2023
@rambohe-ch
Copy link
Member Author

@Congrool @yuanmaomao PTAL

@rambohe-ch rambohe-ch force-pushed the add-nodeportisolation-filter branch 2 times, most recently from 0ea2f18 to a285f94 Compare February 8, 2023 07:37
@codecov
Copy link

codecov bot commented Feb 8, 2023

Codecov Report

Merging #1209 (f6eca59) into master (7488bda) will increase coverage by 0.08%.
The diff coverage is 60.95%.

@@            Coverage Diff             @@
##           master    #1209      +/-   ##
==========================================
+ Coverage   53.49%   53.58%   +0.08%     
==========================================
  Files         101      102       +1     
  Lines       12604    12751     +147     
==========================================
+ Hits         6742     6832      +90     
- Misses       5314     5363      +49     
- Partials      548      556       +8     
Flag Coverage Δ
unittests 53.58% <60.95%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/yurthub/filter/nodeportisolation/filter.go 59.85% <59.85%> (ø)
pkg/yurthub/filter/manager/manager.go 69.35% <100.00%> (+0.50%) ⬆️
pkg/yurthub/util/fs/store.go 68.00% <0.00%> (+0.74%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

}

if len(nif.nodeName) == 0 {
return fmt.Errorf("node name for nodePortIsolationFilter is not ready")
Copy link
Member

Choose a reason for hiding this comment

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

"node name for nodePortIsolationFilter is not set" will be more clear

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

if len(svc.Annotations[ServiceAnnotationNodePortIsolation]) != 0 {
enabledNodePools, disabledNodePools := parseNodePoolFromAnnotation(svc.Annotations[ServiceAnnotationNodePortIsolation])
if disabledNodePools.Has(nodePoolName) {
klog.V(2).Infof("nodePort service(%s) is isolated in nodePool(%s) by nodePortIsolationFilter", nsName, nodePoolName)
Copy link
Member

Choose a reason for hiding this comment

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

"nodePort service(%s) is disabled in nodePool(%s) by nodePortIsolationFilter"

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return svc
}

klog.V(2).Infof("nodePort service(%s) is isolated in nodePool(%s) by nodePortIsolationFilter", nsName, nodePoolName)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


// node is not located in NodePool, skip this filter
if len(nodePoolName) == 0 {
return svc
Copy link
Member

Choose a reason for hiding this comment

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

Is it suitable that skipping filter for node that does not in any nodepool?

  1. If users only set enabled nodepools for svcs, it looks strange that such nodePort svcs will also work on these orphan nodes.

  2. But if users only set disabled nodepools for svcs, it's intuitive that these svcs should work on all nodes in other nodepools and all orphan nodes.

  3. If users set both enable nodepools and disable nodepools, it maybe confused because such two sets may overlap. For example, "np1,np2,-np1,-np3", we have to make more clear definition for such case.

Copy link
Member Author

@rambohe-ch rambohe-ch Feb 10, 2023

Choose a reason for hiding this comment

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

I have updated nodepool definition in #1183 as following:

The details of nodeport.openyurt.io/isolation annotation of service:

key: nodeport.openyurt.io/isolation

value: you can combine [np, -np, *] these three string to configure value, the priority is: [ np > -np > * ]

  • np: enable specified NodePort service listening in this nodePool
  • -np: disable specified NodePort service listening in this nodePool
  • *: enable specified NodePort service listening in all nodePools except specified by -np.
  • !: is used for orphan nodes(don't locate in nodepool), if ! is set, disable NodePort service listening on orphan nodes. if ! is not set, enable NodePort service listening on orphan nodes.

for example:

*: enable NodePort service listening in all nodePools
nodepool1, nodepool2: enable NodePort service listening in nodePool1 and nodePool2
-nodepool1, *: enable NodePort service listening in all nodePools except nodePool1
nodepool1,-nodepool2: only enable NodePort service listening in nodePool1
nodepool1, *: enable NodePort service listening in all nodePools
nodepool1, -nodepool1, *: enable NodePort service listening in of nodePools except nodePool1
*, !: enable NodePort service listening in of nodePools except orphan nodes.

Copy link
Member

Choose a reason for hiding this comment

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

nodepool1, -nodepool1, *: enable NodePort service listening in of nodePools except nodePool1

If [ np > -np > * ], I think it should enable NodePort service on all nodepools.

Is there a better way to indicate orphan nodes? Using ! is hard to read I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Congrool As discussed in community meeting, the design has been changed as following:

I will name the new filter as nodeportisolation, and add a new annotation nodeport.openyurt.io/listen for NodePort service in order to trigger nodeportisolation filter in Yurthub.

The details of nodeport.openyurt.io/listen annotation of service:

  • key: nodeport.openyurt.io/listen
  • value: A list of nodepool names that separated by ','
    • foo: enable specified NodePort service listening on nodes of NodePool named foo

    • -foo: disable specified NodePort service listening on nodes of NodePool named fool

    • *: enable specified NodePort service listening on nodes of all NodePools

    • if NodePool name is duplicated in the configuration, we will take the first configuration

    • if NodePool name is not configured, we will disable NodePort listening on nodes of these unconfigured NodePools.

    • orphan nodes(don't locate in NodePool) will be kept the same as native Kubernetes, so NodePort will be listened on orphan nodes.

      for example:

      • foo, bar: enable NodePort service listening on nodes in foo and bar NodePool.
      • foo, *: enable NodePort service listening on nodes of all NodePools
      • -foo, -bar: disable NodePort service listening on nodes of all NodePools
      • -foo, *: disable NodePort service listening only on nodes in foo NodePool
      • foo,-foo: enable NodePort service listening on nodes in foo NodePool
      • -foo: disable NodePort service listening on nodes of all NodePools(include foo NodePool).

}

klog.V(2).Infof("nodePort service(%s) is isolated in nodePool(%s) by nodePortIsolationFilter", nsName, nodePoolName)
return nil
Copy link
Member

Choose a reason for hiding this comment

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

In other case, we return nil to disable the nodeport svc. It looks confusing. For example, we have "np1,-np2" which also implicitly disable this svc in np3, np4 and so on. Users may be confused when encountering this scenario.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@Congrool
Copy link
Member

Congrool commented Feb 9, 2023

Another problem, this filter seems cannot react to the nodepool change, for example the node is moved to another nodepool.

@rambohe-ch rambohe-ch force-pushed the add-nodeportisolation-filter branch from a285f94 to 0b6f4bb Compare February 10, 2023 03:47
@rambohe-ch
Copy link
Member Author

Another problem, this filter seems cannot react to the nodepool change, for example the node is moved to another nodepool.

@Congrool I suppose that node should be reset and re-join when node want to change the nodePool. or maybe we can adapt nodepool change with a new controller in the other pull request.

@Congrool
Copy link
Member

I suppose that node should be reset and re-join when node want to change the nodePool. or maybe we can adapt nodepool change with a new controller in the other pull request.

If so, we may need to add such instruction to our manual.

@rambohe-ch rambohe-ch force-pushed the add-nodeportisolation-filter branch 2 times, most recently from b31b9d3 to a75b1c7 Compare February 16, 2023 09:37
@Congrool
Copy link
Member

Refer to the design of #1183 (comment):

if NodePool name is not configured, we will disable NodePort listening on nodes of these unconfigured NodePools.

When the svc has the annotation key but with no value, like nodeport.openyurt.io/listen:, I think it's more suitable to disable this svc in all nodepools. But currently, it will enable this svc in all nodepools. What do you think ? @rambohe-ch

@rambohe-ch rambohe-ch force-pushed the add-nodeportisolation-filter branch from a75b1c7 to f6eca59 Compare February 20, 2023 07:10
@rambohe-ch
Copy link
Member Author

Refer to the design of #1183 (comment):

if NodePool name is not configured, we will disable NodePort listening on nodes of these unconfigured NodePools.

When the svc has the annotation key but with no value, like nodeport.openyurt.io/listen:, I think it's more suitable to disable this svc in all nodepools. But currently, it will enable this svc in all nodepools. What do you think ? @rambohe-ch

@Congrool you are right, we need to disable this svc in all nodepools if no value configured. i have fixed it, PTAL

@Congrool
Copy link
Member

/lgtm

@openyurt-bot openyurt-bot added the lgtm lgtm label Feb 21, 2023
@openyurt-bot openyurt-bot merged commit a8c48d2 into openyurtio:master Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved approved kind/feature kind/feature lgtm lgtm size/XL size/XL: 500-999
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request]Need support NodePort service isolate
3 participants