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
1e161bb3
Commit
1e161bb3
authored
Oct 31, 2018
by
Sean Sullivan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubectl: change legacyscheme codecs to direct codecs (no conversion)
parent
b8731a76
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
8 deletions
+50
-8
BUILD
pkg/kubectl/cmd/util/BUILD
+2
-0
kubectl_match_version.go
pkg/kubectl/cmd/util/kubectl_match_version.go
+6
-2
protocolsforobject.go
pkg/kubectl/polymorphichelpers/protocolsforobject.go
+8
-0
protocolsforobject_test.go
pkg/kubectl/polymorphichelpers/protocolsforobject_test.go
+34
-6
No files found.
pkg/kubectl/cmd/util/BUILD
View file @
1e161bb3
...
...
@@ -17,6 +17,7 @@ go_library(
"//pkg/api/legacyscheme:go_default_library",
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//pkg/kubectl/cmd/util/openapi/validation:go_default_library",
"//pkg/kubectl/scheme:go_default_library",
"//pkg/kubectl/util/templates:go_default_library",
"//pkg/kubectl/validation:go_default_library",
"//pkg/version:go_default_library",
...
...
@@ -27,6 +28,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/yaml:go_default_library",
...
...
pkg/kubectl/cmd/util/kubectl_match_version.go
View file @
1e161bb3
...
...
@@ -23,12 +23,13 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/version"
)
...
...
@@ -120,7 +121,10 @@ func setKubernetesDefaults(config *rest.Config) error {
config
.
APIPath
=
"/api"
}
if
config
.
NegotiatedSerializer
==
nil
{
config
.
NegotiatedSerializer
=
legacyscheme
.
Codecs
// This codec factory ensures the resources are not converted. Therefore, resources
// will not be round-tripped through internal versions. Defaulting does not happen
// on the client.
config
.
NegotiatedSerializer
=
&
serializer
.
DirectCodecFactory
{
CodecFactory
:
scheme
.
Codecs
}
}
return
rest
.
SetKubernetesDefaults
(
config
)
}
pkg/kubectl/polymorphichelpers/protocolsforobject.go
View file @
1e161bb3
...
...
@@ -65,6 +65,10 @@ func getProtocols(spec corev1.PodSpec) map[string]string {
result
:=
make
(
map
[
string
]
string
)
for
_
,
container
:=
range
spec
.
Containers
{
for
_
,
port
:=
range
container
.
Ports
{
// Empty protocol must be defaulted (TCP)
if
len
(
port
.
Protocol
)
==
0
{
port
.
Protocol
=
corev1
.
ProtocolTCP
}
result
[
strconv
.
Itoa
(
int
(
port
.
ContainerPort
))]
=
string
(
port
.
Protocol
)
}
}
...
...
@@ -75,6 +79,10 @@ func getProtocols(spec corev1.PodSpec) map[string]string {
func
getServiceProtocols
(
spec
corev1
.
ServiceSpec
)
map
[
string
]
string
{
result
:=
make
(
map
[
string
]
string
)
for
_
,
servicePort
:=
range
spec
.
Ports
{
// Empty protocol must be defaulted (TCP)
if
len
(
servicePort
.
Protocol
)
==
0
{
servicePort
.
Protocol
=
corev1
.
ProtocolTCP
}
result
[
strconv
.
Itoa
(
int
(
servicePort
.
Port
))]
=
string
(
servicePort
.
Protocol
)
}
return
result
...
...
pkg/kubectl/polymorphichelpers/protocolsforobject_test.go
View file @
1e161bb3
...
...
@@ -39,7 +39,23 @@ func TestProtocolsForObject(t *testing.T) {
Ports
:
[]
corev1
.
ContainerPort
{
{
ContainerPort
:
101
,
Protocol
:
"tcp"
,
Protocol
:
"TCP"
,
},
},
},
},
},
},
},
// No protocol--should default to TCP.
{
object
:
&
corev1
.
Pod
{
Spec
:
corev1
.
PodSpec
{
Containers
:
[]
corev1
.
Container
{
{
Ports
:
[]
corev1
.
ContainerPort
{
{
ContainerPort
:
101
,
},
},
},
...
...
@@ -53,7 +69,19 @@ func TestProtocolsForObject(t *testing.T) {
Ports
:
[]
corev1
.
ServicePort
{
{
Port
:
101
,
Protocol
:
"tcp"
,
Protocol
:
"TCP"
,
},
},
},
},
},
// No protocol for service port--default to TCP
{
object
:
&
corev1
.
Service
{
Spec
:
corev1
.
ServiceSpec
{
Ports
:
[]
corev1
.
ServicePort
{
{
Port
:
101
,
},
},
},
...
...
@@ -69,7 +97,7 @@ func TestProtocolsForObject(t *testing.T) {
Ports
:
[]
corev1
.
ContainerPort
{
{
ContainerPort
:
101
,
Protocol
:
"
tcp
"
,
Protocol
:
"
TCP
"
,
},
},
},
...
...
@@ -89,7 +117,7 @@ func TestProtocolsForObject(t *testing.T) {
Ports
:
[]
corev1
.
ContainerPort
{
{
ContainerPort
:
101
,
Protocol
:
"
tcp
"
,
Protocol
:
"
TCP
"
,
},
},
},
...
...
@@ -109,7 +137,7 @@ func TestProtocolsForObject(t *testing.T) {
Ports
:
[]
corev1
.
ContainerPort
{
{
ContainerPort
:
101
,
Protocol
:
"
tcp
"
,
Protocol
:
"
TCP
"
,
},
},
},
...
...
@@ -124,7 +152,7 @@ func TestProtocolsForObject(t *testing.T) {
expectErr
:
true
,
},
}
expectedPorts
:=
map
[
string
]
string
{
"101"
:
"
tcp
"
}
expectedPorts
:=
map
[
string
]
string
{
"101"
:
"
TCP
"
}
for
_
,
test
:=
range
tests
{
actual
,
err
:=
protocolsForObject
(
test
.
object
)
...
...
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