-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. support endpointslice filter for keeping service traffic in-bound of nodePool 2. support master service mutation for pod use InClusterConfig access kube-apiserver
- Loading branch information
1 parent
0bc28b7
commit d7083cd
Showing
21 changed files
with
1,242 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2021 The OpenYurt Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package filter | ||
|
||
import "k8s.io/apimachinery/pkg/util/sets" | ||
|
||
type Approver struct { | ||
comp string | ||
resource string | ||
operations sets.String | ||
} | ||
|
||
func NewApprover(comp, resource string, verbs ...string) *Approver { | ||
return &Approver{ | ||
comp: comp, | ||
resource: resource, | ||
operations: sets.NewString(verbs...), | ||
} | ||
} | ||
|
||
func (a *Approver) Approve(comp, resource, verb string) bool { | ||
if a.comp != comp || a.resource != resource { | ||
return false | ||
} | ||
|
||
return a.operations.Has(verb) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2021 The OpenYurt Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package filter | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
|
||
apirequest "k8s.io/apiserver/pkg/endpoints/request" | ||
|
||
"github.com/openyurtio/openyurt/pkg/yurthub/util" | ||
) | ||
|
||
type filterChain []Interface | ||
|
||
func (fc filterChain) Approve(comp, resource, verb string) bool { | ||
for _, f := range fc { | ||
if f.Approve(comp, resource, verb) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (fc filterChain) Filter(req *http.Request, rc io.ReadCloser, stopCh <-chan struct{}) (int, io.ReadCloser, error) { | ||
ctx := req.Context() | ||
comp, ok := util.ClientComponentFrom(ctx) | ||
if !ok { | ||
return 0, rc, nil | ||
} | ||
|
||
info, ok := apirequest.RequestInfoFrom(ctx) | ||
if !ok { | ||
return 0, rc, nil | ||
} | ||
|
||
for _, f := range fc { | ||
if !f.Approve(comp, info.Resource, info.Verb) { | ||
continue | ||
} | ||
|
||
return f.Filter(req, rc, stopCh) | ||
} | ||
|
||
return 0, rc, nil | ||
} |
Oops, something went wrong.