-
Notifications
You must be signed in to change notification settings - Fork 254
feat: allows users to specify host ports when creating a cluster #9892
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
432f88d
init
leon-ape e776d95
Merge branch 'main' into support/host-network-ports
leon-ape 03fd33c
update
leon-ape d0e11c6
update API
leon-ape 511673d
map for container ports to host ports
leon-ape dedf53f
update
leon-ape 5626c80
test for port manager
leon-ape File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
58 changes: 58 additions & 0 deletions
58
controllers/apps/component/transformer_component_hostport.go
This file contains hidden or 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,58 @@ | ||
| /* | ||
| Copyright (C) 2022-2025 ApeCloud Co., Ltd | ||
|
|
||
| This file is part of KubeBlocks project | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU Affero General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU Affero General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Affero General Public License | ||
| along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package component | ||
|
|
||
| import ( | ||
| "github.com/apecloud/kubeblocks/pkg/controller/graph" | ||
| ) | ||
|
|
||
| type componentHostPortTransformer struct{} | ||
|
|
||
| var _ graph.Transformer = &componentHostPortTransformer{} | ||
|
|
||
| func (t *componentHostPortTransformer) Transform(ctx graph.TransformContext, dag *graph.DAG) error { | ||
| transCtx, _ := ctx.(*componentTransformContext) | ||
| if isCompDeleting(transCtx.ComponentOrig) { | ||
| return nil | ||
| } | ||
|
|
||
| synthesizedComp := transCtx.SynthesizeComponent | ||
| if synthesizedComp == nil || | ||
| synthesizedComp.PodSpec.HostNetwork || | ||
| synthesizedComp.Network == nil || | ||
| synthesizedComp.Network.HostNetwork { | ||
| return nil | ||
| } | ||
|
|
||
| ports := map[string]int32{} | ||
| for _, hostPort := range synthesizedComp.Network.HostPorts { | ||
| ports[hostPort.Name] = hostPort.Port | ||
| } | ||
| if len(ports) > 0 { | ||
| for i, c := range synthesizedComp.PodSpec.Containers { | ||
| for j, p := range c.Ports { | ||
| if hostPort, ok := ports[p.Name]; ok { | ||
| synthesizedComp.PodSpec.Containers[i].Ports[j].HostPort = hostPort | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the HostPort allocated here be conflict with the ports automatically allocated by portmanager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be guaranteed by the user. Either turn off the default port manager or assign a separate port range to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Another question. What if two containers have defined ports with a same name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
K8s requires that each named port in a Pod must have a unique name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like when using hostNetwork, ports defined in hostPorts spec also won't be managed by portmanager?