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


Golang kubectl.SortableResourceNames函數代碼示例

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


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

示例1: DescribeClusterQuota

func DescribeClusterQuota(quota *quotaapi.ClusterResourceQuota) (string, error) {
    labelSelector, err := unversioned.LabelSelectorAsSelector(quota.Spec.Selector.LabelSelector)
    if err != nil {
        return "", err
    }

    return tabbedString(func(out *tabwriter.Writer) error {
        formatMeta(out, quota.ObjectMeta)
        fmt.Fprintf(out, "Label Selector: %s\n", labelSelector)
        fmt.Fprintf(out, "AnnotationSelector: %s\n", quota.Spec.Selector.AnnotationSelector)
        if len(quota.Spec.Quota.Scopes) > 0 {
            scopes := []string{}
            for _, scope := range quota.Spec.Quota.Scopes {
                scopes = append(scopes, string(scope))
            }
            sort.Strings(scopes)
            fmt.Fprintf(out, "Scopes:\t%s\n", strings.Join(scopes, ", "))
        }
        fmt.Fprintf(out, "Resource\tUsed\tHard\n")
        fmt.Fprintf(out, "--------\t----\t----\n")

        resources := []kapi.ResourceName{}
        for resource := range quota.Status.Total.Hard {
            resources = append(resources, resource)
        }
        sort.Sort(kctl.SortableResourceNames(resources))

        msg := "%v\t%v\t%v\n"
        for i := range resources {
            resource := resources[i]
            hardQuantity := quota.Status.Total.Hard[resource]
            usedQuantity := quota.Status.Total.Used[resource]
            fmt.Fprintf(out, msg, resource, usedQuantity.String(), hardQuantity.String())
        }
        return nil
    })
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:37,代碼來源:describer.go

示例2: Describe

// Describe returns the description of a project
func (d *ProjectDescriber) Describe(namespace, name string) (string, error) {
    projectsClient := d.osClient.Projects()
    project, err := projectsClient.Get(name)
    if err != nil {
        return "", err
    }
    resourceQuotasClient := d.kubeClient.ResourceQuotas(name)
    resourceQuotaList, err := resourceQuotasClient.List(labels.Everything())
    if err != nil {
        return "", err
    }
    limitRangesClient := d.kubeClient.LimitRanges(name)
    limitRangeList, err := limitRangesClient.List(labels.Everything())
    if err != nil {
        return "", err
    }

    nodeSelector := ""
    if len(project.ObjectMeta.Annotations) > 0 {
        if ns, ok := project.ObjectMeta.Annotations[projectapi.ProjectNodeSelector]; ok {
            nodeSelector = ns
        }
    }

    return tabbedString(func(out *tabwriter.Writer) error {
        formatMeta(out, project.ObjectMeta)
        formatString(out, "Display Name", project.Annotations[projectapi.ProjectDisplayName])
        formatString(out, "Description", project.Annotations[projectapi.ProjectDescription])
        formatString(out, "Status", project.Status.Phase)
        formatString(out, "Node Selector", nodeSelector)
        fmt.Fprintf(out, "\n")
        if len(resourceQuotaList.Items) == 0 {
            formatString(out, "Quota", "")
        } else {
            fmt.Fprintf(out, "Quota:\n")
            for i := range resourceQuotaList.Items {
                resourceQuota := &resourceQuotaList.Items[i]
                fmt.Fprintf(out, "\tName:\t%s\n", resourceQuota.Name)
                fmt.Fprintf(out, "\tResource\tUsed\tHard\n")
                fmt.Fprintf(out, "\t--------\t----\t----\n")

                resources := []kapi.ResourceName{}
                for resource := range resourceQuota.Status.Hard {
                    resources = append(resources, resource)
                }
                sort.Sort(kctl.SortableResourceNames(resources))

                msg := "\t%v\t%v\t%v\n"
                for i := range resources {
                    resource := resources[i]
                    hardQuantity := resourceQuota.Status.Hard[resource]
                    usedQuantity := resourceQuota.Status.Used[resource]
                    fmt.Fprintf(out, msg, resource, usedQuantity.String(), hardQuantity.String())
                }
            }
        }
        fmt.Fprintf(out, "\n")
        if len(limitRangeList.Items) == 0 {
            formatString(out, "Resource limits", "")
        } else {
            fmt.Fprintf(out, "Resource limits:\n")
            for i := range limitRangeList.Items {
                limitRange := &limitRangeList.Items[i]
                fmt.Fprintf(out, "\tName:\t%s\n", limitRange.Name)
                fmt.Fprintf(out, "\tType\tResource\tMin\tMax\tDefault\n")
                fmt.Fprintf(out, "\t----\t--------\t---\t---\t---\n")
                for i := range limitRange.Spec.Limits {
                    item := limitRange.Spec.Limits[i]
                    maxResources := item.Max
                    minResources := item.Min
                    defaultResources := item.Default

                    set := map[kapi.ResourceName]bool{}
                    for k := range maxResources {
                        set[k] = true
                    }
                    for k := range minResources {
                        set[k] = true
                    }
                    for k := range defaultResources {
                        set[k] = true
                    }

                    for k := range set {
                        // if no value is set, we output -
                        maxValue := "-"
                        minValue := "-"
                        defaultValue := "-"

                        maxQuantity, maxQuantityFound := maxResources[k]
                        if maxQuantityFound {
                            maxValue = maxQuantity.String()
                        }

                        minQuantity, minQuantityFound := minResources[k]
                        if minQuantityFound {
                            minValue = minQuantity.String()
                        }

//.........這裏部分代碼省略.........
開發者ID:dctse,項目名稱:openshift-cucumber,代碼行數:101,代碼來源:describer.go


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