Skip to content

Commit

Permalink
fix: Modify node IP selection logic
Browse files Browse the repository at this point in the history
Signed-off-by: baoyinghai_yewu <[email protected]>
  • Loading branch information
OrangeBao committed Sep 19, 2024
1 parent 65947bd commit 06cd604
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cluster/images/agent.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:latest as release-env
FROM ubuntu:latest AS release-env

ARG BINARY

Expand Down
2 changes: 1 addition & 1 deletion cluster/images/buildx.agent.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:latest as release-env
FROM ubuntu:latest AS release-env

ARG BINARY
ARG TARGETPLATFORM
Expand Down
2 changes: 1 addition & 1 deletion deploy/crds/kosmos.io_kubenestconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ spec:
type: string
type: array
type: object
useTenantDns:
useTenantDNS:
default: false
type: boolean
type: object
Expand Down
2 changes: 1 addition & 1 deletion deploy/crds/kosmos.io_virtualclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ spec:
type: string
type: array
type: object
useTenantDns:
useTenantDNS:
default: false
type: boolean
type: object
Expand Down
2 changes: 1 addition & 1 deletion pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/kubenest/constants/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package constants
import (
"time"

corev1 "k8s.io/api/core/v1"

"github.com/kosmos.io/kosmos/pkg/utils"
)

Expand Down Expand Up @@ -142,8 +144,12 @@ type Action string
var APIServerServiceSubnet string
var KubeControllerManagerPodSubnet string

var PreferredAddressType corev1.NodeAddressType

func init() {
APIServerServiceSubnet = utils.GetEnvWithDefaultValue("SERVICE_SUBNET", "10.237.6.0/18")
// fd11:1122:1111::/48,
KubeControllerManagerPodSubnet = utils.GetEnvWithDefaultValue("POD_SUBNET", "10.244.0.0/16")

PreferredAddressType = corev1.NodeAddressType(utils.GetEnvWithDefaultValue("PREFERRED_ADDRESS_TYPE", string(corev1.NodeInternalIP)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ func (r *GlobalNodeController) Reconcile(ctx context.Context, request reconcile.
}
globalNode.Name = request.Name
globalNode.Spec.State = v1alpha1.NodeReserved
firstNodeIP, err := utils.FindFirstNodeIPAddress(*rootNode, v1.NodeInternalIP)
firstNodeIP, err := utils.FindFirstNodeIPAddress(*rootNode, constants.PreferredAddressType)
if err != nil {
klog.Errorf("get first node ip address err: %s %s", v1.NodeInternalIP, err.Error())
klog.Errorf("get first node ip address err: %s %s", constants.PreferredAddressType, err.Error())
}
globalNode.Spec.NodeIP = firstNodeIP
if _, err = r.KosmosClient.KosmosV1alpha1().GlobalNodes().Create(ctx, &globalNode, metav1.CreateOptions{}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubenest/controller/virtualcluster_init_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ func (c *VirtualClusterInitController) findHostAddresses() ([]string, error) {
ret := []string{}

for _, node := range nodes.Items {
addr, err := utils.FindFirstNodeIPAddress(node, corev1.NodeExternalIP)
addr, err := utils.FindFirstNodeIPAddress(node, constants.PreferredAddressType)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubenest/controlplane/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func installEtcd(client clientset.Interface, name, namespace string, kubeNestCon
var resourceQuantity resource.Quantity
var err error

if vc.Spec.KubeInKubeConfig.ETCDUnitSize != "" {
if vc.Spec.KubeInKubeConfig != nil && vc.Spec.KubeInKubeConfig.ETCDUnitSize != "" {
resourceQuantity, err = resource.ParseQuantity(vc.Spec.KubeInKubeConfig.ETCDUnitSize)
if err != nil {
klog.Errorf("Failed to parse etcdSize %s: %v", vc.Spec.KubeInKubeConfig.ETCDUnitSize, err)
Expand All @@ -56,7 +56,6 @@ func installEtcd(client clientset.Interface, name, namespace string, kubeNestCon
return err
}
resourceQuantity.Set(resourceQuantity.Value() * int64(nodeCount))

}

initialClusters := make([]string, constants.EtcdReplicas)
Expand Down

0 comments on commit 06cd604

Please sign in to comment.