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

fix: getNodeIP logic for no-network mode #413

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func GetSliceGatewayServers(ctx context.Context, c client.Client, sliceName stri
func GetSliceGwServices(ctx context.Context, c client.Client, sliceName string) (*corev1.ServiceList, error) {
sliceGwSvcList := &corev1.ServiceList{}
listOpts := []client.ListOption{
client.InNamespace(ControlPlaneNamespace),
client.MatchingLabels(map[string]string{ApplicationNamespaceSelectorLabelKey: sliceName}),
}

Expand Down
19 changes: 11 additions & 8 deletions pkg/cluster/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,25 @@ type NodeInfo struct {
sync.Mutex
}

//GetNodeExternalIpList gets the list of External Node IPs of kubeslice-gateway nodes

func (n *NodeInfo) getNodeExternalIpList() ([]string, error) {
// When kubeslice network is enabled this method gets the list of External/Internal Node IPs of ready nodes that are labeled as kubeslice-gateway.
// If kubeslice networking is disabled it returns IPs of all ready nodes
func (n *NodeInfo) getNodeExternalIpList(isNetworkPresent bool) ([]string, error) {
n.Lock()
defer n.Unlock()
err := n.populateNodeIpList()
err := n.populateNodeIpList(isNetworkPresent)
if err != nil {
return nil, err
}
return n.NodeIPList, nil
}

func (n *NodeInfo) populateNodeIpList() error {
func (n *NodeInfo) populateNodeIpList(isNetworkPresent bool) error {
ctx := context.Background()
nodeList := corev1.NodeList{}
labels := map[string]string{controllers.NodeTypeSelectorLabelKey: "gateway"}
labels := map[string]string{}
if isNetworkPresent {
labels = map[string]string{controllers.NodeTypeSelectorLabelKey: "gateway"}
}
listOptions := []client.ListOption{
client.MatchingLabels(labels),
}
Expand Down Expand Up @@ -101,10 +104,10 @@ func (n *NodeInfo) populateNodeIpList() error {
return err
}

func GetNodeIP(client client.Client) ([]string, error) {
func GetNodeIP(client client.Client, isNetworkPresent bool) ([]string, error) {
nodeInfo.Client = client
// nodeIPs will either have list of ExternalIPs if available, else Internal IPs
nodeIps, err := nodeInfo.getNodeExternalIpList()
nodeIps, err := nodeInfo.getNodeExternalIpList(isNetworkPresent)
if err != nil || len(nodeIps) == 0 {
log.Error(err, "Getting NodeIP From kube-api-server")
return []string{""}, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/hub/controllers/cluster/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func (r *Reconciler) updateNodeIps(ctx context.Context, cr *hubv1alpha1.Cluster)
if err != nil {
return err
}
nodeIPs, err := cluster.GetNodeIP(r.MeshClient)
nodeIPs, err := cluster.GetNodeIP(r.MeshClient, cr.Status.NetworkPresent)
if err != nil {
log.Error(err, "Error Getting nodeIP")
return err
Expand Down
Loading