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 option to add/remove a specific port/env var of a specific container #131

Merged
merged 6 commits into from
Feb 17, 2022

Conversation

valaparthvi
Copy link
Contributor

What does this PR do?:

This PR modifies devfileObj methods such as SetPorts to allow setting port to a specific container, and RemovePorts to remove a specific port of a specific container.

Which issue(s) this PR fixes:

redhat-developer/odo#5423

PR acceptance criteria:

Testing and documentation do not need to be complete in order for this PR to be approved. We just need to ensure tracking issues are opened.

  • Open new test/doc issues under the devfile/api repo
  • Check each criteria if:
  • There is a separate tracking issue. Add the issue link under the criteria
    or
  • test/doc updates are made as part of this PR
  • If unchecked, explain why it's not needed

How to test changes / Special notes to the reviewer:

The unit tests should help give an idea about the PR changes.

Copy link
Collaborator

@yangcao77 yangcao77 left a comment

Choose a reason for hiding this comment

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

Changes look good. Just need to update the function description for the new behavior.

@@ -80,14 +81,18 @@ func (d DevfileObj) SetPorts(ports ...string) error {
}

// RemovePorts removes all container endpoints from a devfile
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function description should be updated

@@ -61,16 +61,17 @@ func (d DevfileObj) RemoveEnvVars(keys []string) (err error) {
}

// SetPorts converts ports to endpoints, adds to a devfile
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the description for the new behavior

// now check if the port(s) requested for removal exists in
// the ports set for the component
for _, port := range ports {
if !InArray(portList, port) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can replace portList to a map. the key look up for a map is O(1), and the InArray here is looking for a key in Array, which will need to iterate through the array again and is slower.
Also, since you are iterating the ports array here, you can also store the ports information in a map, and replace the below InArray lookup when doing the endpoints removal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also help update the initial InArray usage in RemoveEnvVarsFromList? and also the InArray function? Thanks.

// SetPorts converts ports to endpoints, adds to a devfile
func (d DevfileObj) SetPorts(ports ...string) error {
// SetPorts accepts a map of container name and the port numbers to be set;
// it converts ports to endpoints, and adds to a devfile
Copy link
Collaborator

Choose a reason for hiding this comment

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

please update the description as this PR changes the existing behavior. currently it will set the ports to all container components, and this change will look for specific component and add the endpoint.

@valaparthvi
Copy link
Contributor Author

/hold

@valaparthvi
Copy link
Contributor Author

/unhold

@valaparthvi
Copy link
Contributor Author

@yangcao77 I have modified the existing devfileObj methods and added a few new methods to the DevfileData interface. Reason being, we wanted methods that would update the devfile data without writing to the actual file.

@valaparthvi valaparthvi changed the title Add option to remove a specific port, and add port to a specific container Add option to remove a specific port/env var, and add port/env var to a specific container Feb 16, 2022
corev1 "k8s.io/api/core/v1"
)

func (d *DevfileV2) AddEnvVars(containerEnvMap map[string][]v1alpha2.EnvVar) error {
Copy link
Collaborator

@yangcao77 yangcao77 Feb 16, 2022

Choose a reason for hiding this comment

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

Can you add some description comments for those exposed functions?

Signed-off-by: Parthvi Vala <[email protected]>
Copy link
Collaborator

@yangcao77 yangcao77 left a comment

Choose a reason for hiding this comment

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

Changes look good to me.

@openshift-ci openshift-ci bot added the lgtm label Feb 16, 2022
@openshift-ci
Copy link

openshift-ci bot commented Feb 16, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: valaparthvi, yangcao77

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@valaparthvi valaparthvi changed the title Add option to remove a specific port/env var, and add port/env var to a specific container Add option to add/remove a specific port/env var of a specific container Feb 17, 2022
@yangcao77 yangcao77 merged commit 0f59955 into devfile:main Feb 17, 2022
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.

2 participants