Skip to content

Commit

Permalink
Merge pull request #307 from authzed/podname-volume
Browse files Browse the repository at this point in the history
Inject pod name into volume
  • Loading branch information
ecordell authored Apr 26, 2024
2 parents af93237 + 65a418b commit 721a3a3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
10 changes: 10 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
telemetryTLSVolume = "telemetry-tls"
labelsVolume = "podlabels"
annotationsVolume = "podannotations"
podNameVolume = "podname"

DefaultTLSKeyFile = "/tls/tls.key"
DefaultTLSCrtFile = "/tls/tls.crt"
Expand Down Expand Up @@ -576,6 +577,15 @@ func (c *Config) servicePorts() []*applycorev1.ServicePortApplyConfiguration {

func (c *Config) jobVolumes() []*applycorev1.VolumeApplyConfiguration {
volumes := make([]*applycorev1.VolumeApplyConfiguration, 0)
volumes = append(volumes, applycorev1.Volume().WithName(podNameVolume).
WithDownwardAPI(applycorev1.DownwardAPIVolumeSource().WithItems(
applycorev1.DownwardAPIVolumeFile().
WithPath("name").
WithFieldRef(applycorev1.ObjectFieldSelector().
WithFieldPath("metadata.name"),
),
)))

if len(c.DatastoreTLSSecretName) > 0 {
volumes = append(volumes, applycorev1.Volume().WithName(dbTLSVolume).WithSecret(applycorev1.SecretVolumeSource().WithDefaultMode(420).WithSecretName(c.DatastoreTLSSecretName)))
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,14 @@ spec:
).
WithTerminationMessagePolicy(corev1.TerminationMessageFallbackToLogsOnError),
).WithVolumes(
applycorev1.Volume().WithName(podNameVolume).
WithDownwardAPI(applycorev1.DownwardAPIVolumeSource().WithItems(
applycorev1.DownwardAPIVolumeFile().
WithPath("name").
WithFieldRef(applycorev1.ObjectFieldSelector().
WithFieldPath("metadata.name"),
),
)),
applycorev1.Volume().WithName(labelsVolume).
WithDownwardAPI(applycorev1.DownwardAPIVolumeSource().WithItems(
applycorev1.DownwardAPIVolumeFile().
Expand Down Expand Up @@ -2215,6 +2223,14 @@ spec:
).
WithTerminationMessagePolicy(corev1.TerminationMessageFallbackToLogsOnError),
).WithVolumes(
applycorev1.Volume().WithName(podNameVolume).
WithDownwardAPI(applycorev1.DownwardAPIVolumeSource().WithItems(
applycorev1.DownwardAPIVolumeFile().
WithPath("name").
WithFieldRef(applycorev1.ObjectFieldSelector().
WithFieldPath("metadata.name"),
),
)),
applycorev1.Volume().WithName(labelsVolume).
WithDownwardAPI(applycorev1.DownwardAPIVolumeSource().WithItems(
applycorev1.DownwardAPIVolumeFile().
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/ensure_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
migrationHash: "testtesttesttest",
secretHash: "secret",
existingDeployments: []*appsv1.Deployment{{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n59hb4h5f7h5b7h5dchddh79h67dq",
metadata.SpiceDBConfigKey: "nbh55ch546h5d8h57fhc9h557h684q",
}}}},
expectNext: nextKey,
},
Expand All @@ -71,7 +71,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
migrationHash: "testtesttesttest",
secretHash: "secret",
existingDeployments: []*appsv1.Deployment{{}, {ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n59hb4h5f7h5b7h5dchddh79h67dq",
metadata.SpiceDBConfigKey: "nbh55ch546h5d8h57fhc9h557h684q",
}}}},
expectDelete: true,
expectNext: nextKey,
Expand All @@ -81,7 +81,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
migrationHash: "testtesttesttest",
secretHash: "secret1",
existingDeployments: []*appsv1.Deployment{{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n59hb4h5f7h5b7h5dchddh79h67dq",
metadata.SpiceDBConfigKey: "nbh55ch546h5d8h57fhc9h557h684q",
}}}},
expectApply: true,
expectRequeueAfter: true,
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
}}}},
existingDeployments: []*appsv1.Deployment{{
ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n66bhc9h5c9h6fh8ch559h58bhb4q",
metadata.SpiceDBConfigKey: "n598h54fh54fh65dh579h5b8h68ch5ccq",
}},
Status: appsv1.DeploymentStatus{
Replicas: 2,
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
}}}},
existingDeployments: []*appsv1.Deployment{{
ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n66bhc9h5c9h6fh8ch559h58bhb4q",
metadata.SpiceDBConfigKey: "n598h54fh54fh65dh579h5b8h68ch5ccq",
}},
Status: appsv1.DeploymentStatus{
Replicas: 2,
Expand All @@ -176,7 +176,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
}}}},
existingDeployments: []*appsv1.Deployment{{
ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n66bhc9h5c9h6fh8ch559h58bhb4q",
metadata.SpiceDBConfigKey: "n598h54fh54fh65dh579h5b8h68ch5ccq",
}},
Status: appsv1.DeploymentStatus{
Replicas: 2,
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
}}}},
existingDeployments: []*appsv1.Deployment{{
ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n66bhc9h5c9h6fh8ch559h58bhb4q",
metadata.SpiceDBConfigKey: "n598h54fh54fh65dh579h5b8h68ch5ccq",
}},
Status: appsv1.DeploymentStatus{
Replicas: 2,
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
}}}},
existingDeployments: []*appsv1.Deployment{{
ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n66bhc9h5c9h6fh8ch559h58bhb4q",
metadata.SpiceDBConfigKey: "n598h54fh54fh65dh579h5b8h68ch5ccq",
}},
Status: appsv1.DeploymentStatus{
Replicas: 2,
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestEnsureDeploymentHandler(t *testing.T) {
}}},
existingDeployments: []*appsv1.Deployment{{
ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
metadata.SpiceDBConfigKey: "n66bhc9h5c9h6fh8ch559h58bhb4q",
metadata.SpiceDBConfigKey: "n598h54fh54fh65dh579h5b8h68ch5ccq",
}},
Status: appsv1.DeploymentStatus{
Replicas: 2,
Expand Down

0 comments on commit 721a3a3

Please sign in to comment.