Skip to content

Commit

Permalink
feat: support custom names for generated k8s resources
Browse files Browse the repository at this point in the history
Relates to envoyproxy#3527

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg committed Jun 4, 2024
1 parent 607d8bc commit 8a5705a
Show file tree
Hide file tree
Showing 5 changed files with 674 additions and 3 deletions.
24 changes: 21 additions & 3 deletions internal/infrastructure/kubernetes/proxy/resource_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ func (r *ResourceRender) Service() (*corev1.Service, error) {
},
ObjectMeta: metav1.ObjectMeta{
Namespace: r.Namespace,
Name: r.Name(),
Labels: labels,
Annotations: annotations,
},
Spec: serviceSpec,
}

// set name
if envoyServiceConfig.Name != nil {
svc.ObjectMeta.Name = *envoyServiceConfig.Name
} else {
svc.ObjectMeta.Name = r.Name()
}

// apply merge patch to service
var err error
if svc, err = envoyServiceConfig.ApplyMergePatch(svc); err != nil {
Expand Down Expand Up @@ -225,7 +231,6 @@ func (r *ResourceRender) Deployment() (*appsv1.Deployment, error) {
},
ObjectMeta: metav1.ObjectMeta{
Namespace: r.Namespace,
Name: r.Name(),
Labels: dpLabels,
Annotations: dpAnnotations,
},
Expand Down Expand Up @@ -261,6 +266,13 @@ func (r *ResourceRender) Deployment() (*appsv1.Deployment, error) {
},
}

// set name
if deploymentConfig.Name != nil {
deployment.ObjectMeta.Name = *deploymentConfig.Name
} else {
deployment.ObjectMeta.Name = r.Name()
}

// omit the deployment replicas if HPA is being set
if provider.GetEnvoyProxyKubeProvider().EnvoyHpa != nil {
deployment.Spec.Replicas = nil
Expand Down Expand Up @@ -314,7 +326,6 @@ func (r *ResourceRender) DaemonSet() (*appsv1.DaemonSet, error) {
},
ObjectMeta: metav1.ObjectMeta{
Namespace: r.Namespace,
Name: r.Name(),
Labels: dsLabels,
Annotations: dsAnnotations,
},
Expand All @@ -331,6 +342,13 @@ func (r *ResourceRender) DaemonSet() (*appsv1.DaemonSet, error) {
},
}

// set name
if daemonSetConfig.Name != nil {
daemonSet.ObjectMeta.Name = *daemonSetConfig.Name
} else {
daemonSet.ObjectMeta.Name = r.Name()
}

// apply merge patch to daemonset
if daemonSet, err = daemonSetConfig.ApplyMergePatch(daemonSet); err != nil {
return nil, err
Expand Down
21 changes: 21 additions & 0 deletions internal/infrastructure/kubernetes/proxy/resource_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ func TestDeployment(t *testing.T) {
},
},
},
{
caseName: "with-name",
infra: newTestInfra(),
deploy: &egv1a1.KubernetesDeploymentSpec{
Name: ptr.To("custom-deployment-name"),
},
},
}
for _, tc := range cases {
t.Run(tc.caseName, func(t *testing.T) {
Expand Down Expand Up @@ -933,6 +940,13 @@ func TestDaemonSet(t *testing.T) {
infra: newTestInfra(),
extraArgs: []string{"--key1 val1", "--key2 val2"},
},
{
caseName: "with-name",
infra: newTestInfra(),
daemonset: &egv1a1.KubernetesDaemonSetSpec{
Name: ptr.To("custom-daemonset-name"),
},
},
}
for _, tc := range cases {
t.Run(tc.caseName, func(t *testing.T) {
Expand Down Expand Up @@ -1083,6 +1097,13 @@ func TestService(t *testing.T) {
},
},
},
{
caseName: "with-name",
infra: newTestInfra(),
service: &egv1a1.KubernetesServiceSpec{
Name: ptr.To("custom-service-name"),
},
},
}
for _, tc := range cases {
t.Run(tc.caseName, func(t *testing.T) {
Expand Down
Loading

0 comments on commit 8a5705a

Please sign in to comment.