// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

syntax = "proto3";

package hashicorp.consul.catalog.v1alpha1;

import "pbcatalog/v1alpha1/protocol.proto";

// Workload is the representation of a unit of addressable work. This could
// represent a process on a VM, a Kubernetes pod or something else entirely.
message Workload {
  // addresses has a list of all workload addresses. This should include
  // LAN and WAN addresses as well as any addresses a proxy would need
  // to bind to (if different from the default address).
  repeated WorkloadAddress addresses = 1;

  // ports is a map from port name to workload port’s number and protocol.
  map<string, WorkloadPort> ports = 2;

  // node_name is the name of the node this workload belongs to.
  string node_name = 3;

  // identity is the name of the workload identity this workload is associated with.
  string identity = 4;

  // Locality specifies workload locality.
  Locality locality = 5;

  // Below fields are deprecated but kept here for backward compatibility reasons.

  // deprecated: tags correspond to service tags that you can add to a service for DNS resolution.
  repeated string tags = 6 [deprecated = true];
  // deprecated: enable_tag_override indicates whether agents should be overriding tags during anti-entropy syncs.
  bool enable_tag_override = 7 [deprecated = true];
  // deprecated: connect_native indicates whether this workload is connect native which will allow it to be
  // part of MeshEndpoints without having the corresponding Proxy resource.
  bool connect_native = 8 [deprecated = true];
}

message WorkloadAddress {
  // host can be an IP, DNS name or a unix socket.
  // If it's a unix socket, only one port can be provided.
  string host = 1;

  // ports is a list of names of ports that this host binds to.
  // If no ports are provided, we will assume all ports from the ports map.
  repeated string ports = 2;

  // external indicates whether this address should be used for external communication
  // (aka a WAN address).
  bool external = 3;
}

message WorkloadPort {
  uint32 port = 1;
  Protocol protocol = 2;
}

message Locality {
  // Region is region the zone belongs to.
  string region = 1;

  // Zone is the zone the entity is running in.
  string zone = 2;
}
