rollingupdate should use explicit casting

It needs both internal and versioned - use the new helpers to detect
that
This commit is contained in:
Clayton Coleman
2017-11-17 17:21:25 -05:00
parent 8f4b6c8771
commit 09b64d36d2

View File

@@ -201,39 +201,35 @@ func RunRollingUpdate(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
}
request := f.NewBuilder().
Internal().
Unstructured().
Schema(schema).
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(enforceNamespace, &resource.FilenameOptions{Recursive: false, Filenames: []string{filename}}).
Flatten().
Do()
obj, err := request.Object()
infos, err := request.Infos()
if err != nil {
return err
}
var ok bool
// Handle filename input from stdin. The resource builder always returns an api.List
// when creating resource(s) from a stream.
if list, ok := obj.(*v1.List); ok {
if len(list.Items) > 1 {
// Handle filename input from stdin.
if len(infos) > 1 {
return cmdutil.UsageErrorf(cmd, "%s specifies multiple items", filename)
}
if len(list.Items) == 0 {
if len(infos) == 0 {
return cmdutil.UsageErrorf(cmd, "please make sure %s exists and is not empty", filename)
}
obj = list.Items[0].Object
switch t := infos[0].AsVersioned().(type) {
case *v1.ReplicationController:
replicasDefaulted = t.Spec.Replicas == nil
newRc, _ = infos[0].AsInternal().(*api.ReplicationController)
}
newRc, ok = obj.(*api.ReplicationController)
if !ok {
glog.V(4).Infof("Object %T is not a ReplicationController", obj)
return cmdutil.UsageErrorf(cmd, "%s contains a %v not a ReplicationController", filename, obj.GetObjectKind().GroupVersionKind())
}
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 newRc == nil {
glog.V(4).Infof("Object %T is not a ReplicationController", infos[0].Object)
return cmdutil.UsageErrorf(cmd, "%s contains a %v not a ReplicationController", filename, infos[0].Object.GetObjectKind().GroupVersionKind())
}
}
// 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, with a suffix to provide uniqueness for
// same-image updates.
@@ -391,15 +387,3 @@ func findNewName(args []string, oldRc *api.ReplicationController) string {
}
return ""
}
func isReplicasDefaulted(info *resource.Info) bool {
if info == nil {
// was unable to recover versioned info
return false
}
switch t := info.AsVersioned().(type) {
case *v1.ReplicationController:
return t.Spec.Replicas == nil
}
return false
}