當前位置: 首頁>>代碼示例>>Golang>>正文


Golang kubectl.LoadExistingNextReplicationController函數代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/kubectl.LoadExistingNextReplicationController函數的典型用法代碼示例。如果您正苦於以下問題:Golang LoadExistingNextReplicationController函數的具體用法?Golang LoadExistingNextReplicationController怎麽用?Golang LoadExistingNextReplicationController使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了LoadExistingNextReplicationController函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RunRollingUpdate

func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
    if len(os.Args) > 1 && os.Args[1] == "rollingupdate" {
        printDeprecationWarning("rolling-update", "rollingupdate")
    }
    deploymentKey, filename, image, oldName, err := validateArguments(cmd, args)
    if err != nil {
        return err
    }
    period := cmdutil.GetFlagDuration(cmd, "update-period")
    interval := cmdutil.GetFlagDuration(cmd, "poll-interval")
    timeout := cmdutil.GetFlagDuration(cmd, "timeout")
    dryrun := cmdutil.GetFlagBool(cmd, "dry-run")

    cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
    if err != nil {
        return err
    }

    client, err := f.Client()
    if err != nil {
        return err
    }

    updaterClient := kubectl.NewRollingUpdaterClient(client)

    var newRc *api.ReplicationController
    // fetch rc
    oldRc, err := client.ReplicationControllers(cmdNamespace).Get(oldName)
    if err != nil {
        if !errors.IsNotFound(err) || len(image) == 0 || len(args) > 1 {
            return err
        }
        // We're in the middle of a rename, look for an RC with a source annotation of oldName
        newRc, err := kubectl.FindSourceController(updaterClient, cmdNamespace, oldName)
        if err != nil {
            return err
        }
        return kubectl.Rename(kubectl.NewRollingUpdaterClient(client), newRc, oldName)
    }

    var keepOldName bool
    var replicasDefaulted bool

    mapper, typer := f.Object()

    if len(filename) != 0 {
        schema, err := f.Validator()
        if err != nil {
            return err
        }

        request := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
            Schema(schema).
            NamespaceParam(cmdNamespace).DefaultNamespace().
            FilenameParam(enforceNamespace, filename).
            Do()
        obj, err := request.Object()
        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.(*api.List); ok {
            if len(list.Items) > 1 {
                return cmdutil.UsageError(cmd, "%s specifies multiple items", filename)
            }
            obj = list.Items[0]
        }
        newRc, ok = obj.(*api.ReplicationController)
        if !ok {
            if _, kind, err := typer.ObjectVersionAndKind(obj); err == nil {
                return cmdutil.UsageError(cmd, "%s contains a %s not a ReplicationController", filename, kind)
            }
            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
    // different image.
    if len(image) != 0 {
        keepOldName = len(args) == 1
        newName := findNewName(args, oldRc)
        if newRc, err = kubectl.LoadExistingNextReplicationController(client, cmdNamespace, newName); err != nil {
            return err
        }
        if newRc != nil {
            fmt.Fprintf(out, "Found existing update in progress (%s), resuming.\n", newRc.Name)
        } else {
            newRc, err = kubectl.CreateNewControllerFromCurrentController(client, cmdNamespace, oldName, newName, image, deploymentKey)
            if err != nil {
                return err
            }
//.........這裏部分代碼省略.........
開發者ID:ngbinh,項目名稱:kubernetes,代碼行數:101,代碼來源:rollingupdate.go

示例2: RunRollingUpdate


//.........這裏部分代碼省略.........
            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.(*api.List); ok {
            if len(list.Items) > 1 {
                return cmdutil.UsageError(cmd, "%s specifies multiple items", filename)
            }
            obj = list.Items[0]
        }
        newRc, ok = obj.(*api.ReplicationController)
        if !ok {
            if gvk, err := typer.ObjectKind(obj); err == nil {
                return cmdutil.UsageError(cmd, "%s contains a %v not a ReplicationController", filename, gvk)
            }
            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, with a suffix to provide uniqueness for
    // same-image updates.
    if len(image) != 0 {
        codec := api.Codecs.LegacyCodec(client.APIVersion())
        keepOldName = len(args) == 1
        newName := findNewName(args, oldRc)
        if newRc, err = kubectl.LoadExistingNextReplicationController(client, cmdNamespace, newName); err != nil {
            return err
        }
        if newRc != nil {
            if inProgressImage := newRc.Spec.Template.Spec.Containers[0].Image; inProgressImage != image {
                return cmdutil.UsageError(cmd, "Found existing in-progress update to image (%s).\nEither continue in-progress update with --image=%s or rollback with --rollback", inProgressImage, inProgressImage)
            }
            fmt.Fprintf(out, "Found existing update in progress (%s), resuming.\n", newRc.Name)
        } else {
            config := &kubectl.NewControllerConfig{
                Namespace:     cmdNamespace,
                OldName:       oldName,
                NewName:       newName,
                Image:         image,
                Container:     container,
                DeploymentKey: deploymentKey,
            }
            if oldRc.Spec.Template.Spec.Containers[0].Image == image {
                if len(pullPolicy) == 0 {
                    return cmdutil.UsageError(cmd, "--image-pull-policy (Always|Never|IfNotPresent) must be provided when --image is the same as existing container image")
                }
                config.PullPolicy = api.PullPolicy(pullPolicy)
            }
            newRc, err = kubectl.CreateNewControllerFromCurrentController(client, codec, config)
            if err != nil {
                return err
            }
        }
        // Update the existing replication controller with pointers to the 'next' controller
        // and adding the <deploymentKey> label if necessary to distinguish it from the 'next' controller.
        oldHash, err := api.HashObject(oldRc, codec)
        if err != nil {
            return err
開發者ID:sgallagher,項目名稱:origin,代碼行數:67,代碼來源:rollingupdate.go


注:本文中的k8s/io/kubernetes/pkg/kubectl.LoadExistingNextReplicationController函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。