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
0c8f71aa
Commit
0c8f71aa
authored
Jun 22, 2015
by
Mike Danese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make rolling update check if the replication controller has been defaulted
parent
f79736d7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
10 deletions
+48
-10
rollingupdate.go
pkg/kubectl/cmd/rollingupdate.go
+31
-4
mapper.go
pkg/kubectl/resource/mapper.go
+13
-6
visitor.go
pkg/kubectl/resource/visitor.go
+4
-0
No files found.
pkg/kubectl/cmd/rollingupdate.go
View file @
0c8f71aa
...
@@ -26,6 +26,8 @@ import (
...
@@ -26,6 +26,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
...
@@ -143,6 +145,7 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
...
@@ -143,6 +145,7 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
}
}
var
keepOldName
bool
var
keepOldName
bool
var
replicasDefaulted
bool
mapper
,
typer
:=
f
.
Object
()
mapper
,
typer
:=
f
.
Object
()
...
@@ -151,12 +154,12 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
...
@@ -151,12 +154,12 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
obj
,
err
:=
resource
.
NewBuilder
(
mapper
,
typer
,
f
.
ClientMapperForCommand
())
.
request
:=
resource
.
NewBuilder
(
mapper
,
typer
,
f
.
ClientMapperForCommand
())
.
Schema
(
schema
)
.
Schema
(
schema
)
.
NamespaceParam
(
cmdNamespace
)
.
RequireNamespace
()
.
NamespaceParam
(
cmdNamespace
)
.
RequireNamespace
()
.
FilenameParam
(
filename
)
.
FilenameParam
(
filename
)
.
Do
()
.
Do
()
Object
()
obj
,
err
:=
request
.
Object
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -177,6 +180,12 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
...
@@ -177,6 +180,12 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
glog
.
V
(
4
)
.
Infof
(
"Object %#v is not a ReplicationController"
,
obj
)
glog
.
V
(
4
)
.
Infof
(
"Object %#v is not a ReplicationController"
,
obj
)
return
cmdutil
.
UsageError
(
cmd
,
"%s does not specify a valid ReplicationController"
,
filename
)
return
cmdutil
.
UsageError
(
cmd
,
"%s does not specify a valid ReplicationController"
,
filename
)
}
}
infos
,
err
:=
request
.
Infos
()
if
err
!=
nil
||
len
(
infos
)
!=
1
{
glog
.
V
(
2
)
.
Infof
(
"was not able to recover adequate information to discover if .spec.replicas was defaulted"
)
}
else
{
replicasDefaulted
=
isReplicasDefaulted
(
infos
[
0
])
}
}
}
// If the --image option is specified, we need to create a new rc with at least one different selector
// If the --image option is specified, we need to create a new rc with at least one different selector
// than the old rc. This selector is the hash of the rc, which will differ because the new rc has a
// than the old rc. This selector is the hash of the rc, which will differ because the new rc has a
...
@@ -228,7 +237,7 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
...
@@ -228,7 +237,7 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
filename
,
oldName
)
filename
,
oldName
)
}
}
// TODO: handle scales during rolling update
// TODO: handle scales during rolling update
if
newRc
.
Spec
.
Replicas
==
0
{
if
replicasDefaulted
{
newRc
.
Spec
.
Replicas
=
oldRc
.
Spec
.
Replicas
newRc
.
Spec
.
Replicas
=
oldRc
.
Spec
.
Replicas
}
}
if
dryrun
{
if
dryrun
{
...
@@ -283,3 +292,21 @@ func findNewName(args []string, oldRc *api.ReplicationController) string {
...
@@ -283,3 +292,21 @@ func findNewName(args []string, oldRc *api.ReplicationController) string {
}
}
return
""
return
""
}
}
func
isReplicasDefaulted
(
info
*
resource
.
Info
)
bool
{
if
info
==
nil
||
info
.
VersionedObject
==
nil
{
// was unable to recover versioned info
return
false
}
switch
info
.
Mapping
.
APIVersion
{
case
"v1"
:
if
rc
,
ok
:=
info
.
VersionedObject
.
(
*
v1
.
ReplicationController
);
ok
{
return
rc
.
Spec
.
Replicas
==
nil
}
case
"v1beta3"
:
if
rc
,
ok
:=
info
.
VersionedObject
.
(
*
v1beta3
.
ReplicationController
);
ok
{
return
rc
.
Spec
.
Replicas
==
nil
}
}
return
false
}
pkg/kubectl/resource/mapper.go
View file @
0c8f71aa
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"fmt"
"fmt"
"reflect"
"reflect"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/yaml"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/yaml"
...
@@ -64,13 +65,19 @@ func (m *Mapper) InfoForData(data []byte, source string) (*Info, error) {
...
@@ -64,13 +65,19 @@ func (m *Mapper) InfoForData(data []byte, source string) (*Info, error) {
name
,
_
:=
mapping
.
MetadataAccessor
.
Name
(
obj
)
name
,
_
:=
mapping
.
MetadataAccessor
.
Name
(
obj
)
namespace
,
_
:=
mapping
.
MetadataAccessor
.
Namespace
(
obj
)
namespace
,
_
:=
mapping
.
MetadataAccessor
.
Namespace
(
obj
)
resourceVersion
,
_
:=
mapping
.
MetadataAccessor
.
ResourceVersion
(
obj
)
resourceVersion
,
_
:=
mapping
.
MetadataAccessor
.
ResourceVersion
(
obj
)
return
&
Info
{
Mapping
:
mapping
,
Client
:
client
,
Namespace
:
namespace
,
Name
:
name
,
Source
:
source
,
var
versionedObject
interface
{}
if
vo
,
_
,
_
,
err
:=
api
.
Scheme
.
Raw
()
.
DecodeToVersionedObject
(
data
);
err
==
nil
{
versionedObject
=
vo
}
return
&
Info
{
Mapping
:
mapping
,
Client
:
client
,
Namespace
:
namespace
,
Name
:
name
,
Source
:
source
,
VersionedObject
:
versionedObject
,
Object
:
obj
,
Object
:
obj
,
ResourceVersion
:
resourceVersion
,
ResourceVersion
:
resourceVersion
,
},
nil
},
nil
...
...
pkg/kubectl/resource/visitor.go
View file @
0c8f71aa
...
@@ -69,6 +69,10 @@ type Info struct {
...
@@ -69,6 +69,10 @@ type Info struct {
// Optional, Source is the filename or URL to template file (.json or .yaml),
// Optional, Source is the filename or URL to template file (.json or .yaml),
// or stdin to use to handle the resource
// or stdin to use to handle the resource
Source
string
Source
string
// Optional, this is the provided object in a versioned type before defaulting
// and conversions into its corresponding internal type. This is useful for
// reflecting on user intent which may be lost after defaulting and conversions.
VersionedObject
interface
{}
// Optional, this is the most recent value returned by the server if available
// Optional, this is the most recent value returned by the server if available
runtime
.
Object
runtime
.
Object
// Optional, this is the most recent resource version the server knows about for
// Optional, this is the most recent resource version the server knows about for
...
...
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