Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom names for generated k8s resources #3537

Merged
merged 7 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/gatewayapi/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@
return map[string]string{OwningGatewayClassLabel: name}
}

// OwnerLabels returns the owner labels based on the mergeGateways setting
func OwnerLabels(gateway *gwapiv1.Gateway, mergeGateways bool) map[string]string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

if mergeGateways {
return GatewayClassOwnerLabel(string(gateway.Spec.GatewayClassName))

Check warning on line 234 in internal/gatewayapi/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/helpers.go#L232-L234

Added lines #L232 - L234 were not covered by tests
}

return GatewayOwnerLabels(gateway.Namespace, gateway.Name)

Check warning on line 237 in internal/gatewayapi/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/helpers.go#L237

Added line #L237 was not covered by tests
}

// servicePortToContainerPort translates a service port into an ephemeral
// container port.
func servicePortToContainerPort(servicePort int32, envoyProxy *egv1a1.EnvoyProxy) int32 {
Expand Down
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
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