Skip to content

Commit

Permalink
Merge pull request #413 from kubeslice/fix-getNodeIp
Browse files Browse the repository at this point in the history
fix: getNodeIP logic for no-network mode
  • Loading branch information
mridulgain authored Nov 14, 2024
2 parents 21a7556 + 6886444 commit 2fd8592
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL'
env:
TRIVY_DB_REPOSITORY: "public.ecr.aws/aquasecurity/trivy-db"

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
Expand Down
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

0 comments on commit 2fd8592

Please sign in to comment.