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
ade092fe
Commit
ade092fe
authored
Aug 08, 2016
by
Random-Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add container ports label.
parent
16621cd3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
labels.go
pkg/kubelet/dockertools/labels.go
+16
-1
labels_test.go
pkg/kubelet/dockertools/labels_test.go
+16
-0
No files found.
pkg/kubelet/dockertools/labels.go
View file @
ade092fe
...
@@ -42,6 +42,7 @@ const (
...
@@ -42,6 +42,7 @@ const (
kubernetesContainerRestartCountLabel
=
"io.kubernetes.container.restartCount"
kubernetesContainerRestartCountLabel
=
"io.kubernetes.container.restartCount"
kubernetesContainerTerminationMessagePathLabel
=
"io.kubernetes.container.terminationMessagePath"
kubernetesContainerTerminationMessagePathLabel
=
"io.kubernetes.container.terminationMessagePath"
kubernetesContainerPreStopHandlerLabel
=
"io.kubernetes.container.preStopHandler"
kubernetesContainerPreStopHandlerLabel
=
"io.kubernetes.container.preStopHandler"
kubernetesContainerPortsLabel
=
"io.kubernetes.container.ports"
// Added in 1.4
// TODO(random-liu): Keep this for old containers, remove this when we drop support for v1.1.
// TODO(random-liu): Keep this for old containers, remove this when we drop support for v1.1.
kubernetesPodLabel
=
"io.kubernetes.pod.data"
kubernetesPodLabel
=
"io.kubernetes.pod.data"
...
@@ -62,6 +63,7 @@ type labelledContainerInfo struct {
...
@@ -62,6 +63,7 @@ type labelledContainerInfo struct {
RestartCount
int
RestartCount
int
TerminationMessagePath
string
TerminationMessagePath
string
PreStopHandler
*
api
.
Handler
PreStopHandler
*
api
.
Handler
Ports
[]
api
.
ContainerPort
}
}
func
newLabels
(
container
*
api
.
Container
,
pod
*
api
.
Pod
,
restartCount
int
,
enableCustomMetrics
bool
)
map
[
string
]
string
{
func
newLabels
(
container
*
api
.
Container
,
pod
*
api
.
Pod
,
restartCount
int
,
enableCustomMetrics
bool
)
map
[
string
]
string
{
...
@@ -89,7 +91,14 @@ func newLabels(container *api.Container, pod *api.Pod, restartCount int, enableC
...
@@ -89,7 +91,14 @@ func newLabels(container *api.Container, pod *api.Pod, restartCount int, enableC
labels
[
kubernetesContainerPreStopHandlerLabel
]
=
string
(
rawPreStop
)
labels
[
kubernetesContainerPreStopHandlerLabel
]
=
string
(
rawPreStop
)
}
}
}
}
if
len
(
container
.
Ports
)
>
0
{
rawContainerPorts
,
err
:=
json
.
Marshal
(
container
.
Ports
)
if
err
!=
nil
{
glog
.
Errorf
(
"Unable to marshal container ports for container %q for pod %q: %v"
,
container
.
Name
,
format
.
Pod
(
pod
),
err
)
}
else
{
labels
[
kubernetesContainerPortsLabel
]
=
string
(
rawContainerPorts
)
}
}
if
enableCustomMetrics
{
if
enableCustomMetrics
{
path
,
err
:=
custommetrics
.
GetCAdvisorCustomMetricsDefinitionPath
(
container
)
path
,
err
:=
custommetrics
.
GetCAdvisorCustomMetricsDefinitionPath
(
container
)
if
path
!=
nil
&&
err
==
nil
{
if
path
!=
nil
&&
err
==
nil
{
...
@@ -125,6 +134,12 @@ func getContainerInfoFromLabel(labels map[string]string) *labelledContainerInfo
...
@@ -125,6 +134,12 @@ func getContainerInfoFromLabel(labels map[string]string) *labelledContainerInfo
}
else
if
found
{
}
else
if
found
{
containerInfo
.
PreStopHandler
=
preStopHandler
containerInfo
.
PreStopHandler
=
preStopHandler
}
}
containerPorts
:=
[]
api
.
ContainerPort
{}
if
found
,
err
:=
getJsonObjectFromLabel
(
labels
,
kubernetesContainerPortsLabel
,
&
containerPorts
);
err
!=
nil
{
logError
(
containerInfo
,
kubernetesContainerPortsLabel
,
err
)
}
else
if
found
{
containerInfo
.
Ports
=
containerPorts
}
supplyContainerInfoWithOldLabel
(
labels
,
containerInfo
)
supplyContainerInfoWithOldLabel
(
labels
,
containerInfo
)
return
containerInfo
return
containerInfo
}
}
...
...
pkg/kubelet/dockertools/labels_test.go
View file @
ade092fe
...
@@ -50,8 +50,23 @@ func TestLabels(t *testing.T) {
...
@@ -50,8 +50,23 @@ func TestLabels(t *testing.T) {
},
},
},
},
}
}
containerPorts
:=
[]
api
.
ContainerPort
{
{
Name
:
"http"
,
HostPort
:
80
,
ContainerPort
:
8080
,
Protocol
:
api
.
ProtocolTCP
,
},
{
Name
:
"https"
,
HostPort
:
443
,
ContainerPort
:
6443
,
Protocol
:
api
.
ProtocolTCP
,
},
}
container
:=
&
api
.
Container
{
container
:=
&
api
.
Container
{
Name
:
"test_container"
,
Name
:
"test_container"
,
Ports
:
containerPorts
,
TerminationMessagePath
:
"/somepath"
,
TerminationMessagePath
:
"/somepath"
,
Lifecycle
:
lifecycle
,
Lifecycle
:
lifecycle
,
}
}
...
@@ -78,6 +93,7 @@ func TestLabels(t *testing.T) {
...
@@ -78,6 +93,7 @@ func TestLabels(t *testing.T) {
RestartCount
:
restartCount
,
RestartCount
:
restartCount
,
TerminationMessagePath
:
container
.
TerminationMessagePath
,
TerminationMessagePath
:
container
.
TerminationMessagePath
,
PreStopHandler
:
container
.
Lifecycle
.
PreStop
,
PreStopHandler
:
container
.
Lifecycle
.
PreStop
,
Ports
:
containerPorts
,
}
}
// Test whether we can get right information from label
// Test whether we can get right information from label
...
...
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