Skip to content

Commit

Permalink
Set gateway-kind in Workload metadata when it represents a xGateway Pod
Browse files Browse the repository at this point in the history
By setting the gateway-kind annotation on the Pods for a MeshGateway, we indicate to the Pod controller in consul-k8s that the Pod represents a mesh gateway (or api/terminating in the future). The Pod controller then passes this along as metadata on the Workload that it creates in Consul.

The end result is that the sidecar and gateway proxy controllers can determine which Workloads they should generate ProxyStateTemplates for.
  • Loading branch information
nathancoleman committed Dec 12, 2023
1 parent 9b516ec commit 5d6854f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions control-plane/connect-inject/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const (
// ProxyDefaultHealthPort is the default HTTP health check port for the proxy.
ProxyDefaultHealthPort = 21000

// MetaGatewayKind is the meta key name for indicating which kind of gateway a Pod is for, if any.
// The value should be one of "mesh", "api", or "terminating".
MetaGatewayKind = "gateway-kind"

// MetaKeyManagedBy is the meta key name for indicating which Kubernetes controller manages a Consul resource.
MetaKeyManagedBy = "managed-by"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,16 @@ func parseLocality(node corev1.Node) *pbcatalog.Locality {

func metaFromPod(pod corev1.Pod) map[string]string {
// TODO: allow custom workload metadata
return map[string]string{
meta := map[string]string{
constants.MetaKeyKubeNS: pod.GetNamespace(),
constants.MetaKeyManagedBy: constants.ManagedByPodValue,
}

if gatewayKind := pod.Annotations[constants.AnnotationGatewayKind]; gatewayKind != "" {
meta[constants.MetaGatewayKind] = gatewayKind
}

return meta
}

// getHealthStatusFromPod checks the Pod for a "Ready" condition that is true.
Expand Down
2 changes: 2 additions & 0 deletions control-plane/gateways/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1"

meshv2beta1 "github.com/hashicorp/consul-k8s/control-plane/api/mesh/v2beta1"
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/constants"
)

const (
Expand Down Expand Up @@ -63,6 +64,7 @@ func (b *meshGatewayBuilder) deploymentSpec() (*appsv1.DeploymentSpec, error) {
Labels: b.Labels(),
Annotations: map[string]string{
"consul.hashicorp.com/mesh-inject": "false",
constants.AnnotationGatewayKind: "mesh",
},
},
Spec: corev1.PodSpec{
Expand Down

0 comments on commit 5d6854f

Please sign in to comment.