nomad icon indicating copy to clipboard operation
nomad copied to clipboard

Add Meta on ConsulTerminatingConfigEntry

Open Sol-Stiep opened this issue 2 years ago • 0 comments

Description

Changes

  • Added support for ConsulTerminatingConfigEntry meta configuration:
    • Added Meta field to ConsulTerminatingConfigEntry struct and updated its receiver functions.
  • Updated jobspec/parse_service.go
  • Update related tests
  • Update Nomad Documentation for ConsulTerminatingConfigEntry struct.

Testing Changes

To test these changes you need to build a Nomad binary and deploy a cluster with both Nomad and Consul agents and clients.
When you have your cluster running you can run the following job-spec:

job "countdash-terminating" {

  datacenters = ["dc1"]

  group "api" {
    network {
      mode = "host"
      port "port" {
        static = "9001"
      }
    }
    
    service {
      name = "count-api"
      port = "port"
    }

    task "api" {
      driver = "docker"

      config {
        image        = "hashicorpdev/counter-api:v3"
        network_mode = "host"
      }
    }
  }

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

    service {
      name = "api-gateway"

      connect {
        gateway {          
          proxy {}     
         
          terminating {          
            service {
              name = "count-api"
            }
            
            # New Fields:
            meta {
              test-key = "test-value"
              test-key1 = "test-value1"
              test-key2 = "test-value2"
            }
          }
        }
      }
    }
  }
  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
            }
          }
        }
      }
    }

    task "dashboard" {
      driver = "docker"

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

      config {
        image = "hashicorpdev/counter-dashboard:v3"
      }
    }
  }
}

Once the job is running and healthy, use Consul's API to get the terminating gateway's configuration:

curl --request GET http://127.0.0.1:8500/v1/config/terminating-gateway | json_pp

You will get the following JSON output:

[
   {
      "Meta" : {
         "test-key" : "test-value",
         "test-key1" : "test-value1",
         "test-key2" : "test-value2"
      },
      "Name" : "api-gateway",
      "Services" : [
         {
            "Name" : "count-api"
         }
      ],
      "CreateIndex" : 155,
      "Kind" : "terminating-gateway",
      "ModifyIndex" : 155
   }
]

Demo Video

https://user-images.githubusercontent.com/74208929/226930924-81d538e7-ca1c-4d4a-b874-83c33f008b3c.mp4

Sol-Stiep avatar Mar 31 '23 20:03 Sol-Stiep