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


Golang validation.ValidateScale函數代碼示例

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


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

示例1: Update

func (r *ScaleREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
    if obj == nil {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("nil update passed to Scale"))
    }
    scale, ok := obj.(*extensions.Scale)
    if !ok {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj))
    }

    if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
        return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs)
    }

    rs, err := r.registry.GetReplicaSet(ctx, scale.Name)
    if err != nil {
        return nil, false, errors.NewNotFound(extensions.Resource("replicasets/scale"), scale.Name)
    }
    rs.Spec.Replicas = scale.Spec.Replicas
    rs.ResourceVersion = scale.ResourceVersion
    rs, err = r.registry.UpdateReplicaSet(ctx, rs)
    if err != nil {
        return nil, false, err
    }
    newScale, err := scaleFromReplicaSet(rs)
    if err != nil {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("%v", err))
    }
    return newScale, false, err
}
開發者ID:ysh7,項目名稱:kubernetes,代碼行數:29,代碼來源:etcd.go

示例2: Update

func (r *ScaleREST) Update(ctx api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
    rc, err := (*r.registry).GetController(ctx, name)
    if err != nil {
        return nil, false, errors.NewNotFound(extensions.Resource("replicationcontrollers/scale"), name)
    }
    oldScale := scaleFromRC(rc)

    obj, err := objInfo.UpdatedObject(ctx, oldScale)

    if obj == nil {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("nil update passed to Scale"))
    }
    scale, ok := obj.(*extensions.Scale)
    if !ok {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj))
    }

    if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
        return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs)
    }

    rc.Spec.Replicas = scale.Spec.Replicas
    rc.ResourceVersion = scale.ResourceVersion
    rc, err = (*r.registry).UpdateController(ctx, rc)
    if err != nil {
        return nil, false, errors.NewConflict(extensions.Resource("replicationcontrollers/scale"), scale.Name, err)
    }
    return scaleFromRC(rc), false, nil
}
開發者ID:humblec,項目名稱:kubernetes,代碼行數:29,代碼來源:etcd.go

示例3: Update

func (r *ScaleREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
    if obj == nil {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("nil update passed to Scale"))
    }
    scale, ok := obj.(*extensions.Scale)
    if !ok {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("expected input object type to be Scale, but %T", obj))
    }

    if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
        return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs)
    }

    deployment, err := r.registry.GetDeployment(ctx, scale.Name)
    if err != nil {
        return nil, false, errors.NewNotFound(extensions.Resource("deployments/scale"), scale.Name)
    }
    deployment.Spec.Replicas = scale.Spec.Replicas
    deployment.ResourceVersion = scale.ResourceVersion
    deployment, err = r.registry.UpdateDeployment(ctx, deployment)
    if err != nil {
        return nil, false, err
    }
    newScale, err := scaleFromDeployment(deployment)
    if err != nil {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("%v", err))
    }
    return newScale, false, nil
}
開發者ID:ysh7,項目名稱:kubernetes,代碼行數:29,代碼來源:etcd.go

示例4: Update

// Update scales the DeploymentConfig for the given Scale subresource, returning the updated Scale.
func (r *ScaleREST) Update(ctx kapi.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
    deploymentConfig, err := r.registry.GetDeploymentConfig(ctx, name)
    if err != nil {
        return nil, false, errors.NewNotFound(extensions.Resource("scale"), name)
    }

    old := api.ScaleFromConfig(deploymentConfig)
    obj, err := objInfo.UpdatedObject(ctx, old)
    if err != nil {
        return nil, false, err
    }

    scale, ok := obj.(*extensions.Scale)
    if !ok {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj))
    }

    if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
        return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs)
    }

    deploymentConfig.Spec.Replicas = scale.Spec.Replicas
    if err := r.registry.UpdateDeploymentConfig(ctx, deploymentConfig); err != nil {
        return nil, false, err
    }

    return scale, false, nil
}
開發者ID:xgwang-zte,項目名稱:origin,代碼行數:29,代碼來源:etcd.go

示例5: Update

// Update scales the DeploymentConfig for the given Scale subresource, returning the updated Scale.
func (r *ScaleREST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
    if obj == nil {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("nil update passed to Scale"))
    }
    scale, ok := obj.(*extensions.Scale)
    if !ok {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj))
    }

    if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
        return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs)
    }

    deploymentConfig, err := r.registry.GetDeploymentConfig(ctx, scale.Name)
    if err != nil {
        return nil, false, errors.NewNotFound(extensions.Resource("scale"), scale.Name)
    }

    scaleRet := &extensions.Scale{
        ObjectMeta: kapi.ObjectMeta{
            Name:              deploymentConfig.Name,
            Namespace:         deploymentConfig.Namespace,
            CreationTimestamp: deploymentConfig.CreationTimestamp,
        },
        Spec: extensions.ScaleSpec{
            Replicas: scale.Spec.Replicas,
        },
        Status: extensions.ScaleStatus{
            Selector: &unversioned.LabelSelector{MatchLabels: deploymentConfig.Spec.Selector},
        },
    }

    // TODO(directxman12): this is going to be a bit out of sync, since we are calculating it
    // here and not as part of the deploymentconfig loop -- is there a better way of doing it?
    totalReplicas, err := r.replicasForDeploymentConfig(deploymentConfig.Namespace, deploymentConfig.Name)
    if err != nil {
        return nil, false, err
    }

    oldReplicas := deploymentConfig.Spec.Replicas
    deploymentConfig.Spec.Replicas = scale.Spec.Replicas
    if err := r.registry.UpdateDeploymentConfig(ctx, deploymentConfig); err != nil {
        return nil, false, err
    }
    scaleRet.Status.Replicas = totalReplicas + (scale.Spec.Replicas - oldReplicas)

    return scaleRet, false, nil
}
開發者ID:sgallagher,項目名稱:origin,代碼行數:49,代碼來源:etcd.go

示例6: Update

func (r *ScaleREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
    if obj == nil {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("nil update passed to Scale"))
    }
    scale, ok := obj.(*extensions.Scale)
    if !ok {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj))
    }

    if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
        return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs)
    }

    rc, err := (*r.registry).GetController(ctx, scale.Name)
    if err != nil {
        return nil, false, errors.NewNotFound(extensions.Resource("replicationcontrollers/scale"), scale.Name)
    }
    rc.Spec.Replicas = scale.Spec.Replicas
    rc, err = (*r.registry).UpdateController(ctx, rc)
    if err != nil {
        return nil, false, errors.NewConflict(extensions.Resource("replicationcontrollers/scale"), scale.Name, err)
    }
    return &extensions.Scale{
        ObjectMeta: api.ObjectMeta{
            Name:              rc.Name,
            Namespace:         rc.Namespace,
            CreationTimestamp: rc.CreationTimestamp,
        },
        Spec: extensions.ScaleSpec{
            Replicas: rc.Spec.Replicas,
        },
        Status: extensions.ScaleStatus{
            Replicas: rc.Status.Replicas,
            Selector: rc.Spec.Selector,
        },
    }, false, nil
}
開發者ID:mataihang,項目名稱:kubernetes,代碼行數:37,代碼來源:etcd.go

示例7: Update

func (r *ScaleREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
    if obj == nil {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("nil update passed to Scale"))
    }
    scale, ok := obj.(*extensions.Scale)
    if !ok {
        return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj))
    }

    if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
        return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs)
    }

    deployment, err := (*r.registry).GetDeployment(ctx, scale.Name)
    if err != nil {
        return nil, false, errors.NewNotFound(extensions.Resource("deployments/scale"), scale.Name)
    }
    deployment.Spec.Replicas = scale.Spec.Replicas
    deployment, err = (*r.registry).UpdateDeployment(ctx, deployment)
    if err != nil {
        return nil, false, errors.NewConflict(extensions.Resource("deployments/scale"), scale.Name, err)
    }
    return extensions.ScaleFromDeployment(deployment), false, nil
}
開發者ID:emmanuel,項目名稱:kubernetes,代碼行數:24,代碼來源:etcd.go


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