Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
21611c56
Commit
21611c56
authored
Jul 22, 2024
by
Brad Davidson
Committed by
Brad Davidson
Jul 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cap length of generated name used for servicelb daemonset
Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
891e72f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
servicelb.go
pkg/cloudprovider/servicelb.go
+11
-1
servicelb_test.go
pkg/cloudprovider/servicelb_test.go
+49
-0
No files found.
pkg/cloudprovider/servicelb.go
View file @
21611c56
...
...
@@ -699,7 +699,17 @@ func (k *k3s) getPriorityClassName(svc *core.Service) string {
// generateName generates a distinct name for the DaemonSet based on the service name and UID
func
generateName
(
svc
*
core
.
Service
)
string
{
return
fmt
.
Sprintf
(
"svclb-%s-%s"
,
svc
.
Name
,
svc
.
UID
[
:
8
])
name
:=
svc
.
Name
// ensure that the service name plus prefix and uuid aren't overly long, but
// don't cut the service name at a trailing hyphen.
if
len
(
name
)
>
48
{
trimlen
:=
48
for
name
[
trimlen
-
1
]
==
'-'
{
trimlen
--
}
name
=
name
[
0
:
trimlen
]
}
return
fmt
.
Sprintf
(
"svclb-%s-%s"
,
name
,
svc
.
UID
[
:
8
])
}
// ingressToString converts a list of LoadBalancerIngress entries to strings
...
...
pkg/cloudprovider/servicelb_test.go
View file @
21611c56
...
...
@@ -6,6 +6,8 @@ import (
"testing"
core
"k8s.io/api/core/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
const
(
...
...
@@ -111,3 +113,50 @@ func Test_UnitFilterByIPFamily_Ordering(t *testing.T) {
t
.
Errorf
(
"filterByIPFamily() = %+v
\n
Want = %+v"
,
got
,
want
)
}
}
func
Test_UnitGenerateName
(
t
*
testing
.
T
)
{
uid
:=
types
.
UID
(
"35a5ccb3-4a82-40b7-8d83-cda9582e4251"
)
tests
:=
[]
struct
{
name
string
svc
*
core
.
Service
want
string
}{
{
name
:
"Short name"
,
svc
:
&
core
.
Service
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
"a-service"
,
UID
:
uid
,
},
},
want
:
"svclb-a-service-35a5ccb3"
,
},
{
name
:
"Long name"
,
svc
:
&
core
.
Service
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
"a-service-with-a-very-veeeeeery-long-yet-valid-name"
,
UID
:
uid
,
},
},
want
:
"svclb-a-service-with-a-very-veeeeeery-long-yet-valid-n-35a5ccb3"
,
},
{
name
:
"Long hypenated name"
,
svc
:
&
core
.
Service
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
"a-service-with-a-name-with-inconvenient------------hypens"
,
UID
:
uid
,
},
},
want
:
"svclb-a-service-with-a-name-with-inconvenient-35a5ccb3"
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
got
:=
generateName
(
tt
.
svc
);
got
!=
tt
.
want
{
t
.
Errorf
(
"generateName() = %+v
\n
Want = %+v"
,
got
,
tt
.
want
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment