mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
make rolling update check if the replication controller has been defaulted
This commit is contained in:
parent
f79736d767
commit
0c8f71aa0b
@ -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
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
|||||||
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
|
|||||||
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
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
@ -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) {
|
|||||||
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)
|
||||||
|
|
||||||
|
var versionedObject interface{}
|
||||||
|
|
||||||
|
if vo, _, _, err := api.Scheme.Raw().DecodeToVersionedObject(data); err == nil {
|
||||||
|
versionedObject = vo
|
||||||
|
}
|
||||||
return &Info{
|
return &Info{
|
||||||
Mapping: mapping,
|
Mapping: mapping,
|
||||||
Client: client,
|
Client: client,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
Source: source,
|
Source: source,
|
||||||
|
VersionedObject: versionedObject,
|
||||||
Object: obj,
|
Object: obj,
|
||||||
ResourceVersion: resourceVersion,
|
ResourceVersion: resourceVersion,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user