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

validate connect block allowed only within group.service (fixes #9450) #9817

Merged
merged 3 commits into from
Jan 20, 2021
Merged

validate connect block allowed only within group.service (fixes #9450) #9817

merged 3 commits into from
Jan 20, 2021

Conversation

roccoblues
Copy link
Contributor

This adds the missing validation mentioned in #9450 for a connect block to be allowed only in a group service.

@vercel vercel bot temporarily deployed to Preview – nomad-storybook-and-ui January 14, 2021 16:30 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad January 14, 2021 16:30 Inactive
@tgross tgross self-requested a review January 20, 2021 13:14
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

Hi @roccoblues! Thanks for contributing this PR!

Unfortunately it doesn't look like this fixes the bug... I pulled this PR down locally and used the jobspec @shoenig provided in #9405

jobspec
job "countdash" {
  datacenters = ["dc1"]

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



    task "web" {
      driver = "docker"

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

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

        # should only be valid in group level
        connect {
          sidecar_service {}
        }
      }
    }
  }
}

If I run that job, it passes validation and runs:

$ nomad version
Nomad v1.0.2-dev (2bccb85d38164cfee4bede21fa3d2b10d75a1985)

$ nomad job run ./example.nomad
==> Monitoring evaluation "205d603a"
    Evaluation triggered by job "countdash"
    Evaluation within deployment: "48b3bd4b"
    Allocation "588298bf" created: node "ebf7bb9b", group "api"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "205d603a" finished with status "complete"

$ nomad alloc status 588
...

Recent Events:
Time                       Type        Description
2021-01-20T08:13:57-05:00  Started     Task started by client
2021-01-20T08:13:56-05:00  Task Setup  Building Task Directory
2021-01-20T08:13:55-05:00  Received    Task received by client

nomad/structs/structs.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – nomad January 20, 2021 13:27 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad-storybook-and-ui January 20, 2021 13:27 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad January 20, 2021 16:31 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad-storybook-and-ui January 20, 2021 16:31 Inactive
@roccoblues
Copy link
Contributor Author

Hi @tgross,

yes you're right. The connect block was silently thrown away. Took me a while to step through the code and find the right place. I've fixed it now.

~/p/r/nomad (connect-block↑1|…) $ ./bin/nomad job run /tmp/example.job
Error submitting job: Unexpected response code: 500 (1 error occurred:
	* Task group api validation failed: 1 error occurred:
	* Task web validation failed: 1 error occurred:
	* 1 error occurred:
	* service "count-api" cannot have "connect" block, only services defined in a "group" block can
)

~/p/r/nomad (connect-block↑1|…) $ ./bin/nomad job validate /tmp/example.job
Job validation errors:
1 error occurred:
	* Task group api validation failed: 1 error occurred:
	* Task web validation failed: 1 error occurred:
	* 1 error occurred:
	* service "count-api" cannot have "connect" block, only services defined in a "group" block can

@roccoblues roccoblues requested a review from tgross January 20, 2021 17:40
@tgross
Copy link
Member

tgross commented Jan 20, 2021

LGTM! Thanks @roccoblues!

@tgross tgross merged commit bbebfeb into hashicorp:master Jan 20, 2021
@tgross tgross added this to the 1.0.3 milestone Jan 20, 2021
@github-actions
Copy link

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 Nov 30, 2022
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.

2 participants