Skip to content

Commit

Permalink
Move commands closer to their configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
t-eckert committed Jan 16, 2024
1 parent 4f5c47e commit eb0e6bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 10 additions & 0 deletions control-plane/gateways/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package gateways

const (
envPodName = "POD_NAME"
envPodNamespace = "POD_NAMESPACE"
envNodeName = "NODE_NAME"
)
2 changes: 2 additions & 0 deletions control-plane/gateways/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
const (
globalDefaultInstances int32 = 1
meshGatewayAnnotationKind = "mesh-gateway"
// defaultBearerTokenFile is the default location where the init container will store the bearer token for the dataplane container to read
defaultBearerTokenFile = "/var/run/secrets/kubernetes.io/serviceaccount/token"
)

func (b *meshGatewayBuilder) Deployment() (*appsv1.Deployment, error) {
Expand Down
18 changes: 9 additions & 9 deletions control-plane/gateways/deployment_init_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import (
const (
injectInitContainerName = "consul-mesh-init"
initContainersUserAndGroupID = 5996
defaultBearerTokenFile = "/var/run/secrets/kubernetes.io/serviceaccount/token"
)

var (
tpl = template.Must(template.New("root").Parse(strings.TrimSpace(initContainerCommandTpl)))
)

type initContainerCommandData struct {
Expand All @@ -42,6 +45,11 @@ func (b *meshGatewayBuilder) initContainer() (corev1.Container, error) {
ServiceName: b.gateway.Name,
ServiceAccountName: b.serviceAccountName(),
}
// Render the command
var buf bytes.Buffer
if err := tpl.Execute(&buf, &data); err != nil {
return corev1.Container{}, err
}

// Create expected volume mounts
volMounts := []corev1.VolumeMount{
Expand All @@ -56,14 +64,6 @@ func (b *meshGatewayBuilder) initContainer() (corev1.Container, error) {
bearerTokenFile = defaultBearerTokenFile
}

// Render the command
var buf bytes.Buffer
tpl := template.Must(template.New("root").Parse(strings.TrimSpace(initContainerCommandTpl)))

if err := tpl.Execute(&buf, &data); err != nil {
return corev1.Container{}, err
}

consulNamespace := namespaces.ConsulNamespace(b.gateway.Namespace, b.config.ConsulTenancyConfig.EnableConsulNamespaces, b.config.ConsulTenancyConfig.ConsulDestinationNamespace, b.config.ConsulTenancyConfig.EnableConsulNamespaces, b.config.ConsulTenancyConfig.NSMirroringPrefix)

initContainerName := injectInitContainerName
Expand Down

0 comments on commit eb0e6bd

Please sign in to comment.