Skip to content

ensure ingress-nginx node label is applied#377

Merged
nimakaviani merged 2 commits intocnoe-io:mainfrom
nabuskey:ensure-nginx-label
Aug 29, 2024
Merged

ensure ingress-nginx node label is applied#377
nimakaviani merged 2 commits intocnoe-io:mainfrom
nabuskey:ensure-nginx-label

Conversation

@nabuskey
Copy link
Copy Markdown
Collaborator

fixes: #366
fixes: #367

Signed-off-by: Manabu McCloskey <manabu.mccloskey@gmail.com>
Copy link
Copy Markdown
Contributor

@nimakaviani nimakaviani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a minor typo and a comment

Comment on lines +258 to +279

nodes:
for i := range parsedCluster.Nodes {
node := parsedCluster.Nodes[i]
for _, pm := range node.ExtraPortMappings {
if strconv.Itoa(int(pm.HostPort)) == c.cfg.Port {
appendNecessaryPort = false
nodePosition = i
if node.Labels != nil {
v, ok := node.Labels[ingressNginxNodeLabelKey]
if ok && v == ingressNginxNodeLabelValue {
appendIngresNodeLabel = false
}
}
break nodes
}
}
if node.Labels != nil {
v, ok := node.Labels[ingressNginxNodeLabelKey]
if ok && v == ingressNginxNodeLabelValue {
appendIngresNodeLabel = false
nodePosition = i
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this can be further simplified. I am not fond of label breaks in go, but leave it up to you.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really just comes down to last one winning or the first one winning. I chose first one winning. If we do last one wins, we can avoid using label breaks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like first one winning too.

Here is an alternative way of writing it (thanks ChatGPT). I dont think it is any easier tho. let's leave it.

for i, node := range parsedCluster.Nodes {
    checkNodeLabels := func() {
        if node.Labels != nil {
            if v, ok := node.Labels[ingressNginxNodeLabelKey]; ok && v == ingressNginxNodeLabelValue {
                appendIngresNodeLabel = false
            }
        }
    }

    for _, pm := range node.ExtraPortMappings {
        if strconv.Itoa(int(pm.HostPort)) == c.cfg.Port {
            appendNecessaryPort = false
            nodePosition = i
            checkNodeLabels()
            break
        }
    }

    if appendNecessaryPort { // If the port was not matched, check labels
        checkNodeLabels()
        if !appendIngresNodeLabel {
            nodePosition = i
            break
        }
    }
}

Signed-off-by: Manabu McCloskey <manabu.mccloskey@gmail.com>
@nimakaviani nimakaviani self-requested a review August 29, 2024 22:14
Copy link
Copy Markdown
Contributor

@nimakaviani nimakaviani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nimakaviani nimakaviani merged commit caf882e into cnoe-io:main Aug 29, 2024
tapas4java pushed a commit to tapas4java/idpbuilder that referenced this pull request Sep 3, 2024
Signed-off-by: Manabu McCloskey <manabu.mccloskey@gmail.com>
Signed-off-by: Tapas Jena <tapas.friends@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants