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

connect: enable configuring sidecar_task.name #7684

Merged
merged 2 commits into from Apr 10, 2020
Merged

Conversation

shoenig
Copy link
Member

@shoenig shoenig commented Apr 10, 2020

Before, the submitted jobspec for sidecar_task would pass
through 2 HCL key validation steps - once for the subset specific
to connect sidecar task definitions, and once again for the set
of normal task definition.

The valid keys for the normal task definition did not include
name, which is supposed to be configurable for the sidecar
task. To fix this, just eliminate the double validation for sidecars,
and instead pass in the correct set of keys to validate against
to the one generic task parser.

Fixes #7680

Example)

$ cat example.nomad 
job "countdash" {
  datacenters = ["dc1"]

  group "api" {
    network {
      mode = "bridge"
    }

    service {
      name = "count-api"
      port = "9001"

      connect {
	sidecar_service {}
	sidecar_task {
	  name = "sidecar-for-api"
	}
      }
    }

    task "web" {
      driver = "docker"

      config {
        image = "hashicorpnomad/counter-api:v1"
      }
    }
  }

  group "dashboard" {
    network {
      mode = "bridge"

      port "http" {
        static = 9002
        to     = 9002
      }
    }

    service {
      name = "count-dashboard"
      port = "9002"

      connect {
        sidecar_service {
          proxy {
            upstreams {
              destination_name = "count-api"
              local_bind_port  = 8080
            }
          }
	}
	sidecar_task {
	  name = "sidecar-for-dashboard"
	}
      }
    }

    task "dashboard" {
      driver = "docker"

      env {
        COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}"
      }

      config {
        image = "hashicorpnomad/counter-dashboard:v1"
      }
    }
  }
}
$ nomad job run example.nomad
==> Monitoring evaluation "bba4c500"
    Evaluation triggered by job "countdash"
    Allocation "c146aa5b" created: node "452bfc95", group "dashboard"
    Allocation "d08ba27e" created: node "452bfc95", group "api"
    Evaluation within deployment: "5ac8764c"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "bba4c500" finished with status "complete"
$ nomad alloc status c1
ID                  = c146aa5b-3430-935d-1045-458415e51b5a
Eval ID             = bba4c500
Name                = countdash.dashboard[0]
Node ID             = 452bfc95
Node Name           = NUC10
Job ID              = countdash
Job Version         = 0
Client Status       = running
Client Description  = Tasks are running
Desired Status      = run
Desired Description = <none>
Created             = 19s ago
Modified            = 7s ago
Deployment ID       = 5ac8764c
Deployment Health   = healthy

Allocation Addresses (mode = "bridge")
Label                          Dynamic  Address
connect-proxy-count-dashboard  yes      192.168.1.53:30194 -> 30194
http                           yes      192.168.1.53:9002 -> 9002

Task "sidecar-for-dashboard" (prestart sidecar) is "running"
Task Resources
CPU        Memory          Disk     Addresses
7/250 MHz  11 MiB/128 MiB  300 MiB  

Task Events:
Started At     = 2020-04-10T03:06:49Z
Finished At    = N/A
Total Restarts = 0
Last Restart   = N/A

Recent Events:
Time                       Type        Description
2020-04-09T21:06:49-06:00  Started     Task started by client
2020-04-09T21:06:48-06:00  Task Setup  Building Task Directory
2020-04-09T21:06:47-06:00  Received    Task received by client

Task "dashboard" is "running"
Task Resources
CPU        Memory           Disk     Addresses
0/100 MHz  1.4 MiB/300 MiB  300 MiB  

Task Events:
Started At     = 2020-04-10T03:06:49Z
Finished At    = N/A
Total Restarts = 0
Last Restart   = N/A

Recent Events:
Time                       Type        Description
2020-04-09T21:06:49-06:00  Started     Task started by client
2020-04-09T21:06:49-06:00  Task Setup  Building Task Directory
2020-04-09T21:06:47-06:00  Received    Task received by client
$ nomad alloc status d0
ID                  = d08ba27e-06d0-b397-2a62-42b39ea684fb
Eval ID             = bba4c500
Name                = countdash.api[0]
Node ID             = 452bfc95
Node Name           = NUC10
Job ID              = countdash
Job Version         = 0
Client Status       = running
Client Description  = Tasks are running
Desired Status      = run
Desired Description = <none>
Created             = 27s ago
Modified            = 15s ago
Deployment ID       = 5ac8764c
Deployment Health   = healthy

Allocation Addresses (mode = "bridge")
Label                    Dynamic  Address
connect-proxy-count-api  yes      192.168.1.53:21489 -> 21489
Task "sidecar-for-api" (prestart sidecar) is "running"
Task Resources
CPU        Memory          Disk     Addresses
8/250 MHz  10 MiB/128 MiB  300 MiB  

Task Events:
Started At     = 2020-04-10T03:06:49Z
Finished At    = N/A
Total Restarts = 0
Last Restart   = N/A

Recent Events:
Time                       Type        Description
2020-04-09T21:06:49-06:00  Started     Task started by client
2020-04-09T21:06:48-06:00  Task Setup  Building Task Directory
2020-04-09T21:06:47-06:00  Received    Task received by client

Task "web" is "running"
Task Resources
CPU        Memory           Disk     Addresses
0/100 MHz  536 KiB/300 MiB  300 MiB  

Task Events:
Started At     = 2020-04-10T03:06:49Z
Finished At    = N/A
Total Restarts = 0
Last Restart   = N/A

Recent Events:
Time                       Type        Description
2020-04-09T21:06:49-06:00  Started     Task started by client
2020-04-09T21:06:49-06:00  Task Setup  Building Task Directory
2020-04-09T21:06:47-06:00  Received    Task received by client

Before, the submitted jobspec for sidecar_task would pass
through 2 key validation steps - once for the subset specific
to connect sidecar task definitions, and once again for the set
of normal task definition where the task would actually get
unmarshalled.

The valid keys for the normal task definition did not include
"name", which is supposed to be configurable for the sidecar
task. To fix this, just eliminate the double validation step,
and instead pass-in the correct set of keys to validate against
to the one generic task parser.

Fixes #7680
@@ -12,6 +12,48 @@ import (
"github.com/mitchellh/mapstructure"
)

var (
normalTaskKeys = []string{
Copy link
Member

Choose a reason for hiding this comment

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

So that the shared keys don’t fall out of sync maybe we should have a coreTaskKeys and have these two something like
normalTaskKeys = append(coreTaskKeys, ...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea; done!

@shoenig shoenig merged commit 47dfa76 into master Apr 10, 2020
@shoenig shoenig deleted the b-connect-sidecar-name branch April 10, 2020 16:04
shoenig added a commit that referenced this pull request Apr 20, 2020
@github-actions
Copy link

github-actions bot commented Jan 9, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

connect sidecar_task name is not configurable
2 participants