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
79d8868c
Commit
79d8868c
authored
Jul 29, 2016
by
Vishnu Kannan
Committed by
Vishnu kannan
Jul 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add instance metadata to image config file
Signed-off-by:
Vishnu Kannan
<
vishnuk@google.com
>
parent
bb4e1e62
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
40 deletions
+68
-40
gci-init.yaml
test/e2e_node/jenkins/gci-init.yaml
+2
-2
run_e2e.go
test/e2e_node/runner/run_e2e.go
+66
-38
No files found.
test/e2e_node/jenkins/gci-init.yaml
View file @
79d8868c
#cloud-config
#cloud-config
runcmd
:
runcmd
:
-
sudo
mount /tmp /tmp -o remount,exec,suid
-
mount /tmp /tmp -o remount,exec,suid
-
ETCD_VERSION=v2.2.5
-
ETCD_VERSION=v2.2.5
-
curl -L https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz -o /tmp/etcd.tar.gz
-
curl -L https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz -o /tmp/etcd.tar.gz
-
tar xzvf /tmp/etcd.tar.gz -C /tmp
-
tar xzvf /tmp/etcd.tar.gz -C /tmp
-
cp /tmp/etcd-${ETCD_VERSION}-linux-amd64/etcd* /tmp/
-
cp /tmp/etcd-${ETCD_VERSION}-linux-amd64/etcd* /tmp/
-
rm -rf /tmp/etcd-${ETCD_VERSION}-linux-amd64/
-
rm -rf /tmp/etcd-${ETCD_VERSION}-linux-amd64/
-
sudo
usermod -a -G docker jenkins
-
usermod -a -G docker jenkins
test/e2e_node/runner/run_e2e.go
View file @
79d8868c
...
@@ -86,8 +86,19 @@ type ImageConfig struct {
...
@@ -86,8 +86,19 @@ type ImageConfig struct {
}
}
type
GCEImage
struct
{
type
GCEImage
struct
{
Image
string
`json:"image"`
Image
string
`json:"image"`
Project
string
`json:"project"`
Project
string
`json:"project"`
Metadata
string
`json:"metadata"`
}
type
internalImageConfig
struct
{
images
map
[
string
]
internalGCEImage
}
type
internalGCEImage
struct
{
image
string
project
string
metadata
*
compute
.
Metadata
}
}
func
main
()
{
func
main
()
{
...
@@ -102,8 +113,8 @@ func main() {
...
@@ -102,8 +113,8 @@ func main() {
if
*
hosts
==
""
&&
*
imageConfigFile
==
""
&&
*
images
==
""
{
if
*
hosts
==
""
&&
*
imageConfigFile
==
""
&&
*
images
==
""
{
glog
.
Fatalf
(
"Must specify one of --image-config-file, --hosts, --images."
)
glog
.
Fatalf
(
"Must specify one of --image-config-file, --hosts, --images."
)
}
}
gceImages
:=
&
ImageConfig
{
gceImages
:=
&
internal
ImageConfig
{
Images
:
make
(
map
[
string
]
GCEImage
),
images
:
make
(
map
[
string
]
internal
GCEImage
),
}
}
if
*
imageConfigFile
!=
""
{
if
*
imageConfigFile
!=
""
{
// parse images
// parse images
...
@@ -111,10 +122,19 @@ func main() {
...
@@ -111,10 +122,19 @@ func main() {
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Could not read image config file provided: %v"
,
err
)
glog
.
Fatalf
(
"Could not read image config file provided: %v"
,
err
)
}
}
err
=
yaml
.
Unmarshal
(
imageConfigData
,
gceImages
)
externalImageConfig
:=
ImageConfig
{
Images
:
make
(
map
[
string
]
GCEImage
)}
err
=
yaml
.
Unmarshal
(
imageConfigData
,
&
externalImageConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Could not parse image config file: %v"
,
err
)
glog
.
Fatalf
(
"Could not parse image config file: %v"
,
err
)
}
}
for
key
,
imageConfig
:=
range
externalImageConfig
.
Images
{
gceImage
:=
internalGCEImage
{
image
:
imageConfig
.
Image
,
project
:
imageConfig
.
Project
,
metadata
:
getImageMetadata
(
imageConfig
.
Metadata
),
}
gceImages
.
images
[
key
]
=
gceImage
}
}
}
// Allow users to specify additional images via cli flags for local testing
// Allow users to specify additional images via cli flags for local testing
...
@@ -125,22 +145,24 @@ func main() {
...
@@ -125,22 +145,24 @@ func main() {
}
}
cliImages
:=
strings
.
Split
(
*
images
,
","
)
cliImages
:=
strings
.
Split
(
*
images
,
","
)
for
_
,
img
:=
range
cliImages
{
for
_
,
img
:=
range
cliImages
{
gceImages
.
Images
[
img
]
=
GCEImage
{
gceImage
:=
internalGCEImage
{
Image
:
img
,
image
:
img
,
Project
:
*
imageProject
,
project
:
*
imageProject
,
metadata
:
getImageMetadata
(
*
instanceMetadata
),
}
}
gceImages
.
images
[
img
]
=
gceImage
}
}
}
}
if
len
(
gceImages
.
I
mages
)
!=
0
&&
*
zone
==
""
{
if
len
(
gceImages
.
i
mages
)
!=
0
&&
*
zone
==
""
{
glog
.
Fatal
(
"Must specify --zone flag"
)
glog
.
Fatal
(
"Must specify --zone flag"
)
}
}
for
shortName
,
image
:=
range
gceImages
.
I
mages
{
for
shortName
,
image
:=
range
gceImages
.
i
mages
{
if
image
.
P
roject
==
""
{
if
image
.
p
roject
==
""
{
glog
.
Fatalf
(
"Invalid config for %v; must specify a project"
,
shortName
)
glog
.
Fatalf
(
"Invalid config for %v; must specify a project"
,
shortName
)
}
}
}
}
if
len
(
gceImages
.
I
mages
)
!=
0
{
if
len
(
gceImages
.
i
mages
)
!=
0
{
if
*
project
==
""
{
if
*
project
==
""
{
glog
.
Fatal
(
"Must specify --project flag to launch images into"
)
glog
.
Fatal
(
"Must specify --project flag to launch images into"
)
}
}
...
@@ -170,12 +192,13 @@ func main() {
...
@@ -170,12 +192,13 @@ func main() {
results
:=
make
(
chan
*
TestResult
)
results
:=
make
(
chan
*
TestResult
)
running
:=
0
running
:=
0
for
shortName
,
image
:=
range
gceImages
.
Images
{
for
shortName
:=
range
gceImages
.
images
{
imageConfig
:=
gceImages
.
images
[
shortName
]
running
++
running
++
fmt
.
Printf
(
"Initializing e2e tests using image %s.
\n
"
,
shortName
)
fmt
.
Printf
(
"Initializing e2e tests using image %s.
\n
"
,
shortName
)
go
func
(
image
,
imageProject
string
,
junitFileNum
int
)
{
go
func
(
image
*
internalGCEImage
,
junitFileNum
int
)
{
results
<-
testImage
(
image
,
imageProject
,
junitFileNum
)
results
<-
testImage
(
image
,
junitFileNum
)
}(
image
.
Image
,
image
.
Project
,
running
)
}(
&
imageConfig
,
running
)
}
}
if
*
hosts
!=
""
{
if
*
hosts
!=
""
{
for
_
,
host
:=
range
strings
.
Split
(
*
hosts
,
","
)
{
for
_
,
host
:=
range
strings
.
Split
(
*
hosts
,
","
)
{
...
@@ -224,6 +247,25 @@ func (a *Archive) deleteArchive() {
...
@@ -224,6 +247,25 @@ func (a *Archive) deleteArchive() {
os
.
Remove
(
path
)
os
.
Remove
(
path
)
}
}
func
getImageMetadata
(
input
string
)
*
compute
.
Metadata
{
if
input
==
""
{
return
nil
}
glog
.
V
(
3
)
.
Infof
(
"parsing instance metadata: %q"
,
input
)
raw
:=
parseInstanceMetadata
(
input
)
glog
.
V
(
4
)
.
Infof
(
"parsed instance metadata: %v"
,
raw
)
metadataItems
:=
[]
*
compute
.
MetadataItems
{}
for
k
,
v
:=
range
raw
{
val
:=
v
metadataItems
=
append
(
metadataItems
,
&
compute
.
MetadataItems
{
Key
:
k
,
Value
:
&
val
,
})
}
ret
:=
compute
.
Metadata
{
Items
:
metadataItems
}
return
&
ret
}
// Run tests in archive against host
// Run tests in archive against host
func
testHost
(
host
string
,
deleteFiles
bool
,
junitFileNum
int
,
setupNode
bool
)
*
TestResult
{
func
testHost
(
host
string
,
deleteFiles
bool
,
junitFileNum
int
,
setupNode
bool
)
*
TestResult
{
instance
,
err
:=
computeService
.
Instances
.
Get
(
*
project
,
*
zone
,
host
)
.
Do
()
instance
,
err
:=
computeService
.
Instances
.
Get
(
*
project
,
*
zone
,
host
)
.
Do
()
...
@@ -266,14 +308,14 @@ func testHost(host string, deleteFiles bool, junitFileNum int, setupNode bool) *
...
@@ -266,14 +308,14 @@ func testHost(host string, deleteFiles bool, junitFileNum int, setupNode bool) *
// Provision a gce instance using image and run the tests in archive against the instance.
// Provision a gce instance using image and run the tests in archive against the instance.
// Delete the instance afterward.
// Delete the instance afterward.
func
testImage
(
image
,
imageProject
string
,
junitFileNum
int
)
*
TestResult
{
func
testImage
(
image
*
internalGCEImage
,
junitFileNum
int
)
*
TestResult
{
host
,
err
:=
createInstance
(
image
,
imageProject
)
host
,
err
:=
createInstance
(
image
)
if
*
deleteInstances
{
if
*
deleteInstances
{
defer
deleteInstance
(
image
)
defer
deleteInstance
(
image
.
image
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
&
TestResult
{
return
&
TestResult
{
err
:
fmt
.
Errorf
(
"unable to create gce instance with running docker daemon for image %s. %v"
,
image
,
err
),
err
:
fmt
.
Errorf
(
"unable to create gce instance with running docker daemon for image %s. %v"
,
image
.
image
,
err
),
}
}
}
}
...
@@ -284,8 +326,8 @@ func testImage(image, imageProject string, junitFileNum int) *TestResult {
...
@@ -284,8 +326,8 @@ func testImage(image, imageProject string, junitFileNum int) *TestResult {
}
}
// Provision a gce instance using image
// Provision a gce instance using image
func
createInstance
(
image
,
imageProject
string
)
(
string
,
error
)
{
func
createInstance
(
image
*
internalGCEImage
)
(
string
,
error
)
{
name
:=
imageToInstanceName
(
image
)
name
:=
imageToInstanceName
(
image
.
image
)
i
:=
&
compute
.
Instance
{
i
:=
&
compute
.
Instance
{
Name
:
name
,
Name
:
name
,
MachineType
:
machineType
(),
MachineType
:
machineType
(),
...
@@ -304,26 +346,12 @@ func createInstance(image, imageProject string) (string, error) {
...
@@ -304,26 +346,12 @@ func createInstance(image, imageProject string) (string, error) {
Boot
:
true
,
Boot
:
true
,
Type
:
"PERSISTENT"
,
Type
:
"PERSISTENT"
,
InitializeParams
:
&
compute
.
AttachedDiskInitializeParams
{
InitializeParams
:
&
compute
.
AttachedDiskInitializeParams
{
SourceImage
:
sourceImage
(
image
,
imageP
roject
),
SourceImage
:
sourceImage
(
image
.
image
,
image
.
p
roject
),
},
},
},
},
},
},
}
}
if
*
instanceMetadata
!=
""
{
i
.
Metadata
=
image
.
metadata
glog
.
V
(
2
)
.
Infof
(
"parsing instance metadata: %q"
,
*
instanceMetadata
)
raw
:=
parseInstanceMetadata
(
*
instanceMetadata
)
glog
.
V
(
3
)
.
Infof
(
"parsed instance metadata: %v"
,
raw
)
i
.
Metadata
=
&
compute
.
Metadata
{}
metadata
:=
[]
*
compute
.
MetadataItems
{}
for
k
,
v
:=
range
raw
{
val
:=
v
metadata
=
append
(
metadata
,
&
compute
.
MetadataItems
{
Key
:
k
,
Value
:
&
val
,
})
}
i
.
Metadata
.
Items
=
metadata
}
op
,
err
:=
computeService
.
Instances
.
Insert
(
*
project
,
*
zone
,
i
)
.
Do
()
op
,
err
:=
computeService
.
Instances
.
Insert
(
*
project
,
*
zone
,
i
)
.
Do
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
...
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