mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Add recovery for anonymous rollouts.
This commit is contained in:
		@@ -26,6 +26,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
			
		||||
	apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
 | 
			
		||||
@@ -155,7 +156,23 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if len(image) != 0 {
 | 
			
		||||
		var newName string
 | 
			
		||||
		var err error
 | 
			
		||||
 | 
			
		||||
		if len(args) >= 2 {
 | 
			
		||||
			newName = args[1]
 | 
			
		||||
		} else {
 | 
			
		||||
			newName, _ = kubectl.GetNextControllerAnnotation(oldRc)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(newName) > 0 {
 | 
			
		||||
			newRc, err = client.ReplicationControllers(cmdNamespace).Get(newName)
 | 
			
		||||
			if err != nil && !apierrors.IsNotFound(err) {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
			fmt.Fprint(out, "Found existing update in progress (%s), resuming.\n", newName)
 | 
			
		||||
		}
 | 
			
		||||
		if newRc == nil {
 | 
			
		||||
			// load the old RC into the "new" RC
 | 
			
		||||
			if newRc, err = client.ReplicationControllers(cmdNamespace).Get(oldName); err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
@@ -175,10 +192,7 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		var newName string
 | 
			
		||||
		if len(args) >= 2 {
 | 
			
		||||
			newName = args[1]
 | 
			
		||||
		} else {
 | 
			
		||||
			if len(newName) == 0 {
 | 
			
		||||
				keepOldName = true
 | 
			
		||||
				newName = fmt.Sprintf("%s-%s", newRc.Name, newHash)
 | 
			
		||||
			}
 | 
			
		||||
@@ -189,12 +203,14 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
 | 
			
		||||
			// Clear resource version after hashing so that identical updates get different hashes.
 | 
			
		||||
			newRc.ResourceVersion = ""
 | 
			
		||||
 | 
			
		||||
			kubectl.SetNextControllerAnnotation(oldRc, newName)
 | 
			
		||||
			if _, found := oldRc.Spec.Selector[deploymentKey]; !found {
 | 
			
		||||
				if err := addDeploymentKeyToReplicationController(oldRc, client, deploymentKey, cmdNamespace, out); err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	newName := newRc.Name
 | 
			
		||||
	if oldName == newName {
 | 
			
		||||
		return cmdutil.UsageError(cmd, "%s cannot have the same name as the existing ReplicationController %s",
 | 
			
		||||
 
 | 
			
		||||
@@ -82,8 +82,21 @@ func NewRollingUpdater(namespace string, c RollingUpdaterClient) *RollingUpdater
 | 
			
		||||
const (
 | 
			
		||||
	sourceIdAnnotation        = kubectlAnnotationPrefix + "update-source-id"
 | 
			
		||||
	desiredReplicasAnnotation = kubectlAnnotationPrefix + "desired-replicas"
 | 
			
		||||
	nextControllerAnnotation  = kubectlAnnotationPrefix + "next-controller-id"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetNextControllerAnnotation(rc *api.ReplicationController) (string, bool) {
 | 
			
		||||
	res, found := rc.Annotations[nextControllerAnnotation]
 | 
			
		||||
	return res, found
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func SetNextControllerAnnotation(rc *api.ReplicationController, name string) {
 | 
			
		||||
	if rc.Annotations == nil {
 | 
			
		||||
		rc.Annotations = map[string]string{}
 | 
			
		||||
	}
 | 
			
		||||
	rc.Annotations[nextControllerAnnotation] = name
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Update all pods for a ReplicationController (oldRc) by creating a new
 | 
			
		||||
// controller (newRc) with 0 replicas, and synchronously resizing oldRc,newRc
 | 
			
		||||
// by 1 until oldRc has 0 replicas and newRc has the original # of desired
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user