本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors.NewAggregate函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAggregate函数的具体用法?Golang NewAggregate怎么用?Golang NewAggregate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAggregate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Create
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
if err := rest.BeforeCreate(projectrequestregistry.Strategy, ctx, obj); err != nil {
return nil, err
}
projectRequest := obj.(*projectapi.ProjectRequest)
if _, err := r.openshiftClient.Projects().Get(projectRequest.Name); err == nil {
return nil, kapierror.NewAlreadyExists("project", projectRequest.Name)
}
projectName := projectRequest.Name
projectAdmin := ""
if userInfo, exists := kapi.UserFrom(ctx); exists {
projectAdmin = userInfo.GetName()
}
template, err := r.getTemplate()
if err != nil {
return nil, err
}
for i := range template.Parameters {
switch template.Parameters[i].Name {
case ProjectAdminUserParam:
template.Parameters[i].Value = projectAdmin
case ProjectDescriptionParam:
template.Parameters[i].Value = projectRequest.Description
case ProjectDisplayNameParam:
template.Parameters[i].Value = projectRequest.DisplayName
case ProjectNameParam:
template.Parameters[i].Value = projectName
}
}
list, err := r.openshiftClient.TemplateConfigs(kapi.NamespaceDefault).Create(template)
if err != nil {
return nil, err
}
if err := utilerrors.NewAggregate(runtime.DecodeList(list.Objects, kapi.Scheme)); err != nil {
return nil, err
}
bulk := configcmd.Bulk{
Mapper: latest.RESTMapper,
Typer: kapi.Scheme,
RESTClientFactory: func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return r.openshiftClient, nil
},
}
if err := utilerrors.NewAggregate(bulk.Create(&kapi.List{Items: list.Objects}, projectName)); err != nil {
return nil, err
}
return r.openshiftClient.Projects().Get(projectName)
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:57,代码来源:delegated.go
示例2: Create
// Create registers a given new ResourceAccessReview instance to r.registry.
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
resourceAccessReview, ok := obj.(*authorizationapi.ResourceAccessReview)
if !ok {
return nil, errors.NewBadRequest(fmt.Sprintf("not a resourceAccessReview: %#v", obj))
}
if err := kutilerrors.NewAggregate(authorizationvalidation.ValidateResourceAccessReview(resourceAccessReview)); err != nil {
return nil, err
}
namespace := kapi.NamespaceValue(ctx)
attributes := &authorizer.DefaultAuthorizationAttributes{
Verb: resourceAccessReview.Verb,
Resource: resourceAccessReview.Resource,
}
users, groups, err := r.authorizer.GetAllowedSubjects(ctx, attributes)
if err != nil {
return nil, err
}
response := &authorizationapi.ResourceAccessReviewResponse{
Namespace: namespace,
Users: users,
Groups: groups,
}
return response, nil
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:30,代码来源:rest.go
示例3: ConfirmUsable
// ConfirmUsable looks a particular context and determines if that particular part of the config is useable. There might still be errors in the config,
// but no errors in the sections requested or referenced. It does not return early so that it can find as many errors as possible.
func (config DirectClientConfig) ConfirmUsable() error {
validationErrors := make([]error, 0)
validationErrors = append(validationErrors, validateAuthInfo(config.getAuthInfoName(), config.getAuthInfo())...)
validationErrors = append(validationErrors, validateClusterInfo(config.getClusterName(), config.getCluster())...)
return errors.NewAggregate(validationErrors)
}
开发者ID:nhr,项目名称:kubernetes,代码行数:9,代码来源:client_config.go
示例4: validate
// validate converts all of the arguments on the config into references to objects, or returns an error
func (c *AppConfig) validate() (app.ComponentReferences, app.SourceRepositories, cmdutil.Environment, cmdutil.Environment, error) {
b := c.refBuilder
b.AddComponents(c.DockerImages, func(input *app.ComponentInput) app.ComponentReference {
input.Argument = fmt.Sprintf("--docker-image=%q", input.From)
input.Resolver = c.dockerResolver
return input
})
b.AddComponents(c.ImageStreams, func(input *app.ComponentInput) app.ComponentReference {
input.Argument = fmt.Sprintf("--image=%q", input.From)
input.Resolver = c.imageStreamResolver
return input
})
b.AddComponents(c.Templates, func(input *app.ComponentInput) app.ComponentReference {
input.Argument = fmt.Sprintf("--template=%q", input.From)
input.Resolver = c.templateResolver
return input
})
b.AddComponents(c.TemplateFiles, func(input *app.ComponentInput) app.ComponentReference {
input.Argument = fmt.Sprintf("--file=%q", input.From)
input.Resolver = c.templateFileResolver
return input
})
b.AddComponents(c.Components, func(input *app.ComponentInput) app.ComponentReference {
input.Resolver = app.PerfectMatchWeightedResolver{
app.WeightedResolver{Resolver: c.imageStreamResolver, Weight: 0.0},
app.WeightedResolver{Resolver: c.templateResolver, Weight: 0.0},
app.WeightedResolver{Resolver: c.templateFileResolver, Weight: 0.0},
app.WeightedResolver{Resolver: c.dockerResolver, Weight: 2.0},
}
return input
})
b.AddGroups(c.Groups)
refs, repos, errs := b.Result()
if len(repos) > 0 {
repos[0].SetContextDir(c.ContextDir)
if len(repos) > 1 {
glog.Warningf("You have specified more than one source repository and a context directory. "+
"The context directory will be applied to the first repository: %q", repos[0])
}
}
if len(c.Strategy) != 0 && len(repos) == 0 {
errs = append(errs, fmt.Errorf("when --strategy is specified you must provide at least one source code location"))
}
env, duplicateEnv, envErrs := cmdutil.ParseEnvironmentArguments(c.Environment)
for _, s := range duplicateEnv {
glog.V(1).Infof("The environment variable %q was overwritten", s)
}
errs = append(errs, envErrs...)
parms, duplicateParms, parmsErrs := cmdutil.ParseEnvironmentArguments(c.TemplateParameters)
for _, s := range duplicateParms {
glog.V(1).Infof("The template parameter %q was overwritten", s)
}
errs = append(errs, parmsErrs...)
return refs, repos, env, parms, errors.NewAggregate(errs)
}
开发者ID:mignev,项目名称:origin,代码行数:61,代码来源:newapp.go
示例5: GetEffectivePolicyRules
// GetEffectivePolicyRules returns the list of rules that apply to a given user in a given namespace and error. If an error is returned, the slice of
// PolicyRules may not be complete, but it contains all retrievable rules. This is done because policy rules are purely additive and policy determinations
// can be made on the basis of those rules that are found.
func (a *DefaultRuleResolver) GetEffectivePolicyRules(ctx kapi.Context) ([]authorizationapi.PolicyRule, error) {
roleBindings, err := a.GetRoleBindings(ctx)
if err != nil {
return nil, err
}
user, exists := kapi.UserFrom(ctx)
if !exists {
return nil, errors.New("user missing from context")
}
errs := []error{}
rules := make([]authorizationapi.PolicyRule, 0, len(roleBindings))
for _, roleBinding := range roleBindings {
if !appliesToUser(roleBinding.Users(), roleBinding.Groups(), user) {
continue
}
role, err := a.GetRole(roleBinding)
if err != nil {
errs = append(errs, err)
continue
}
for _, curr := range role.Rules() {
rules = append(rules, curr)
}
}
return rules, kerrors.NewAggregate(errs)
}
开发者ID:cjnygard,项目名称:origin,代码行数:33,代码来源:find_rules.go
示例6: Visit
func (v FlattenListVisitor) Visit(fn VisitorFunc) error {
return v.Visitor.Visit(func(info *Info) error {
if info.Object == nil {
return fn(info)
}
items, err := runtime.ExtractList(info.Object)
if err != nil {
return fn(info)
}
if errs := runtime.DecodeList(items, struct {
runtime.ObjectTyper
runtime.Decoder
}{v.Mapper, info.Mapping.Codec}); len(errs) > 0 {
return errors.NewAggregate(errs)
}
for i := range items {
item, err := v.InfoForObject(items[i])
if err != nil {
return err
}
if len(info.ResourceVersion) != 0 {
item.ResourceVersion = info.ResourceVersion
}
if err := fn(item); err != nil {
return err
}
}
return nil
})
}
开发者ID:sseago,项目名称:kubernetes,代码行数:30,代码来源:visitor.go
示例7: InitPlugins
// InitPlugins initializes each plugin. All plugins must have unique names.
// This must be called exactly once before any New* methods are called on any
// plugins.
func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, host VolumeHost) error {
pm.mutex.Lock()
defer pm.mutex.Unlock()
if pm.plugins == nil {
pm.plugins = map[string]VolumePlugin{}
}
allErrs := []error{}
for _, plugin := range plugins {
name := plugin.Name()
if !util.IsQualifiedName(name) {
allErrs = append(allErrs, fmt.Errorf("volume plugin has invalid name: %#v", plugin))
continue
}
if _, found := pm.plugins[name]; found {
allErrs = append(allErrs, fmt.Errorf("volume plugin %q was registered more than once", name))
continue
}
plugin.Init(host)
pm.plugins[name] = plugin
glog.V(1).Infof("Loaded volume plugin %q", name)
}
return errors.NewAggregate(allErrs)
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:29,代码来源:plugins.go
示例8: validate
// validate converts all of the arguments on the config into references to objects, or returns an error
func (c *AppConfig) validate() (app.ComponentReferences, app.SourceRepositories, cmdutil.Environment, cmdutil.Environment, error) {
b := c.refBuilder
c.addReferenceBuilderComponents(b)
b.AddGroups(c.Groups)
refs, repos, errs := b.Result()
if len(repos) > 0 {
repos[0].SetContextDir(c.ContextDir)
if len(repos) > 1 {
glog.Warningf("You have specified more than one source repository and a context directory. "+
"The context directory will be applied to the first repository: %q", repos[0])
}
}
if len(c.Strategy) != 0 && len(repos) == 0 {
errs = append(errs, fmt.Errorf("when --strategy is specified you must provide at least one source code location"))
}
env, duplicateEnv, envErrs := cmdutil.ParseEnvironmentArguments(c.Environment)
for _, s := range duplicateEnv {
glog.V(1).Infof("The environment variable %q was overwritten", s)
}
errs = append(errs, envErrs...)
parms, duplicateParms, parmsErrs := cmdutil.ParseEnvironmentArguments(c.TemplateParameters)
for _, s := range duplicateParms {
glog.V(1).Infof("The template parameter %q was overwritten", s)
}
errs = append(errs, parmsErrs...)
return refs, repos, env, parms, errors.NewAggregate(errs)
}
开发者ID:bdmiller3,项目名称:origin,代码行数:33,代码来源:newapp.go
示例9: resolve
// resolve the references to ensure they are all valid, and identify any images that don't match user input.
func (c *AppConfig) resolve(components app.ComponentReferences) error {
errs := []error{}
for _, ref := range components {
if err := ref.Resolve(); err != nil {
errs = append(errs, err)
continue
}
switch input := ref.Input(); {
case !input.ExpectToBuild && input.ResolvedMatch.Builder:
if c.Strategy != "docker" {
glog.Infof("Image %q is a builder, so a repository will be expected unless you also specify --strategy=docker", input)
input.ExpectToBuild = true
}
case input.ExpectToBuild && input.ResolvedMatch.IsTemplate():
// TODO: harder - break the template pieces and check if source code can be attached (look for a build config, build image, etc)
errs = append(errs, fmt.Errorf("template with source code explicitly attached is not supported - you must either specify the template and source code separately or attach an image to the source code using the '[image]~[code]' form"))
continue
case input.ExpectToBuild && !input.ResolvedMatch.Builder && !input.Uses.IsDockerBuild():
if len(c.Strategy) == 0 {
errs = append(errs, fmt.Errorf("none of the images that match %q can build source code - check whether this is the image you want to use, then use --strategy=source to build using source or --strategy=docker to treat this as a Docker base image and set up a layered Docker build", ref))
continue
}
}
}
return errors.NewAggregate(errs)
}
开发者ID:bdmiller3,项目名称:origin,代码行数:27,代码来源:newapp.go
示例10: MakeGraph
// MakeGraph will create the graph of all build configurations and the image streams
// they point to via image change triggers in the provided namespace(s)
func (d *ChainDescriber) MakeGraph() (osgraph.Graph, error) {
g := osgraph.New()
loaders := []GraphLoader{}
for namespace := range d.namespaces {
glog.V(4).Infof("Loading build configurations from %q", namespace)
loaders = append(loaders, &bcLoader{namespace: namespace, lister: d.c})
}
loadingFuncs := []func() error{}
for _, loader := range loaders {
loadingFuncs = append(loadingFuncs, loader.Load)
}
if errs := parallel.Run(loadingFuncs...); len(errs) > 0 {
return g, utilerrors.NewAggregate(errs)
}
for _, loader := range loaders {
loader.AddToGraph(g)
}
buildedges.AddAllInputOutputEdges(g)
return g, nil
}
开发者ID:patrykattc,项目名称:origin,代码行数:27,代码来源:chaindescriber.go
示例11: buildTemplates
// buildTemplates converts a set of resolved, valid references into references to template objects.
func (c *AppConfig) buildTemplates(components app.ComponentReferences, environment app.Environment) ([]runtime.Object, error) {
objects := []runtime.Object{}
for _, ref := range components {
tpl := ref.Input().ResolvedMatch.Template
glog.V(4).Infof("processing template %s/%s", c.originNamespace, tpl.Name)
for _, env := range environment.List() {
// only set environment values that match what's expected by the template.
if v := template.GetParameterByName(tpl, env.Name); v != nil {
v.Value = env.Value
v.Generate = ""
template.AddParameter(tpl, *v)
} else {
return nil, fmt.Errorf("unexpected parameter name %q", env.Name)
}
}
result, err := c.osclient.TemplateConfigs(c.originNamespace).Create(tpl)
if err != nil {
return nil, fmt.Errorf("error processing template %s/%s: %v", c.originNamespace, tpl.Name, err)
}
errs := runtime.DecodeList(result.Objects, kapi.Scheme)
if len(errs) > 0 {
err = errors.NewAggregate(errs)
return nil, fmt.Errorf("error processing template %s/%s: %v", c.originNamespace, tpl.Name, errs)
}
objects = append(objects, result.Objects...)
}
return objects, nil
}
开发者ID:bdmiller3,项目名称:origin,代码行数:32,代码来源:newapp.go
示例12: filterInvalidPods
func filterInvalidPods(pods []*api.Pod, source string, recorder record.EventRecorder) (filtered []*api.Pod) {
names := util.StringSet{}
for i, pod := range pods {
var errlist []error
if errs := validation.ValidatePod(pod); len(errs) != 0 {
errlist = append(errlist, errs...)
// If validation fails, don't trust it any further -
// even Name could be bad.
} else {
name := kubecontainer.GetPodFullName(pod)
if names.Has(name) {
errlist = append(errlist, fielderrors.NewFieldDuplicate("name", pod.Name))
} else {
names.Insert(name)
}
}
if len(errlist) > 0 {
name := bestPodIdentString(pod)
err := utilerrors.NewAggregate(errlist)
glog.Warningf("Pod[%d] (%s) from %s failed validation, ignoring: %v", i+1, name, source, err)
recorder.Eventf(pod, "failedValidation", "Error validating pod %s from %s, ignoring: %v", name, source, err)
continue
}
filtered = append(filtered, pod)
}
return
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:27,代码来源:config.go
示例13: ValidateBytes
func (s *SwaggerSchema) ValidateBytes(data []byte) error {
var obj interface{}
out, err := yaml.ToJSON(data)
if err != nil {
return err
}
data = out
if err := json.Unmarshal(data, &obj); err != nil {
return err
}
fields, ok := obj.(map[string]interface{})
if !ok {
return fmt.Errorf("error in unmarshaling data %s", string(data))
}
apiVersion := fields["apiVersion"]
if apiVersion == nil {
return fmt.Errorf("apiVersion not set")
}
kind := fields["kind"]
if kind == nil {
return fmt.Errorf("kind not set")
}
allErrs := s.ValidateObject(obj, apiVersion.(string), "", apiVersion.(string)+"."+kind.(string))
if len(allErrs) == 1 {
return allErrs[0]
}
return errors.NewAggregate(allErrs)
}
开发者ID:eghobo,项目名称:kubedash,代码行数:28,代码来源:schema.go
示例14: Run
func (l *ListPodsOptions) Run() error {
nodes, err := l.Options.GetNodes()
if err != nil {
return err
}
var printer kubectl.ResourcePrinter
if l.Options.CmdPrinterOutput {
printer = l.Options.CmdPrinter
} else {
printer, _, err = l.Options.GetPrintersByResource("pod")
if err != nil {
return err
}
}
errList := []error{}
for _, node := range nodes {
err := l.runListPods(node, printer)
if err != nil {
// Don't bail out if one node fails
errList = append(errList, err)
}
}
return kerrors.NewAggregate(errList)
}
开发者ID:klpauba,项目名称:origin,代码行数:26,代码来源:listpods.go
示例15: statusCausesToAggrError
func statusCausesToAggrError(scs []api.StatusCause) utilerrors.Aggregate {
errs := make([]error, len(scs))
for i, sc := range scs {
errs[i] = fmt.Errorf("%s: %s", sc.Field, sc.Message)
}
return utilerrors.NewAggregate(errs)
}
开发者ID:gabrielweyer,项目名称:kubernetes,代码行数:7,代码来源:helpers.go
示例16: AuthenticateRequest
// AuthenticateRequest authenticates the request using presented client certificates
func (a *Authenticator) AuthenticateRequest(req *http.Request) (user.Info, bool, error) {
if req.TLS == nil {
return nil, false, nil
}
var errlist []error
for _, cert := range req.TLS.PeerCertificates {
chains, err := cert.Verify(a.opts)
if err != nil {
errlist = append(errlist, err)
continue
}
for _, chain := range chains {
user, ok, err := a.user.User(chain)
if err != nil {
errlist = append(errlist, err)
continue
}
if ok {
return user, ok, err
}
}
}
return nil, false, errors.NewAggregate(errlist)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:28,代码来源:x509.go
示例17: ConfirmUsable
// ConfirmUsable looks a particular context and determines if that particular part of the config is useable. There might still be errors in the config,
// but no errors in the sections requested or referenced. It does not return early so that it can find as many errors as possible.
func ConfirmUsable(config clientcmdapi.Config, passedContextName string) error {
validationErrors := make([]error, 0)
var contextName string
if len(passedContextName) != 0 {
contextName = passedContextName
} else {
contextName = config.CurrentContext
}
if len(contextName) == 0 {
return ErrNoContext
}
context, exists := config.Contexts[contextName]
if !exists {
validationErrors = append(validationErrors, &errContextNotFound{contextName})
}
if exists {
validationErrors = append(validationErrors, validateContext(contextName, context, config)...)
validationErrors = append(validationErrors, validateAuthInfo(context.AuthInfo, config.AuthInfos[context.AuthInfo])...)
validationErrors = append(validationErrors, validateClusterInfo(context.Cluster, config.Clusters[context.Cluster])...)
}
return utilerrors.NewAggregate(validationErrors)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:29,代码来源:validation.go
示例18: CreateMasterCerts
func (o CreateMasterCertsOptions) CreateMasterCerts() error {
glog.V(4).Infof("Creating all certs with: %#v", o)
signerCertOptions := CreateSignerCertOptions{
CertFile: DefaultCertFilename(o.CertDir, CAFilePrefix),
KeyFile: DefaultKeyFilename(o.CertDir, CAFilePrefix),
SerialFile: DefaultSerialFilename(o.CertDir, CAFilePrefix),
Name: o.SignerName,
Overwrite: o.Overwrite,
Output: o.Output,
}
if err := signerCertOptions.Validate(nil); err != nil {
return err
}
if _, err := signerCertOptions.CreateSignerCert(); err != nil {
return err
}
// once we've minted the signer, don't overwrite it
getSignerCertOptions := GetSignerCertOptions{
CertFile: DefaultCertFilename(o.CertDir, CAFilePrefix),
KeyFile: DefaultKeyFilename(o.CertDir, CAFilePrefix),
SerialFile: DefaultSerialFilename(o.CertDir, CAFilePrefix),
}
errs := parallel.Run(
func() error { return o.createServerCerts(&getSignerCertOptions) },
func() error { return o.createAPIClients(&getSignerCertOptions) },
func() error { return o.createEtcdClientCerts(&getSignerCertOptions) },
func() error { return o.createKubeletClientCerts(&getSignerCertOptions) },
func() error { return o.createServiceAccountKeys() },
)
return utilerrors.NewAggregate(errs)
}
开发者ID:miminar,项目名称:atomic-enterprise,代码行数:33,代码来源:create_mastercerts.go
示例19: RunSearch
// RunSearch executes the provided config and returns the result of the resolution.
func (c *AppConfig) RunSearch(out, errOut io.Writer) (*SearchResult, error) {
c.ensureDockerSearcher()
repositories, err := c.individualSourceRepositories()
if err != nil {
return nil, err
}
components, repositories, environment, parameters, err := c.validate()
if err != nil {
return nil, err
}
if len(repositories) == 0 && len(components) == 0 {
return nil, ErrNoInputs
}
errs := []error{}
if len(repositories) > 0 {
errs = append(errs, fmt.Errorf("--search can't be used with source code"))
}
if len(environment) > 0 {
errs = append(errs, fmt.Errorf("--search can't be used with --env"))
}
if len(parameters) > 0 {
errs = append(errs, fmt.Errorf("--search can't be used with --param"))
}
if len(errs) > 0 {
return nil, errors.NewAggregate(errs)
}
if err := c.search(components); err != nil {
return nil, err
}
glog.V(4).Infof("Code %v", repositories)
glog.V(4).Infof("Components %v", components)
matches := app.ComponentMatches{}
objects := app.Objects{}
for _, ref := range components {
for _, match := range ref.Input().SearchMatches {
matches = append(matches, match)
if match.IsTemplate() {
objects = append(objects, match.Template)
} else if match.IsImage() {
if match.ImageStream != nil {
objects = append(objects, match.ImageStream)
}
if match.Image != nil {
objects = append(objects, match.Image)
}
}
}
}
return &SearchResult{
Matches: matches,
List: &kapi.List{Items: objects},
}, nil
}
开发者ID:bdmiller3,项目名称:origin,代码行数:59,代码来源:newapp.go
示例20: Filter
// Filter removes items from the ValidationErrorList that match the provided fns.
func (list ValidationErrorList) Filter(fns ...errors.Matcher) ValidationErrorList {
err := errors.FilterOut(errors.NewAggregate(list), fns...)
if err == nil {
return nil
}
// FilterOut that takes an Aggregate returns an Aggregate
agg := err.(errors.Aggregate)
return ValidationErrorList(agg.Errors())
}
开发者ID:brorhie,项目名称:panamax-kubernetes-adapter-go,代码行数:10,代码来源:validation.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors.NewAggregate函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论