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
737b3277
Commit
737b3277
authored
Sep 20, 2016
by
Michal Fojtik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ResolveImage function to CLI factory
parent
98c4c73c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
17 deletions
+46
-17
set_image.go
pkg/kubectl/cmd/set/set_image.go
+34
-17
fake.go
pkg/kubectl/cmd/testing/fake.go
+4
-0
factory.go
pkg/kubectl/cmd/util/factory.go
+8
-0
No files found.
pkg/kubectl/cmd/set/set_image.go
View file @
737b3277
...
@@ -35,21 +35,22 @@ import (
...
@@ -35,21 +35,22 @@ import (
type
ImageOptions
struct
{
type
ImageOptions
struct
{
resource
.
FilenameOptions
resource
.
FilenameOptions
Mapper
meta
.
RESTMapper
Mapper
meta
.
RESTMapper
Typer
runtime
.
ObjectTyper
Typer
runtime
.
ObjectTyper
Infos
[]
*
resource
.
Info
Infos
[]
*
resource
.
Info
Encoder
runtime
.
Encoder
Encoder
runtime
.
Encoder
Selector
string
Selector
string
Out
io
.
Writer
Out
io
.
Writer
Err
io
.
Writer
Err
io
.
Writer
DryRun
bool
DryRun
bool
ShortOutput
bool
ShortOutput
bool
All
bool
All
bool
Record
bool
Record
bool
Output
string
Output
string
ChangeCause
string
ChangeCause
string
Local
bool
Local
bool
Cmd
*
cobra
.
Command
Cmd
*
cobra
.
Command
ResolveImage
func
(
in
string
)
(
string
,
error
)
PrintObject
func
(
cmd
*
cobra
.
Command
,
mapper
meta
.
RESTMapper
,
obj
runtime
.
Object
,
out
io
.
Writer
)
error
PrintObject
func
(
cmd
*
cobra
.
Command
,
mapper
meta
.
RESTMapper
,
obj
runtime
.
Object
,
out
io
.
Writer
)
error
UpdatePodSpecForObject
func
(
obj
runtime
.
Object
,
fn
func
(
*
api
.
PodSpec
)
error
)
(
bool
,
error
)
UpdatePodSpecForObject
func
(
obj
runtime
.
Object
,
fn
func
(
*
api
.
PodSpec
)
error
)
(
bool
,
error
)
...
@@ -120,6 +121,7 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
...
@@ -120,6 +121,7 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
o
.
PrintObject
=
f
.
PrintObject
o
.
PrintObject
=
f
.
PrintObject
o
.
DryRun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
DryRun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
Output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
Output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
ResolveImage
=
f
.
ResolveImage
o
.
Cmd
=
cmd
o
.
Cmd
=
cmd
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
...
@@ -171,12 +173,27 @@ func (o *ImageOptions) Run() error {
...
@@ -171,12 +173,27 @@ func (o *ImageOptions) Run() error {
transformed
:=
false
transformed
:=
false
_
,
err
:=
o
.
UpdatePodSpecForObject
(
info
.
Object
,
func
(
spec
*
api
.
PodSpec
)
error
{
_
,
err
:=
o
.
UpdatePodSpecForObject
(
info
.
Object
,
func
(
spec
*
api
.
PodSpec
)
error
{
for
name
,
image
:=
range
o
.
ContainerImages
{
for
name
,
image
:=
range
o
.
ContainerImages
{
containerFound
:=
false
var
(
containerFound
bool
err
error
resolved
string
)
// Find the container to update, and update its image
// Find the container to update, and update its image
for
i
,
c
:=
range
spec
.
Containers
{
for
i
,
c
:=
range
spec
.
Containers
{
if
c
.
Name
==
name
||
name
==
"*"
{
if
c
.
Name
==
name
||
name
==
"*"
{
spec
.
Containers
[
i
]
.
Image
=
image
containerFound
=
true
containerFound
=
true
if
len
(
resolved
)
==
0
{
if
resolved
,
err
=
o
.
ResolveImage
(
image
);
err
!=
nil
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"error: unable to resolve image %q for container %q: %v"
,
image
,
name
,
err
))
// Do not loop again if the image resolving failed for wildcard case as we
// will report the same error again for the next container.
if
name
==
"*"
{
break
}
continue
}
}
spec
.
Containers
[
i
]
.
Image
=
resolved
// Perform updates
// Perform updates
transformed
=
true
transformed
=
true
}
}
...
...
pkg/kubectl/cmd/testing/fake.go
View file @
737b3277
...
@@ -293,6 +293,10 @@ func (f *FakeFactory) Resumer(info *resource.Info) (bool, error) {
...
@@ -293,6 +293,10 @@ func (f *FakeFactory) Resumer(info *resource.Info) (bool, error) {
return
false
,
nil
return
false
,
nil
}
}
func
(
f
*
FakeFactory
)
ResolveImage
(
name
string
)
(
string
,
error
)
{
return
name
,
nil
}
func
(
f
*
FakeFactory
)
Validator
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
func
(
f
*
FakeFactory
)
Validator
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
return
f
.
tf
.
Validator
,
f
.
tf
.
Err
return
f
.
tf
.
Validator
,
f
.
tf
.
Err
}
}
...
...
pkg/kubectl/cmd/util/factory.go
View file @
737b3277
...
@@ -135,6 +135,10 @@ type Factory interface {
...
@@ -135,6 +135,10 @@ type Factory interface {
Pauser
(
info
*
resource
.
Info
)
(
bool
,
error
)
Pauser
(
info
*
resource
.
Info
)
(
bool
,
error
)
// Resumer resumes a paused object inside the info ie. it will be reconciled by its controller.
// Resumer resumes a paused object inside the info ie. it will be reconciled by its controller.
Resumer
(
info
*
resource
.
Info
)
(
bool
,
error
)
Resumer
(
info
*
resource
.
Info
)
(
bool
,
error
)
// ResolveImage resolves the image names. For kubernetes this function is just
// passthrough but it allows to perform more sophisticated image name resolving for
// third-party vendors.
ResolveImage
(
imageName
string
)
(
string
,
error
)
// Returns a schema that can validate objects stored on disk.
// Returns a schema that can validate objects stored on disk.
Validator
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
Validator
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
// SwaggerSchema returns the schema declaration for the provided group version kind.
// SwaggerSchema returns the schema declaration for the provided group version kind.
...
@@ -654,6 +658,10 @@ func (f *factory) Pauser(info *resource.Info) (bool, error) {
...
@@ -654,6 +658,10 @@ func (f *factory) Pauser(info *resource.Info) (bool, error) {
}
}
}
}
func
(
f
*
factory
)
ResolveImage
(
name
string
)
(
string
,
error
)
{
return
name
,
nil
}
func
(
f
*
factory
)
Resumer
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
func
(
f
*
factory
)
Resumer
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
switch
obj
:=
info
.
Object
.
(
type
)
{
switch
obj
:=
info
.
Object
.
(
type
)
{
case
*
extensions
.
Deployment
:
case
*
extensions
.
Deployment
:
...
...
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