Bug 1154167

Summary: Document port-forwarding to other gears (as part of your scaled application).
Product: OpenShift Online Reporter: Eric Rich <erich>
Component: DocumentationAssignee: Timothy <tpoitras>
Status: CLOSED NOTABUG QA Contact: Bilhar <baulakh>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 2.xCC: erich, jokerman, mmccomas
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Build Name: 22503, User Guide-null-1.0 Build Date: 29-09-2014 11:16:34 Topic ID: 26309-621713 [Latest]
Last Closed: 2014-11-07 00:36:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Eric Rich 2014-10-17 17:46:49 UTC
Title: Application Port Forwarding

Describe the issue:

If you want to enable port-forwarding to a gear, the default examples shown in the current documentation only show you how to get forwarded to the Head gear, and any attached Databased. 

However if you run:

   # rhc port-forward eap -g 54401bb67f116a704e000169

You can get forwarded to any gear in your environment. 


Suggestions for improvement:

Explain / update the documentation to explain this -g option. 

Additional information:

Currently Portforarding for a gear does the following: 

# Collect locally bound ports
declare -A $(/usr/sbin/lsof -iTCP -sTCP:LISTEN -P 2> /dev/null | /bin/awk '/LISTEN/{ print "local_bindings["$9"]="$1 }')

# Extract database ports out of the environment
declare -A remote_bindings

for host_var in $(env | grep _DB_HOST | awk -F '=' '{print $1}'); do
    db_name=$(echo $host_var |sed -e 's/.*OPENSHIFT_\(.*\)_DB_HOST/\1/' |tr '[A-Z]' '[a-z]')
    port_var=$(echo $host_var |sed 's/_DB_HOST/_DB_PORT/')
    port_val=$(echo ${!port_var})
    host_val=$(echo ${!host_var})
    db_binding="${host_val}:${port_val}"
    remote_bindings[$db_binding]=${db_name}
done
    
# Merge the database ports into the local binding list; if the databases are
# local, the keys will simply be overwritten in the array
if ! $exclude_remote ; then
  for remote_binding in "${!remote_bindings[@]}"; do
    local_bindings[$remote_binding]="${remote_bindings[$remote_binding]}"
  done
fi

In short:

- you get a listing of ports seen by the gear
- Find out if you have a database mapping
  - Determine if its scaled
- Merge duplicates
- Report on the ports for rhc to setup mappings.

Comment 1 Eric Rich 2014-10-17 17:47:24 UTC
https://blog.openshift.com/getting-started-with-port-forwarding-on-openshift/ should also be updated as it coves the same content.

Comment 5 Timothy 2014-11-07 00:36:05 UTC
Already documented.

Closing.