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

Add variable to enable to specify the name of port in the service #801

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

sonali-rajput
Copy link

@sonali-rajput sonali-rajput commented Mar 6, 2023

Changes

Fixes #736
Add variable in the helm chart to enable to specify the name of port in the service.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS.

Release Notes

Describe any user facing changes here, or delete this block.

Examples of user facing changes:
- API changes
- Bug fixes
- Any changes in behavior

@sonali-rajput
Copy link
Author

@brokenpip3 Can you please suggest me the changes I need to make in the test?

@brokenpip3
Copy link
Collaborator

Hi @sonali-rajput thanks for your contribution!

@brokenpip3 Can you please suggest me the changes I need to make in the test?

You can just merge/rebase master here.

@@ -26,7 +26,7 @@ spec:
image: {{ .Values.operator.image }}
imagePullPolicy: {{ .Values.operator.imagePullPolicy }}
ports:
- name: http
- name: {{ .Values.portName }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the original issue the request was to have the possibility of specifying the name of the port of the result jenkins pod not the operator.
This will require to add a serviceName here and more golang code, finally the helm chart change.
If you are looking to something more easy to do I can suggest you to take a look on the others good-first-issue issue :)
If don't you can start with some changes and we can double check the code together :)

Copy link
Author

Choose a reason for hiding this comment

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

I am new to all this but I'll try to resolve this issue as soon as I can and get back to you. Thank you for guiding me in this, I really appreciate that.

Copy link
Author

Choose a reason for hiding this comment

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

@brokenpip3 Is that right?

Copy link
Member

@iamrajiv iamrajiv left a comment

Choose a reason for hiding this comment

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

@sonali-rajput I suggest removing redundant checks and refactoring the code to improve readability and efficiency. The refactored code for validating Jenkins API connection settings looks like this:

func (j JenkinsAPIConnectionSettings) Validate() error {
    if j.Port < 0 {
        return errors.New("service port cannot be lower than 0")
    }
    if j.Hostname == "" {
        return errors.New("empty hostname is not allowed. Please provide hostname")
    }
    if j.Portname == "" {
        return errors.New("empty portname is not allowed. Please provide portname")
    }
    if j.Port > 0 && j.UseNodePort {
        return errors.New("cannot use service port and nodePort at the same time. Please use port or nodePort")
    }
    return nil
}

This code checks for negative service port values first, then validates the hostname and portname fields for emptiness. Finally, it checks whether the service port and nodePort are both set, which is not allowed.

Copy link
Collaborator

@brokenpip3 brokenpip3 left a comment

Choose a reason for hiding this comment

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

Overall looks ok!
I left a couple of comments and also:

  • we also need to add the helm chart template modifications to support the port name (we need to provide a default: http)
  • we also need to take care of the CRD part:

main.go Outdated
@@ -94,6 +94,7 @@ func main() {
port := flag.Int("jenkins-api-port", 0, "The port on which Jenkins API is running. Note: If you want to use nodePort don't set this setting and --jenkins-api-use-nodeport must be true.")
useNodePort := flag.Bool("jenkins-api-use-nodeport", false, "Connect to Jenkins API using the service nodePort instead of service port. If you want to set this as true - don't set --jenkins-api-port.")
kubernetesClusterDomain := flag.String("cluster-domain", "cluster.local", "Use custom domain name instead of 'cluster.local'.")
portName := flag.String("jenkins-api-portname", "default", "The port name given to the service.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why we should specify the port name in the commandline options?

main.go Outdated
@@ -158,7 +159,7 @@ func main() {
go notifications.Listen(notificationEvents, events, mgr.GetClient())

// validate jenkins API connection
jenkinsAPIConnectionSettings := client.JenkinsAPIConnectionSettings{Hostname: *hostname, Port: *port, UseNodePort: *useNodePort}
jenkinsAPIConnectionSettings := client.JenkinsAPIConnectionSettings{Hostname: *hostname, Port: *port, UseNodePort: *useNodePort, Portname: *portName}
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

@@ -130,6 +131,10 @@ func (j JenkinsAPIConnectionSettings) Validate() error {
return errors.New("empty hostname is now allowed. Please provide hostname")
}

if (j.Portname == "" && j.Port > 0) || (j.Portname == "" && j.UseNodePort) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should avoid to force a port name, we don't need it to let the operator or jenkins run, we just need it in the CRDs to be added in the helm chart and consumed by the operator while creating the jenkins pod

Copy link
Author

Choose a reason for hiding this comment

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

@brokenpip3 I have made the required changes. Can you please review it? (sorry for the late reply I was busy preparing for GSoC'23)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Like this that field is not consumed by the operator while creating the jenkins pod, you need to add some code in pkg/configuration/base/resources/service.go where also you need to add the default http as port name if is not defined in the crd :)

Copy link
Author

Choose a reason for hiding this comment

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

Okay I will make the changes.

@sonali-rajput
Copy link
Author

Hi @brokenpip3 I don't understand why the workflows have been running in my forked repository here https://github.com/sonali-rajput/kubernetes-operator/actions it should not be running in my repo unless I did it manually right?

@brokenpip3
Copy link
Collaborator

yup unfortunately when you enabled the workflow from the fork all the workflow will be run, not only the e2e tests one :)
Are you actively working on this PR? I saw some new commits

@brokenpip3
Copy link
Collaborator

I took a look on the latest changes, looks good 👍
You only miss one thing: in the service.go you need to specify the default value http unless the user will provide another name.
Last bit: can you add a bats test that will double check if the port name is the right one? If need help let me know I can push that change as soon you have modified the service.go :)

@sonali-rajput
Copy link
Author

sonali-rajput commented May 4, 2023

I took a look on the latest changes, looks good 👍 You only miss one thing: in the service.go you need to specify the default value http unless the user will provide another name. Last bit: can you add a bats test that will double check if the port name is the right one? If need help let me know I can push that change as soon you have modified the service.go :)

Hi @brokenpip3 I have made the changes but I made a mistake earlier while committing the changes the commits done by you also appeared in my commit so I did git reset --hard then forced push the changes. But it is not the right way to do this right? Can you please help me here?

@brokenpip3
Copy link
Collaborator

I took a look on the latest changes, looks good +1 You only miss one thing: in the service.go you need to specify the default value http unless the user will provide another name. Last bit: can you add a bats test that will double check if the port name is the right one? If need help let me know I can push that change as soon you have modified the service.go :)

Hi @brokenpip3 I have made the changes but I made a mistake earlier while committing the changes the commits done by you also appeared in my commit so I did git reset --hard then forced push the changes. But it is not the right way to do this right? Can you please help me here?

whatever git flow you followed the git history looks good :)
don't worry about the bats test, I will add the specific test

as soon this #835 will be merged in master merge/rebase master in your branch so we can fix the ci and finally we can merge this PR 🎉

@sonali-rajput
Copy link
Author

I took a look on the latest changes, looks good +1 You only miss one thing: in the service.go you need to specify the default value http unless the user will provide another name. Last bit: can you add a bats test that will double check if the port name is the right one? If need help let me know I can push that change as soon you have modified the service.go :)

Hi @brokenpip3 I have made the changes but I made a mistake earlier while committing the changes the commits done by you also appeared in my commit so I did git reset --hard then forced push the changes. But it is not the right way to do this right? Can you please help me here?

whatever git flow you followed the git history looks good :) don't worry about the bats test, I will add the specific test

as soon this #835 will be merged in master merge/rebase master in your branch so we can fix the ci and finally we can merge this PR 🎉

Alright! @brokenpip3 😊 Thanks for helping me with the PR.

@brokenpip3
Copy link
Collaborator

Thanks to you! I will let you know when you can merge master in your branch so we can pass the tests and finally merge this PR :)

@brokenpip3
Copy link
Collaborator

hi @sonali-rajput could you please merge master branch in your branch? I want to see the tests ✔️ so we can finally merge the PR for the upcoming v0.8.0, thanks a lot!

brokenpip3 and others added 7 commits June 10, 2023 11:27
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@sonali-rajput
Copy link
Author

hi @sonali-rajput could you please merge master branch in your branch? I want to see the tests heavy_check_mark so we can finally merge the PR for the upcoming v0.8.0, thanks a lot!

Is that alright? I have rebased master on my branch

@github-actions github-actions bot added the stale label Aug 10, 2023
@github-actions github-actions bot closed this Aug 18, 2023
@brokenpip3 brokenpip3 reopened this Aug 18, 2023
@github-actions github-actions bot removed the stale label Aug 19, 2023
@github-actions github-actions bot added the stale label Oct 18, 2023
@github-actions github-actions bot closed this Oct 25, 2023
@brokenpip3 brokenpip3 reopened this Oct 25, 2023
@lavigneer
Copy link

HI! This change would be quite helpful for a project I'm working on that involves the Prometheus operator that needs port names for its ServiceMonitor CRD. Are there any tasks for this PR that are outstanding that I can assist with? I'm happy to help where I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unable to specify a name of the port in services will be created by Jenkins Operator
5 participants