Skip to content

Commit

Permalink
fix(MeshService): limit display name to 63 characters (#10719)
Browse files Browse the repository at this point in the history
The name was being validated to have the given length leading to errors with syncing and the `name.namespace` format on Kubernetes. We actually only need to limit the display name.

See #10474

Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont authored Jul 3, 2024
1 parent 7e57803 commit 2e266da
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Port struct {
AppProtocol core_mesh.Protocol `json:"appProtocol,omitempty"`
}

const maxNameLength = 63

// MeshService
// +kuma:policy:is_policy=false
// +kuma:policy:has_status=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package v1alpha1

import (
"github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/validators"
)

func (r *MeshServiceResource) validate() error {
var verr validators.ValidationError

verr.Add(validators.ValidateLength(validators.RootedAt("name"), 63, r.GetMeta().GetName()))
name := model.GetDisplayName(r.GetMeta())
verr.Add(validators.ValidateLength(validators.RootedAt("name"), maxNameLength, name))

return verr.OrNil()
}
42 changes: 42 additions & 0 deletions test/e2e_env/multizone/meshservice/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,30 @@ spec:
Setup(multizone.UniZone2)).To(Succeed())

err := NewClusterSetup().
Setup(multizone.KubeZone1)
Expect(err).ToNot(HaveOccurred())

veryLongNamedService := `
kind: MeshService
apiVersion: kuma.io/v1alpha1
metadata:
name: this-service-has-a-name-thats-the-exact-length-allowed-for-svcs
namespace: meshservice
labels:
kuma.io/mesh: meshservice
spec:
selector:
dataplaneTags:
kuma.io/service: some-service
ports:
- port: 80
targetPort: 80
appProtocol: http
`

err = NewClusterSetup().
Install(NamespaceWithSidecarInjection(namespace)).
Install(YamlK8s(veryLongNamedService)).
Install(democlient.Install(democlient.WithNamespace(namespace), democlient.WithMesh(meshName))).
Setup(multizone.KubeZone2)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -185,6 +208,25 @@ spec:
}, "30s", "1s").Should(Succeed())
})

It("should sync MeshServices with a long name", func() {
hashedName := hash.HashedName(meshName, "this-service-has-a-name-thats-the-exact-length-allowed-for-svcs", "kuma-2", "meshservice")
// MeshServices are synced to global zone without conflict
Eventually(func(g Gomega) {
_, _, err := msStatus(multizone.Global, hashedName)
g.Expect(err).ToNot(HaveOccurred())
}, "30s", "1s").Should(Succeed())

// MeshServices are synced to other zone without conflict
Eventually(func(g Gomega) {
_, _, err := msStatus(multizone.KubeZone1, fmt.Sprintf("%s.%s", hashedName, Config.KumaNamespace))
g.Expect(err).ToNot(HaveOccurred())
}, "30s", "1s").Should(Succeed())
Eventually(func(g Gomega) {
_, _, err := msStatus(multizone.UniZone2, hashedName)
g.Expect(err).ToNot(HaveOccurred())
}, "30s", "1s").Should(Succeed())
})

mzStatus := func(cluster Cluster, name string) (*meshmzservice_api.MeshMultiZoneServiceStatus, error) {
out, err := cluster.GetKumactlOptions().RunKumactlAndGetOutput("get", "meshmultizoneservice", "-m", meshName, hash.HashedName(meshName, name), "-ojson")
if err != nil {
Expand Down

0 comments on commit 2e266da

Please sign in to comment.