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 new --run-port flag to odo init to set ports non-interactively #6953

Conversation

rm3l
Copy link
Member

@rm3l rm3l commented Jul 6, 2023

What type of PR is this:
/kind feature
/area init

What does this PR do / why we need it:
This introduces a new --run-port repeatable flag to odo init, allowing to set application ports non-interactively. It looks into the fetched Devfile for any default (or single non-default) run command; and, if it is an exec command, tries to find the referenced container component to overwrite its endpoints.

More context in #6925

Which issue(s) this PR fixes:
Fixes #6925

PR acceptance criteria:

How to test changes / Special notes to the reviewer:

  • No error if the Devfile does not have a run command;
$ odo init --name udi --devfile udi --run-port 8080 --run-port 9090
  __
 /  \__     Initializing a new component
 \__/  \    
 /  \__/    odo version: v3.12.0
 \__/

 ✓  Downloading devfile "udi" [16ms]

Your new component 'udi' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

$ yq '.components[] | select(has("container")) | del(.container.env) | del(.container.volumeMounts) | split_doc' devfile.yaml
container:
  cpuLimit: 4000m
  cpuRequest: 1000m
  image: quay.io/devfile/universal-developer-image:ubi8-latest
  memoryLimit: 6G
  memoryRequest: 512Mi
  mountSources: true
name: tools
  • It should overwrite the container endpoints with the ones coming from --run-port
$ odo init --name my-nodejs --devfile nodejs --run-port 18080 --run-port 28080 --run-port 38080
  __
 /  \__     Initializing a new component
 \__/  \    
 /  \__/    odo version: v3.12.0
 \__/

 ✓  Downloading devfile "nodejs" [18ms]

Your new component 'my-nodejs' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

$ yq '.components[] | select(has("container")) | del(.container.env) | del(.container.volumeMounts) | split_doc' devfile.yaml
container:
  args:
    - tail
    - -f
    - /dev/null
  endpoints:
    - name: port-18080-tcp
      protocol: tcp
      targetPort: 18080
    - name: port-28080-tcp
      protocol: tcp
      targetPort: 28080
    - name: port-38080-tcp
      protocol: tcp
      targetPort: 38080
  image: registry.access.redhat.com/ubi8/nodejs-16:latest
  memoryLimit: 1024Mi
  mountSources: true
name: runtime
  • It should overwrite the container endpoints with the ones coming from --run-port, even if the Devfile stack in the registry has many container components; example with java-wildfly:
$ odo init --name my-java-wildfly --devfile java-wildfly --run-port 1234 --run-port 5678 --run-port 9012
  __
 /  \__     Initializing a new component
 \__/  \    
 /  \__/    odo version: v3.12.0
 \__/

 ✓  Downloading devfile "java-wildfly" [44ms]

Your new component 'my-java-wildfly' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

$ yq '.components[] | select(has("container")) | del(.container.env) | del(.container.volumeMounts) | split_doc' devfile.yaml
container:
  endpoints:
    - name: port-1234-tcp
      protocol: tcp
      targetPort: 1234
    - name: port-5678-tcp
      protocol: tcp
      targetPort: 5678
    - name: port-9012-tcp
      protocol: tcp
      targetPort: 9012
  image: quay.io/wildfly/wildfly-centos7:26.1
  memoryLimit: 1512Mi
  mountSources: true
name: wildfly
---
container:
  endpoints:
    - name: tracing-ui-wild
      targetPort: 16686
  image: quay.io/jaegertracing/all-in-one:1.27
  memoryLimit: 128Mi
name: jaeger

rm3l added 4 commits July 6, 2023 09:33
As depicted in [1], this leverages the default (or single non-default) run command to find the linked container component.
As such, it assumes that the command found is an exec command,
and that the linked component is a container component.

[1] redhat-developer#6925
@openshift-ci openshift-ci bot added kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation area/init Issues or PRs related to `odo init` labels Jul 6, 2023
@rm3l rm3l temporarily deployed to internal July 6, 2023 07:57 — with GitHub Actions Inactive
@netlify
Copy link

netlify bot commented Jul 6, 2023

🔨 Deploy Preview deleted from internal cluster!

Name Link
🔨 Latest commit 76f96e2
😎 Deploy Preview https://odo-dev-pr-6953.odo-test-kubernete-449701-49529fc6e6a4a9fe7ebba9a3db5b55c4-0000.eu-de.containers.appdomain.cloud/

@openshift-ci openshift-ci bot requested review from feloy and kadel July 6, 2023 07:58
@odo-robot
Copy link

odo-robot bot commented Jul 6, 2023

Windows Tests (OCP) on commit 996ab8e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Jul 6, 2023

OpenShift Unauthenticated Tests on commit 996ab8e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Jul 6, 2023

NoCluster Tests on commit 996ab8e finished successfully.
View logs: TXT HTML

This ensures the output and sample in the doc are kept in sync with the code base.
@odo-robot
Copy link

odo-robot bot commented Jul 6, 2023

Unit Tests on commit 996ab8e finished successfully.
View logs: TXT HTML

@rm3l rm3l force-pushed the 6925-odo-init-add-new-run-port-flag-to-set-ports-into-initial-devfile branch from 7e0f5b1 to 76f96e2 Compare July 6, 2023 08:07
@rm3l rm3l temporarily deployed to internal July 6, 2023 08:07 — with GitHub Actions Inactive
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@odo-robot
Copy link

odo-robot bot commented Jul 6, 2023

Validate Tests on commit 996ab8e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Jul 6, 2023

Kubernetes Tests on commit 996ab8e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Jul 6, 2023

OpenShift Tests on commit 996ab8e finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Jul 6, 2023

Kubernetes Docs Tests on commit 5911930 finished successfully.
View logs: TXT HTML

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 6, 2023
@openshift-merge-robot openshift-merge-robot merged commit c4b103d into redhat-developer:main Jul 6, 2023
@openshift-merge-robot openshift-merge-robot temporarily deployed to internal July 6, 2023 14:35 — with GitHub Actions Inactive
@rm3l rm3l deleted the 6925-odo-init-add-new-run-port-flag-to-set-ports-into-initial-devfile branch July 6, 2023 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/init Issues or PRs related to `odo init` kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

odo init: Add new --run-port flag to set ports into initial Devfile
3 participants