make rolling update check if the replication controller has been defaulted

This commit is contained in:
Mike Danese
2015-06-22 18:56:53 -07:00
parent f79736d767
commit 0c8f71aa0b
3 changed files with 48 additions and 10 deletions

View File

@@ -26,6 +26,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"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"
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"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 replicasDefaulted bool
mapper, typer := f.Object()
@@ -151,12 +154,12 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
if err != nil {
return err
}
obj, err := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
request := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
Schema(schema).
NamespaceParam(cmdNamespace).RequireNamespace().
FilenameParam(filename).
Do().
Object()
Do()
obj, err := request.Object()
if err != nil {
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)
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
// 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)
}
// TODO: handle scales during rolling update
if newRc.Spec.Replicas == 0 {
if replicasDefaulted {
newRc.Spec.Replicas = oldRc.Spec.Replicas
}
if dryrun {
@@ -283,3 +292,21 @@ func findNewName(args []string, oldRc *api.ReplicationController) string {
}
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
}