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
ff1da767
Commit
ff1da767
authored
Apr 15, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24268 from wojtek-t/remove_old_conversions_generator
Automatic merge from submit-queue Remove old conversion generator
parents
d56ec66e
89e860e6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
31 additions
and
387 deletions
+31
-387
conversion.go
cmd/genconversion/conversion.go
+0
-132
update-generated-conversions.sh
hack/after-build/update-generated-conversions.sh
+0
-52
verify-generated-conversions.sh
hack/after-build/verify-generated-conversions.sh
+0
-53
golang.sh
hack/lib/golang.sh
+0
-1
update-all.sh
hack/update-all.sh
+0
-1
update-generated-conversions.sh
hack/update-generated-conversions.sh
+0
-30
verify-generated-conversions.sh
hack/verify-generated-conversions.sh
+0
-30
pre-commit
hooks/pre-commit
+0
-12
conversion_generator.go
pkg/runtime/conversion_generator.go
+0
-0
conversion_generator_test.go
pkg/runtime/conversion_generator_test.go
+0
-76
swagger_doc_generator.go
pkg/runtime/swagger_doc_generator.go
+31
-0
No files found.
cmd/genconversion/conversion.go
deleted
100644 → 0
View file @
d56ec66e
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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
main
import
(
"bytes"
"fmt"
"io"
"os"
"path"
"runtime"
"k8s.io/kubernetes/pkg/api"
_
"k8s.io/kubernetes/pkg/api/install"
"k8s.io/kubernetes/pkg/api/unversioned"
_
"k8s.io/kubernetes/pkg/apis/autoscaling/install"
_
"k8s.io/kubernetes/pkg/apis/batch/install"
_
"k8s.io/kubernetes/pkg/apis/componentconfig/install"
_
"k8s.io/kubernetes/pkg/apis/extensions/install"
_
"k8s.io/kubernetes/pkg/apis/metrics/install"
kruntime
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/sets"
"github.com/golang/glog"
flag
"github.com/spf13/pflag"
"golang.org/x/tools/imports"
)
const
pkgBase
=
"k8s.io/kubernetes/pkg"
var
(
functionDest
=
flag
.
StringP
(
"funcDest"
,
"f"
,
"-"
,
"Output for conversion functions; '-' means stdout"
)
groupVersion
=
flag
.
StringP
(
"version"
,
"v"
,
"api/v1"
,
"groupPath/version for conversion."
)
)
// We're moving to pkg/apis/group/version. This handles new and legacy packages.
func
pkgPath
(
group
,
version
string
)
string
{
if
group
==
""
{
group
=
"api"
}
gv
:=
group
if
version
!=
""
{
gv
=
path
.
Join
(
group
,
version
)
}
switch
{
case
group
==
"api"
:
// TODO(lavalamp): remove this special case when we move api to apis/api
return
path
.
Join
(
pkgBase
,
gv
)
default
:
return
path
.
Join
(
pkgBase
,
"apis"
,
gv
)
}
}
func
main
()
{
runtime
.
GOMAXPROCS
(
runtime
.
NumCPU
())
flag
.
Parse
()
var
funcOut
io
.
Writer
if
*
functionDest
==
"-"
{
funcOut
=
os
.
Stdout
}
else
{
file
,
err
:=
os
.
Create
(
*
functionDest
)
if
err
!=
nil
{
glog
.
Fatalf
(
"Couldn't open %v: %v"
,
*
functionDest
,
err
)
}
defer
file
.
Close
()
funcOut
=
file
}
data
:=
new
(
bytes
.
Buffer
)
gv
,
err
:=
unversioned
.
ParseGroupVersion
(
*
groupVersion
)
if
err
!=
nil
{
glog
.
Fatalf
(
"Error parsing groupversion %v: %v"
,
*
groupVersion
,
err
)
}
_
,
err
=
data
.
WriteString
(
fmt
.
Sprintf
(
"package %v
\n
"
,
gv
.
Version
))
if
err
!=
nil
{
glog
.
Fatalf
(
"Error while writing package line: %v"
,
err
)
}
versionPath
:=
pkgPath
(
gv
.
Group
,
gv
.
Version
)
generator
:=
kruntime
.
NewConversionGenerator
(
api
.
Scheme
,
versionPath
)
apiShort
:=
generator
.
AddImport
(
path
.
Join
(
pkgBase
,
"api"
))
generator
.
AddImport
(
path
.
Join
(
pkgBase
,
"api/resource"
))
generator
.
AddImport
(
path
.
Join
(
pkgBase
,
"types"
))
// TODO(wojtek-t): Change the overwrites to a flag.
generator
.
OverwritePackage
(
gv
.
Version
,
""
)
for
_
,
knownType
:=
range
api
.
Scheme
.
KnownTypes
(
gv
)
{
if
knownType
.
PkgPath
()
!=
versionPath
{
continue
}
if
err
:=
generator
.
GenerateConversionsForType
(
gv
,
knownType
);
err
!=
nil
{
glog
.
Errorf
(
"Error while generating conversion functions for %v: %v"
,
knownType
,
err
)
}
}
generator
.
RepackImports
(
sets
.
NewString
())
if
err
:=
generator
.
WriteImports
(
data
);
err
!=
nil
{
glog
.
Fatalf
(
"Error while writing imports: %v"
,
err
)
}
if
err
:=
generator
.
WriteConversionFunctions
(
data
);
err
!=
nil
{
glog
.
Fatalf
(
"Error while writing conversion functions: %v"
,
err
)
}
if
err
:=
generator
.
RegisterConversionFunctions
(
data
,
fmt
.
Sprintf
(
"%s.Scheme"
,
apiShort
));
err
!=
nil
{
glog
.
Fatalf
(
"Error while writing conversion functions: %v"
,
err
)
}
b
,
err
:=
imports
.
Process
(
""
,
data
.
Bytes
(),
nil
)
if
err
!=
nil
{
for
i
,
s
:=
range
bytes
.
Split
(
data
.
Bytes
(),
[]
byte
(
"
\n
"
))
{
glog
.
Infof
(
"%d:
\t
%s"
,
i
,
s
)
}
glog
.
Fatalf
(
"Error while update imports: %v
\n
"
,
err
)
}
if
_
,
err
:=
funcOut
.
Write
(
b
);
err
!=
nil
{
glog
.
Fatalf
(
"Error while writing out the resulting file: %v"
,
err
)
}
}
hack/after-build/update-generated-conversions.sh
deleted
100755 → 0
View file @
d56ec66e
#!/bin/bash
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# 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.
set
-o
errexit
set
-o
nounset
set
-o
pipefail
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/../..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
kube::golang::setup_env
genconversion
=
$(
kube::util::find-binary
"genconversion"
)
function
generate_version
()
{
local
group_version
=
$1
local
TMPFILE
=
"/tmp/conversion_generated.
$(
date
+%s
)
.go"
echo
"Generating for
${
group_version
}
"
sed
's/YEAR/2015/'
hack/boilerplate/boilerplate.go.txt
>
"
$TMPFILE
"
cat
>>
"
$TMPFILE
"
<<
EOF
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY \
$KUBEROOT
/hack/update-generated-conversions.sh
EOF
"
${
genconversion
}
"
-v
"
${
group_version
}
"
-f
-
>>
"
$TMPFILE
"
mv
"
$TMPFILE
"
"pkg/
$(
kube::util::group-version-to-pkg-path
"
${
group_version
}
"
)
/conversion_generated.go"
}
# TODO(lavalamp): get this list by listing the pkg/apis/ directory?
DEFAULT_GROUP_VERSIONS
=
""
VERSIONS
=
${
VERSIONS
:-
$DEFAULT_GROUP_VERSIONS
}
for
ver
in
$VERSIONS
;
do
# Ensure that the version being processed is registered by setting
# KUBE_API_VERSIONS.
KUBE_API_VERSIONS
=
"
${
ver
}
"
generate_version
"
${
ver
}
"
done
hack/after-build/verify-generated-conversions.sh
deleted
100755 → 0
View file @
d56ec66e
#!/bin/bash
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# 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.
set
-o
errexit
set
-o
nounset
set
-o
pipefail
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/../..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
kube::golang::setup_env
APIROOTS
=
${
APIROOTS
:-
pkg
/apis/authorization pkg/apis/autoscaling pkg/apis/batch pkg/apis/extensions pkg/apis/metrics
}
_tmp
=
"
${
KUBE_ROOT
}
/_tmp"
cleanup
()
{
rm
-rf
"
${
_tmp
}
"
}
trap
"cleanup"
EXIT SIGINT
for
APIROOT
in
${
APIROOTS
}
;
do
mkdir
-p
"
${
_tmp
}
/
${
APIROOT
%/*
}
"
cp
-a
"
${
KUBE_ROOT
}
/
${
APIROOT
}
"
"
${
_tmp
}
/
${
APIROOT
}
"
done
"
${
KUBE_ROOT
}
/hack/after-build/update-generated-conversions.sh"
for
APIROOT
in
${
APIROOTS
}
;
do
TMP_APIROOT
=
"
${
_tmp
}
/
${
APIROOT
}
"
echo
"diffing
${
APIROOT
}
against freshly generated conversions"
ret
=
0
diff
-Naupr
-I
'Auto generated by'
"
${
KUBE_ROOT
}
/
${
APIROOT
}
"
"
${
TMP_APIROOT
}
"
||
ret
=
$?
cp
-a
"
${
TMP_APIROOT
}
"
"
${
KUBE_ROOT
}
/
${
APIROOT
%/*
}
"
if
[[
$ret
-eq
0
]]
;
then
echo
"
${
APIROOT
}
up to date."
else
echo
"
${
APIROOT
}
is out of date. Please run hack/update-generated-conversions.sh"
exit
1
fi
done
hack/lib/golang.sh
View file @
ff1da767
...
...
@@ -108,7 +108,6 @@ kube::golang::test_targets() {
cmd/genyaml
cmd/mungedocs
cmd/genbashcomp
cmd/genconversion
cmd/genswaggertypedocs
examples/k8petstore/web-server/src
github.com/onsi/ginkgo/ginkgo
...
...
hack/update-all.sh
View file @
ff1da767
...
...
@@ -51,7 +51,6 @@ if ! $ALL ; then
fi
BASH_TARGETS
=
"codecgen
generated-conversions
generated-docs
generated-swagger-docs
swagger-spec
...
...
hack/update-generated-conversions.sh
deleted
100755 → 0
View file @
d56ec66e
#!/bin/bash
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# 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.
set
-o
errexit
set
-o
nounset
set
-o
pipefail
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
kube::golang::setup_env
"
${
KUBE_ROOT
}
/hack/build-go.sh"
cmd/genconversion
"
${
KUBE_ROOT
}
/hack/after-build/update-generated-conversions.sh"
"
$@
"
# ex: ts=2 sw=2 et filetype=sh
hack/verify-generated-conversions.sh
deleted
100755 → 0
View file @
d56ec66e
#!/bin/bash
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# 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.
set
-o
errexit
set
-o
nounset
set
-o
pipefail
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
kube::golang::setup_env
"
${
KUBE_ROOT
}
/hack/build-go.sh"
cmd/genconversion
"
${
KUBE_ROOT
}
/hack/after-build/verify-generated-conversions.sh"
"
$@
"
# ex: ts=2 sw=2 et filetype=sh
hooks/pre-commit
View file @
ff1da767
...
...
@@ -134,18 +134,6 @@ else
fi
echo
"
${
reset
}
"
echo
-ne
"Checking for conversions that need updating... "
if
!
hack/after-build/verify-generated-conversions.sh
>
/dev/null
;
then
echo
"
${
red
}
ERROR!"
echo
"Some conversions functions need regeneration."
echo
"To regenerate conversions, run:"
echo
" hack/update-generated-conversions.sh"
exit_code
=
1
else
echo
"
${
green
}
OK"
fi
echo
"
${
reset
}
"
echo
-ne
"Checking for swagger type documentation that need updating... "
if
!
hack/after-build/verify-generated-swagger-docs.sh
>
/dev/null
;
then
echo
"
${
red
}
ERROR!"
...
...
pkg/runtime/conversion_generator.go
deleted
100644 → 0
View file @
d56ec66e
This diff is collapsed.
Click to expand it.
pkg/runtime/conversion_generator_test.go
deleted
100644 → 0
View file @
d56ec66e
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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
runtime
import
(
"reflect"
"testing"
"k8s.io/kubernetes/pkg/api/unversioned"
)
type
InternalSubtype
struct
{
String
string
}
type
Internal
struct
{
TypeMeta
Bool
bool
Complex
InternalSubtype
}
type
ExternalSubtype
struct
{
String
string
}
type
External
struct
{
TypeMeta
Complex
ExternalSubtype
}
func
(
obj
*
Internal
)
GetObjectKind
()
unversioned
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
External
)
GetObjectKind
()
unversioned
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
TestGenerateConversionsForStruct
(
t
*
testing
.
T
)
{
internalGV
:=
unversioned
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
APIVersionInternal
}
externalGV
:=
unversioned
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
"external"
}
scheme
:=
NewScheme
()
scheme
.
Log
(
t
)
scheme
.
AddKnownTypeWithName
(
internalGV
.
WithKind
(
"Complex"
),
&
Internal
{})
scheme
.
AddKnownTypeWithName
(
externalGV
.
WithKind
(
"Complex"
),
&
External
{})
generator
:=
NewConversionGenerator
(
scheme
,
"foo"
)
typedGenerator
,
ok
:=
generator
.
(
*
conversionGenerator
)
if
!
ok
{
t
.
Fatalf
(
"error converting to conversionGenerator"
)
}
internalType
:=
reflect
.
TypeOf
(
Internal
{})
externalType
:=
reflect
.
TypeOf
(
External
{})
err
:=
typedGenerator
.
generateConversionsForStruct
(
internalType
,
externalType
)
if
err
==
nil
{
t
.
Errorf
(
"expected error for asymmetrical field"
)
}
// we are expecting Convert_runtime_InternalSubtype_To_runtime_ExternalSubtype to be generated
// even though the conversion for the parent type cannot be auto generated
if
len
(
typedGenerator
.
publicFuncs
)
!=
1
{
t
.
Errorf
(
"expected to find one public conversion for the Complex type but found: %v"
,
typedGenerator
.
publicFuncs
)
}
}
pkg/runtime/swagger_doc_generator.go
View file @
ff1da767
...
...
@@ -113,6 +113,37 @@ func fieldName(field *ast.Field) string {
return
jsonTag
}
// A buffer of lines that will be written.
type
bufferedLine
struct
{
line
string
indentation
int
}
type
buffer
struct
{
lines
[]
bufferedLine
}
func
newBuffer
()
*
buffer
{
return
&
buffer
{
lines
:
make
([]
bufferedLine
,
0
),
}
}
func
(
b
*
buffer
)
addLine
(
line
string
,
indent
int
)
{
b
.
lines
=
append
(
b
.
lines
,
bufferedLine
{
line
,
indent
})
}
func
(
b
*
buffer
)
flushLines
(
w
io
.
Writer
)
error
{
for
_
,
line
:=
range
b
.
lines
{
indentation
:=
strings
.
Repeat
(
"
\t
"
,
line
.
indentation
)
fullLine
:=
fmt
.
Sprintf
(
"%s%s"
,
indentation
,
line
.
line
)
if
_
,
err
:=
io
.
WriteString
(
w
,
fullLine
);
err
!=
nil
{
return
err
}
}
return
nil
}
func
writeFuncHeader
(
b
*
buffer
,
structName
string
,
indent
int
)
{
s
:=
fmt
.
Sprintf
(
"var map_%s = map[string]string {
\n
"
,
structName
)
b
.
addLine
(
s
,
indent
)
...
...
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