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
3ea4de60
Commit
3ea4de60
authored
May 08, 2017
by
Timothy St. Clair
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a utility to convert componentconfig into a configmap
parent
6dab46e3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
0 deletions
+75
-0
BUILD
pkg/apis/componentconfig/BUILD
+1
-0
helpers.go
pkg/apis/componentconfig/helpers.go
+22
-0
BUILD
pkg/apis/componentconfig/v1alpha1/BUILD
+9
-0
defaults_test.go
pkg/apis/componentconfig/v1alpha1/defaults_test.go
+43
-0
No files found.
pkg/apis/componentconfig/BUILD
View file @
3ea4de60
...
...
@@ -20,6 +20,7 @@ go_library(
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
...
...
pkg/apis/componentconfig/helpers.go
View file @
3ea4de60
...
...
@@ -17,10 +17,14 @@ limitations under the License.
package
componentconfig
import
(
"encoding/json"
"fmt"
"net"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilnet
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/kubernetes/pkg/api/v1"
)
// used for validating command line opts
...
...
@@ -95,3 +99,21 @@ func (v PortRangeVar) String() string {
func
(
v
PortRangeVar
)
Type
()
string
{
return
"port-range"
}
// ConvertObjToConfigMap converts an object to a ConfigMap.
// This is specifically meant for ComponentConfigs.
func
ConvertObjToConfigMap
(
name
string
,
obj
runtime
.
Object
)
(
*
v1
.
ConfigMap
,
error
)
{
eJSONBytes
,
err
:=
json
.
Marshal
(
obj
)
if
err
!=
nil
{
return
nil
,
err
}
cm
:=
&
v1
.
ConfigMap
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
name
,
},
Data
:
map
[
string
]
string
{
name
:
string
(
eJSONBytes
[
:
]),
},
}
return
cm
,
nil
}
pkg/apis/componentconfig/v1alpha1/BUILD
View file @
3ea4de60
...
...
@@ -5,6 +5,7 @@ licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
...
...
@@ -45,3 +46,11 @@ filegroup(
srcs = [":package-srcs"],
tags = ["automanaged"],
)
go_test(
name = "go_default_test",
srcs = ["defaults_test.go"],
library = ":go_default_library",
tags = ["automanaged"],
deps = ["//pkg/apis/componentconfig:go_default_library"],
)
pkg/apis/componentconfig/v1alpha1/defaults_test.go
0 → 100644
View file @
3ea4de60
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
v1alpha1
import
(
"encoding/json"
"reflect"
"testing"
componentconfig
"k8s.io/kubernetes/pkg/apis/componentconfig"
)
func
TestSchedulerDefaults
(
t
*
testing
.
T
)
{
ks1
:=
&
KubeSchedulerConfiguration
{}
SetDefaults_KubeSchedulerConfiguration
(
ks1
)
cm
,
err
:=
componentconfig
.
ConvertObjToConfigMap
(
"KubeSchedulerConfiguration"
,
ks1
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected ConvertObjToConfigMap error %v"
,
err
)
}
ks2
:=
&
KubeSchedulerConfiguration
{}
if
err
=
json
.
Unmarshal
([]
byte
(
cm
.
Data
[
"KubeSchedulerConfiguration"
]),
ks2
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error unserializing scheduler config %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
ks2
,
ks1
)
{
t
.
Errorf
(
"Expected:
\n
%#v
\n\n
Got:
\n
%#v"
,
ks1
,
ks2
)
}
}
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