Skip to content

Commit

Permalink
Merge pull request #62 from hashicorp/f-sync-oss
Browse files Browse the repository at this point in the history
Sync oss for 0.7.1 RC1
  • Loading branch information
dadgar authored Dec 12, 2017
2 parents 5528592 + ecb8d4e commit 6912837
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
15 changes: 3 additions & 12 deletions command/agent/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package consul

import (
"context"
"crypto/sha1"
"encoding/base32"
"fmt"
"io"
"log"
"net"
"net/url"
Expand Down Expand Up @@ -1004,17 +1001,11 @@ func (c *ServiceClient) removeTaskRegistration(allocID, taskName string) {
// Agent service IDs are of the form:
//
// {nomadServicePrefix}-{ROLE}-b32(sha1({Service.Name}-{Service.Tags...})
// Example Server ID: _nomad-server-FBBK265QN4TMT25ND4EP42TJVMYJ3HR4
// Example Client ID: _nomad-client-GGNJPGL7YN7RGMVXZILMPVRZZVRSZC7L
// Example Server ID: _nomad-server-fbbk265qn4tmt25nd4ep42tjvmyj3hr4
// Example Client ID: _nomad-client-ggnjpgl7yn7rgmvxzilmpvrzzvrszc7l
//
func makeAgentServiceID(role string, service *structs.Service) string {
h := sha1.New()
io.WriteString(h, service.Name)
for _, tag := range service.Tags {
io.WriteString(h, tag)
}
b32 := base32.StdEncoding.EncodeToString(h.Sum(nil))
return fmt.Sprintf("%s-%s-%s", nomadServicePrefix, role, b32)
return fmt.Sprintf("%s-%s-%s", nomadServicePrefix, role, service.Hash(role, ""))
}

// makeTaskServiceID creates a unique ID for identifying a task service in
Expand Down
2 changes: 1 addition & 1 deletion command/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func fmtInt(buf []byte, v uint64) int {
// is 10 months, 12 days, 3 hours and 2 seconds, the string "10mo12d" is returned. Zero values return the empty string
func prettyTimeDiff(first, second time.Time) string {
// handle zero values
if first.IsZero() {
if first.IsZero() || first.UnixNano() == 0 {
return ""
}
// round to the nearest second
Expand Down
2 changes: 2 additions & 0 deletions command/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ func TestPrettyTimeDiff(t *testing.T) {
t2 time.Time
exp string
}{
{now, time.Unix(0, 0), ""}, // This is the upgrade path case
{now, now.Add(-10 * time.Millisecond), "0s ago"},
{now, now.Add(-10 * time.Millisecond), "0s ago"},
{now, now.Add(-740 * time.Second), "12m20s ago"},
{now, now.Add(-12 * time.Minute), "12m ago"},
Expand Down
22 changes: 14 additions & 8 deletions command/job_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,9 @@ func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLen
} else {
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created|Modified"
for i, alloc := range stubs {
createTimePretty := prettyTimeDiff(time.Unix(0, alloc.CreateTime), time.Now())
modTimePretty := prettyTimeDiff(time.Unix(0, alloc.ModifyTime), time.Now())
now := time.Now()
createTimePretty := prettyTimeDiff(time.Unix(0, alloc.CreateTime), now)
modTimePretty := prettyTimeDiff(time.Unix(0, alloc.ModifyTime), now)
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.NodeID, uuidLength),
Expand All @@ -446,29 +447,34 @@ func formatAllocList(allocations []*api.Allocation, verbose bool, uuidLength int

allocs := make([]string, len(allocations)+1)
if verbose {
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created At"
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created|Modified"
for i, alloc := range allocations {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s",
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.EvalID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.TaskGroup,
getVersion(alloc.Job),
alloc.DesiredStatus,
alloc.ClientStatus,
formatUnixNanoTime(alloc.CreateTime))
formatUnixNanoTime(alloc.CreateTime),
formatUnixNanoTime(alloc.ModifyTime))
}
} else {
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created At"
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created|Modified"
for i, alloc := range allocations {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s",
now := time.Now()
createTimePretty := prettyTimeDiff(time.Unix(0, alloc.CreateTime), now)
modTimePretty := prettyTimeDiff(time.Unix(0, alloc.ModifyTime), now)
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.TaskGroup,
getVersion(alloc.Job),
alloc.DesiredStatus,
alloc.ClientStatus,
formatUnixNanoTime(alloc.CreateTime))
createTimePretty,
modTimePretty)
}
}

Expand Down
3 changes: 3 additions & 0 deletions nomad/structs/config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,8 @@ func (t *TLSConfig) Merge(b *TLSConfig) *TLSConfig {
if b.VerifyHTTPSClient {
result.VerifyHTTPSClient = true
}
if b.RPCUpgradeMode {
result.RPCUpgradeMode = true
}
return result
}
27 changes: 27 additions & 0 deletions nomad/structs/config/tls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestTLSConfig_Merge(t *testing.T) {
assert := assert.New(t)
a := &TLSConfig{
CAFile: "test-ca-file",
CertFile: "test-cert-file",
}

b := &TLSConfig{
EnableHTTP: true,
EnableRPC: true,
VerifyServerHostname: true,
CAFile: "test-ca-file-2",
CertFile: "test-cert-file-2",
RPCUpgradeMode: true,
}

new := a.Merge(b)
assert.Equal(b, new)
}

0 comments on commit 6912837

Please sign in to comment.