Skip to content
This repository was archived by the owner on Aug 29, 2018. It is now read-only.

Commit b31df16

Browse files
Merge pull request #42 from smarterclayton/port_mappings_lost_locally
Port mappings lost on local gear deploy
2 parents 3d25ad8 + ecd9171 commit b31df16

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

cmd/gear/commands.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,9 @@ func deployContainers(cmd *cobra.Command, args []string) {
334334
}
335335
},
336336
OnSuccess: func(r *CliJobResponse, w io.Writer, job interface{}) {
337-
instance, _ := changes.Instances.Find(job.(*http.HttpInstallContainerRequest).InstallContainerRequest.Id)
338-
if pairs, ok := r.Pending["Ports"].(port.PortPairs); ok {
337+
installJob := job.(*http.HttpInstallContainerRequest)
338+
instance, _ := changes.Instances.Find(installJob.Id)
339+
if pairs, ok := installJob.PortMappingsFrom(r.Pending); ok {
339340
if !instance.Ports.Update(pairs) {
340341
fmt.Fprintf(os.Stderr, "Not all ports listed %+v were returned by the server %+v", instance.Ports, pairs)
341342
}

contrib/build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ else
6161
go install -tags "$tags" github.com/openshift/geard/cmd/gear
6262
go install -tags "$tags" github.com/openshift/geard/cmd/switchns
6363
go install -tags "$tags" github.com/openshift/geard/ssh/cmd/gear-auth-keys-command
64+
echo "..done"
6465

6566
if $copy_binaries; then
67+
echo "Copying binaries.."
6668
sudo /usr/bin/cp -f $ORIG_GOPATH/bin/gear-auth-keys-command /usr/sbin/
6769
sudo /usr/bin/cp -f $ORIG_GOPATH/bin/switchns /usr/bin
6870
sudo /usr/bin/cp -f $ORIG_GOPATH/bin/gear /usr/bin
6971
sudo chmod +s /usr/bin/switchns
7072
sudo restorecon -v /usr/sbin/gear-auth-keys-command /usr/bin/gear /usr/bin/switchns
73+
echo "..done"
7174
fi
72-
echo "..done"
7375
fi

deployment/links.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func (link containerLink) appendLinks() error {
189189
if !found {
190190
return errors.New(fmt.Sprintf("deployment: instance does not expose %d for link %s", port, link.String()))
191191
}
192+
log.Printf("appending %d on %s: %+v %+v", port, instance.Id, mapping, instance)
192193

193194
instance.links = append(instance.links, InstanceLink{
194195
NetworkLink: containers.NetworkLink{

git/permission.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/openshift/geard/containers"
66
"github.com/openshift/geard/ssh"
77
"github.com/openshift/geard/utils"
8-
"log"
98
"os"
109
)
1110

@@ -30,7 +29,6 @@ func (r repositoryPermission) CreatePermission(locator ssh.KeyLocator, value *ut
3029
}
3130
}
3231

33-
log.Printf("debug: Id %s", p.Id)
3432
id, err := containers.NewIdentifier(p.Id)
3533
if err != nil {
3634
return err

http/marshal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func (h *HttpInstallContainerRequest) MarshalHttpRequestBody(w io.Writer) error
3939
func (h *HttpInstallContainerRequest) UnmarshalHttpResponse(headers http.Header, r io.Reader, mode ResponseContentMode) (interface{}, error) {
4040
if r == nil {
4141
pending := make(map[string]interface{})
42-
if s := headers.Get("X-PortMapping"); s != "" {
42+
if s := headers.Get("X-" + jobs.PendingPortMappingName); s != "" {
4343
ports, err := port.FromPortPairHeader(s)
4444
if err != nil {
4545
return nil, err
4646
}
47-
pending["Ports"] = ports
47+
pending[jobs.PendingPortMappingName] = ports
4848
}
4949
return pending, nil
5050
}

jobs/install_container.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616

1717
var ErrContainerCreateFailedPortsReserved = SimpleJobError{JobResponseError, "Unable to create container: some ports could not be reserved."}
1818

19+
const PendingPortMappingName = "PortMapping"
20+
1921
// Installing a Container
2022
//
2123
// This job will install a given container definition as a systemd service unit,
@@ -184,7 +186,7 @@ func (req *InstallContainerRequest) Execute(resp JobResponse) {
184186
return
185187
}
186188
if len(reserved) > 0 {
187-
resp.WritePendingSuccess("PortMapping", reserved)
189+
resp.WritePendingSuccess(PendingPortMappingName, reserved)
188190
}
189191

190192
var portSpec string
@@ -359,3 +361,8 @@ func (j *InstallContainerRequest) Join(job Job, complete <-chan bool) (joined bo
359361
joined = true
360362
return
361363
}
364+
365+
func (j *InstallContainerRequest) PortMappingsFrom(pending map[string]interface{}) (port.PortPairs, bool) {
366+
p, ok := pending[PendingPortMappingName].(port.PortPairs)
367+
return p, ok
368+
}

port/port.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func NewHostPort(hostport string) (HostPort, error) {
6565
}
6666

6767
func (hostport HostPort) String() string {
68-
return net.JoinHostPort(hostport.Host, string(hostport.Port))
68+
return net.JoinHostPort(hostport.Host, hostport.Port.String())
6969
}
7070

7171
func (hostport HostPort) Empty() bool {

0 commit comments

Comments
 (0)