mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
rollingupdate should use explicit casting
It needs both internal and versioned - use the new helpers to detect that
This commit is contained in:
@@ -201,39 +201,35 @@ func RunRollingUpdate(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
|
|||||||
}
|
}
|
||||||
|
|
||||||
request := f.NewBuilder().
|
request := f.NewBuilder().
|
||||||
Internal().
|
Unstructured().
|
||||||
Schema(schema).
|
Schema(schema).
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||||
FilenameParam(enforceNamespace, &resource.FilenameOptions{Recursive: false, Filenames: []string{filename}}).
|
FilenameParam(enforceNamespace, &resource.FilenameOptions{Recursive: false, Filenames: []string{filename}}).
|
||||||
|
Flatten().
|
||||||
Do()
|
Do()
|
||||||
obj, err := request.Object()
|
infos, err := request.Infos()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var ok bool
|
// Handle filename input from stdin.
|
||||||
// Handle filename input from stdin. The resource builder always returns an api.List
|
if len(infos) > 1 {
|
||||||
// when creating resource(s) from a stream.
|
|
||||||
if list, ok := obj.(*v1.List); ok {
|
|
||||||
if len(list.Items) > 1 {
|
|
||||||
return cmdutil.UsageErrorf(cmd, "%s specifies multiple items", filename)
|
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)
|
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 newRc == nil {
|
||||||
if !ok {
|
glog.V(4).Infof("Object %T is not a ReplicationController", infos[0].Object)
|
||||||
glog.V(4).Infof("Object %T is not a ReplicationController", obj)
|
return cmdutil.UsageErrorf(cmd, "%s contains a %v not a ReplicationController", filename, infos[0].Object.GetObjectKind().GroupVersionKind())
|
||||||
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 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, with a suffix to provide uniqueness for
|
// than the old rc. This selector is the hash of the rc, with a suffix to provide uniqueness for
|
||||||
// same-image updates.
|
// same-image updates.
|
||||||
@@ -391,15 +387,3 @@ func findNewName(args []string, oldRc *api.ReplicationController) string {
|
|||||||
}
|
}
|
||||||
return ""
|
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
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user