Skip to content

Commit b7ab0ed

Browse files
committed
update
1 parent e776d95 commit b7ab0ed

File tree

22 files changed

+417
-110
lines changed

22 files changed

+417
-110
lines changed

apis/apps/v1/types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,20 +257,26 @@ type ComponentNetwork struct {
257257
// +optional
258258
DNSConfig *corev1.PodDNSConfig `json:"dnsConfig,omitempty"`
259259

260-
// Specifies the host ports of the pod[ explicitly.
260+
// Specifies the host ports of the pod.
261261
// It's valid if and only if the `hostNetwork` is enabled.
262262
//
263+
// If any host ports are specified, the default host-port manager provided by KB will be ignored.
264+
// Therefore, it is the user's responsibility to specify all container ports that need to be bound to host ports.
265+
// Check @cmpd.spec.hostNetwork to obtain all container ports that need to be bound.
266+
//
267+
// !!!!! When you specify the host ports, you must specify two additional ports for the kbagent sidecar of KB: 'http', 'streaming'.
268+
//
263269
// +optional
264270
HostPorts []HostPort `json:"hostPorts,omitempty"`
265271
}
266272

267273
type HostPort struct {
268-
// Name is the name of the host port.
274+
// The name of the host port.
269275
//
270276
// +kubebuilder:validation:Required
271277
Name string `json:"name"`
272278

273-
// Port is the port number of the host port.
279+
// The port number of the host port.
274280
//
275281
// +kubebuilder:validation:Minimum=1
276282
// +kubebuilder:validation:Maximum=65535

apis/apps/v1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/manager/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func main() {
417417
client = multiClusterMgr.GetClient()
418418
}
419419

420-
if err := intctrlutil.InitHostPortManager(mgr.GetClient()); err != nil {
420+
if err := intctrlutil.InitDefaultHostPortManager(mgr.GetClient()); err != nil {
421421
setupLog.Error(err, "unable to init port manager")
422422
os.Exit(1)
423423
}

config/crd/bases/apps.kubeblocks.io_clusters.yaml

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,7 @@ spec:
27092709
description: Defines the network configuration for the Component.
27102710
properties:
27112711
dnsConfig:
2712-
description: Specifies the DNS parameters of a pod.
2712+
description: Specifies the DNS parameters of the pod.
27132713
properties:
27142714
nameservers:
27152715
description: |-
@@ -2774,6 +2774,34 @@ spec:
27742774
description: Host networking requested for this pod. Use
27752775
the host's network namespace.
27762776
type: boolean
2777+
hostPorts:
2778+
description: |-
2779+
Specifies the host ports of the pod.
2780+
It's valid if and only if the `hostNetwork` is enabled.
2781+
2782+
2783+
If any host ports are specified, the default host-port manager provided by KB will be ignored.
2784+
Therefore, it is the user's responsibility to specify all container ports that need to be bound to host ports.
2785+
Check @cmpd.spec.hostNetwork to obtain all container ports that need to be bound.
2786+
2787+
2788+
!!!!! When you specify the host ports, you must specify two additional ports for the kbagent sidecar of KB: 'http', 'streaming'.
2789+
items:
2790+
properties:
2791+
name:
2792+
description: The name of the host port.
2793+
type: string
2794+
port:
2795+
description: The port number of the host port.
2796+
format: int32
2797+
maximum: 65535
2798+
minimum: 1
2799+
type: integer
2800+
required:
2801+
- name
2802+
- port
2803+
type: object
2804+
type: array
27772805
type: object
27782806
offlineInstances:
27792807
description: |-
@@ -13959,7 +13987,7 @@ spec:
1395913987
description: Defines the network configuration for the Component.
1396013988
properties:
1396113989
dnsConfig:
13962-
description: Specifies the DNS parameters of a pod.
13990+
description: Specifies the DNS parameters of the pod.
1396313991
properties:
1396413992
nameservers:
1396513993
description: |-
@@ -14024,6 +14052,34 @@ spec:
1402414052
description: Host networking requested for this pod.
1402514053
Use the host's network namespace.
1402614054
type: boolean
14055+
hostPorts:
14056+
description: |-
14057+
Specifies the host ports of the pod.
14058+
It's valid if and only if the `hostNetwork` is enabled.
14059+
14060+
14061+
If any host ports are specified, the default host-port manager provided by KB will be ignored.
14062+
Therefore, it is the user's responsibility to specify all container ports that need to be bound to host ports.
14063+
Check @cmpd.spec.hostNetwork to obtain all container ports that need to be bound.
14064+
14065+
14066+
!!!!! When you specify the host ports, you must specify two additional ports for the kbagent sidecar of KB: 'http', 'streaming'.
14067+
items:
14068+
properties:
14069+
name:
14070+
description: The name of the host port.
14071+
type: string
14072+
port:
14073+
description: The port number of the host port.
14074+
format: int32
14075+
maximum: 65535
14076+
minimum: 1
14077+
type: integer
14078+
required:
14079+
- name
14080+
- port
14081+
type: object
14082+
type: array
1402714083
type: object
1402814084
offlineInstances:
1402914085
description: |-

config/crd/bases/apps.kubeblocks.io_components.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,7 @@ spec:
24882488
description: Defines the network configuration for the Component.
24892489
properties:
24902490
dnsConfig:
2491-
description: Specifies the DNS parameters of a pod.
2491+
description: Specifies the DNS parameters of the pod.
24922492
properties:
24932493
nameservers:
24942494
description: |-
@@ -2553,6 +2553,34 @@ spec:
25532553
description: Host networking requested for this pod. Use the host's
25542554
network namespace.
25552555
type: boolean
2556+
hostPorts:
2557+
description: |-
2558+
Specifies the host ports of the pod.
2559+
It's valid if and only if the `hostNetwork` is enabled.
2560+
2561+
2562+
If any host ports are specified, the default host-port manager provided by KB will be ignored.
2563+
Therefore, it is the user's responsibility to specify all container ports that need to be bound to host ports.
2564+
Check @cmpd.spec.hostNetwork to obtain all container ports that need to be bound.
2565+
2566+
2567+
!!!!! When you specify the host ports, you must specify two additional ports for the kbagent sidecar of KB: 'http', 'streaming'.
2568+
items:
2569+
properties:
2570+
name:
2571+
description: The name of the host port.
2572+
type: string
2573+
port:
2574+
description: The port number of the host port.
2575+
format: int32
2576+
maximum: 65535
2577+
minimum: 1
2578+
type: integer
2579+
required:
2580+
- name
2581+
- port
2582+
type: object
2583+
type: array
25562584
type: object
25572585
offlineInstances:
25582586
description: |-

controllers/apps/cluster/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ var _ = BeforeSuite(func() {
162162
viper.SetDefault("HOST_PORT_CM_NAME", "kubeblocks-host-ports")
163163
viper.SetDefault(constant.EnableRBACManager, true)
164164

165-
err = intctrlutil.InitHostPortManager(k8sClient)
165+
err = intctrlutil.InitDefaultHostPortManager(k8sClient)
166166
Expect(err).ToNot(HaveOccurred())
167167

168168
err = (&apps.ClusterDefinitionReconciler{

controllers/apps/component/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ var _ = BeforeSuite(func() {
168168
viper.SetDefault("HOST_PORT_CM_NAME", "kubeblocks-host-ports")
169169
viper.SetDefault(constant.EnableRBACManager, true)
170170

171-
err = intctrlutil.InitHostPortManager(k8sClient)
171+
err = intctrlutil.InitDefaultHostPortManager(k8sClient)
172172
Expect(err).ToNot(HaveOccurred())
173173

174174
err = (&apps.ComponentDefinitionReconciler{

controllers/apps/component/transformer_component_deletion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (t *componentDeletionTransformer) deleteCompResources(transCtx *componentTr
147147
}
148148

149149
// release the allocated host-network ports for the component
150-
pm := intctrlutil.GetPortManager()
150+
pm := intctrlutil.GetPortManager(comp.Spec.Network)
151151
if err = pm.ReleaseByPrefix(comp.Name); err != nil {
152152
return intctrlutil.NewRequeueError(time.Second*1, fmt.Sprintf("release host ports for component %s error: %s", comp.Name, err.Error()))
153153
}

controllers/apps/component/transformer_component_hostnetwork.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ func (t *componentHostNetworkTransformer) Transform(ctx graph.TransformContext,
4343
}
4444

4545
synthesizedComp := transCtx.SynthesizeComponent
46-
ports, err := allocateHostPorts(synthesizedComp)
46+
ports, err := t.allocateHostPorts(synthesizedComp)
4747
if err != nil {
4848
return err
4949
}
5050

5151
comp := transCtx.Component
52-
updateObjectsWithAllocatedPorts(synthesizedComp, comp, ports)
52+
t.updateObjectsWithAllocatedPorts(synthesizedComp, comp, ports)
5353

5454
return nil
5555
}
5656

57-
func allocateHostPorts(synthesizedComp *component.SynthesizedComponent) (map[string]map[string]int32, error) {
57+
func (t *componentHostNetworkTransformer) allocateHostPorts(synthesizedComp *component.SynthesizedComponent) (map[string]map[string]int32, error) {
5858
ports := map[string]map[string]bool{}
5959
for _, c := range synthesizedComp.HostNetwork.ContainerPorts {
6060
for _, p := range c.Ports {
@@ -65,18 +65,18 @@ func allocateHostPorts(synthesizedComp *component.SynthesizedComponent) (map[str
6565
}
6666
}
6767

68-
pm := intctrlutil.GetPortManager()
68+
pm := intctrlutil.GetPortManager(synthesizedComp.Network)
6969
needAllocate := func(c string, p string) bool {
7070
containerPorts, ok := ports[c]
7171
if !ok {
7272
return false
7373
}
7474
return containerPorts[p]
7575
}
76-
return allocateHostPortsWithFunc(pm, synthesizedComp, needAllocate)
76+
return t.allocateHostPortsWithFunc(pm, synthesizedComp, needAllocate)
7777
}
7878

79-
func allocateHostPortsWithFunc(pm *intctrlutil.PortManager, synthesizedComp *component.SynthesizedComponent,
79+
func (t *componentHostNetworkTransformer) allocateHostPortsWithFunc(pm intctrlutil.PortManager, synthesizedComp *component.SynthesizedComponent,
8080
needAllocate func(string, string) bool) (map[string]map[string]int32, error) {
8181
ports := map[string]map[string]int32{}
8282
insert := func(c, pk string, pv int32) {
@@ -87,7 +87,7 @@ func allocateHostPortsWithFunc(pm *intctrlutil.PortManager, synthesizedComp *com
8787
}
8888
for _, c := range synthesizedComp.PodSpec.Containers {
8989
for _, p := range c.Ports {
90-
portKey := intctrlutil.BuildHostPortName(synthesizedComp.ClusterName, synthesizedComp.Name, c.Name, p.Name)
90+
portKey := pm.PortKey(synthesizedComp.ClusterName, synthesizedComp.Name, c.Name, p.Name)
9191
if needAllocate(c.Name, p.Name) {
9292
port, err := pm.AllocatePort(portKey)
9393
if err != nil {
@@ -104,7 +104,7 @@ func allocateHostPortsWithFunc(pm *intctrlutil.PortManager, synthesizedComp *com
104104
return ports, nil
105105
}
106106

107-
func updateObjectsWithAllocatedPorts(synthesizedComp *component.SynthesizedComponent,
107+
func (t *componentHostNetworkTransformer) updateObjectsWithAllocatedPorts(synthesizedComp *component.SynthesizedComponent,
108108
comp *appsv1.Component, ports map[string]map[string]int32) {
109109
synthesizedComp.PodSpec.HostNetwork = true
110110
if comp.Spec.Network != nil && comp.Spec.Network.DNSPolicy != nil {

controllers/apps/rollout/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ var _ = BeforeSuite(func() {
124124
viper.SetDefault("HOST_PORT_CM_NAME", "kubeblocks-host-ports")
125125
viper.SetDefault(constant.EnableRBACManager, true)
126126

127-
err = intctrlutil.InitHostPortManager(k8sClient)
127+
err = intctrlutil.InitDefaultHostPortManager(k8sClient)
128128
Expect(err).ToNot(HaveOccurred())
129129

130130
err = (&RolloutReconciler{

0 commit comments

Comments
 (0)