本文整理汇总了Golang中github.com/openshift/origin/pkg/generate/app.ComponentReferences类的典型用法代码示例。如果您正苦于以下问题:Golang ComponentReferences类的具体用法?Golang ComponentReferences怎么用?Golang ComponentReferences使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ComponentReferences类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: installComponents
// installComponents attempts to create pods to run installable images identified by the user. If an image
// is installable, we check whether it requires access to the user token. If so, the caller must have
// explicitly granted that access (because the token may be the user's).
func (c *AppConfig) installComponents(components app.ComponentReferences) ([]runtime.Object, string, error) {
if c.SkipGeneration {
return nil, "", nil
}
jobs := components.InstallableComponentRefs()
switch {
case len(jobs) > 1:
return nil, "", fmt.Errorf("only one installable component may be provided: %s", jobs.HumanString(", "))
case len(jobs) == 0:
return nil, "", nil
}
job := jobs[0]
if len(components) > 1 {
return nil, "", fmt.Errorf("%q is installable and may not be specified with other components", job.Input().Value)
}
input := job.Input()
imageRef, err := app.InputImageFromMatch(input.ResolvedMatch)
if err != nil {
return nil, "", fmt.Errorf("can't include %q: %v", input, err)
}
glog.V(4).Infof("Resolved match for installer %#v", input.ResolvedMatch)
imageRef.AsImageStream = false
imageRef.AsResolvedImage = true
name := c.Name
if len(name) == 0 {
var ok bool
name, ok = imageRef.SuggestName()
if !ok {
return nil, "", fmt.Errorf("can't suggest a valid name, please specify a name with --name")
}
}
imageRef.ObjectName = name
glog.V(4).Infof("Proposed installable image %#v", imageRef)
generatorInput := input.ResolvedMatch.GeneratorInput
if generatorInput.Token != nil && !c.AllowSecretUse || c.SecretAccessor == nil {
return nil, "", ErrRequiresExplicitAccess{*input.ResolvedMatch}
}
pod, secret, err := imageRef.InstallablePod(generatorInput, c.SecretAccessor)
if err != nil {
return nil, "", err
}
objects := []runtime.Object{pod}
if secret != nil {
objects = append(objects, secret)
}
for i := range objects {
outil.AddObjectAnnotations(objects[i], map[string]string{
GeneratedForJob: "true",
GeneratedForJobFor: input.String(),
})
}
return objects, name, nil
}
开发者ID:hloganathan,项目名称:origin,代码行数:63,代码来源:newapp.go
示例2: buildPipelines
// buildPipelines converts a set of resolved, valid references into pipelines.
func (c *AppConfig) buildPipelines(components app.ComponentReferences, environment app.Environment) (app.PipelineGroup, error) {
pipelines := app.PipelineGroup{}
pipelineBuilder := app.NewPipelineBuilder(c.Name, c.GetBuildEnvironment(environment), c.OutputDocker).To(c.To)
for _, group := range components.Group() {
glog.V(4).Infof("found group: %v", group)
common := app.PipelineGroup{}
for _, ref := range group {
refInput := ref.Input()
from := refInput.String()
var (
pipeline *app.Pipeline
err error
)
switch {
case refInput.ExpectToBuild:
glog.V(4).Infof("will add %q secrets into a build for a source build of %q", strings.Join(c.Secrets, ","), refInput.Uses)
if err := refInput.Uses.AddBuildSecrets(c.Secrets); err != nil {
return nil, fmt.Errorf("unable to add build secrets %q: %v", strings.Join(c.Secrets, ","), err)
}
glog.V(4).Infof("will use %q as the base image for a source build of %q", ref, refInput.Uses)
if pipeline, err = pipelineBuilder.NewBuildPipeline(from, refInput.ResolvedMatch, refInput.Uses); err != nil {
return nil, fmt.Errorf("can't build %q: %v", refInput.Uses, err)
}
default:
glog.V(4).Infof("will include %q", ref)
if pipeline, err = pipelineBuilder.NewImagePipeline(from, refInput.ResolvedMatch); err != nil {
return nil, fmt.Errorf("can't include %q: %v", refInput, err)
}
}
if c.Deploy {
if err := pipeline.NeedsDeployment(environment, c.Labels); err != nil {
return nil, fmt.Errorf("can't set up a deployment for %q: %v", refInput, err)
}
}
if c.NoOutput {
pipeline.Build.Output = nil
}
if err := pipeline.Validate(); err != nil {
switch err.(type) {
case app.CircularOutputReferenceError:
if len(c.To) == 0 {
// Output reference was generated, return error.
return nil, err
}
// Output reference was explicitly provided, print warning.
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n", err)
default:
return nil, err
}
}
common = append(common, pipeline)
if err := common.Reduce(); err != nil {
return nil, fmt.Errorf("can't create a pipeline from %s: %v", common, err)
}
describeBuildPipelineWithImage(c.Out, ref, pipeline, c.originNamespace)
}
pipelines = append(pipelines, common...)
}
return pipelines, nil
}
开发者ID:roofmonkey,项目名称:origin,代码行数:61,代码来源:newapp.go
示例3: buildPipelines
// buildPipelines converts a set of resolved, valid references into pipelines.
func (c *AppConfig) buildPipelines(components app.ComponentReferences, environment app.Environment) (app.PipelineGroup, error) {
pipelines := app.PipelineGroup{}
pipelineBuilder := app.NewPipelineBuilder(c.Name, c.GetBuildEnvironment(environment), c.OutputDocker)
for _, group := range components.Group() {
glog.V(4).Infof("found group: %#v", group)
common := app.PipelineGroup{}
for _, ref := range group {
refInput := ref.Input()
from := refInput.String()
var (
pipeline *app.Pipeline
err error
)
if refInput.ExpectToBuild {
glog.V(4).Infof("will use %q as the base image for a source build of %q", ref, refInput.Uses)
if pipeline, err = pipelineBuilder.NewBuildPipeline(from, refInput.ResolvedMatch, refInput.Uses); err != nil {
return nil, fmt.Errorf("can't build %q: %v", refInput, err)
}
} else {
glog.V(4).Infof("will include %q", ref)
if pipeline, err = pipelineBuilder.NewImagePipeline(from, refInput.ResolvedMatch); err != nil {
return nil, fmt.Errorf("can't include %q: %v", refInput, err)
}
}
if c.Deploy {
if err := pipeline.NeedsDeployment(environment, c.Labels); err != nil {
return nil, fmt.Errorf("can't set up a deployment for %q: %v", refInput, err)
}
}
common = append(common, pipeline)
if err := common.Reduce(); err != nil {
return nil, fmt.Errorf("can't create a pipeline from %s: %v", common, err)
}
describeBuildPipelineWithImage(c.Out, ref, pipeline, c.originNamespace)
}
pipelines = append(pipelines, common...)
}
return pipelines, nil
}
开发者ID:biswajeetparida,项目名称:origin,代码行数:40,代码来源:newapp.go
示例4: buildPipelines
// buildPipelines converts a set of resolved, valid references into pipelines.
func (c *AppConfig) buildPipelines(components app.ComponentReferences, environment app.Environment) (app.PipelineGroup, error) {
pipelines := app.PipelineGroup{}
names := map[string]int{}
for _, group := range components.Group() {
glog.V(2).Infof("found group: %#v", group)
common := app.PipelineGroup{}
for _, ref := range group {
var pipeline *app.Pipeline
var name string
if ref.Input().ExpectToBuild {
glog.V(2).Infof("will use %q as the base image for a source build of %q", ref, ref.Input().Uses)
input, err := app.InputImageFromMatch(ref.Input().ResolvedMatch)
if err != nil {
return nil, fmt.Errorf("can't build %q: %v", ref.Input(), err)
}
if !input.AsImageStream {
glog.Warningf("Could not find an image match for %q. Make sure that a Docker image with that tag is available on the node for the build to succeed.", ref.Input().ResolvedMatch.Value)
}
strategy, source, err := app.StrategyAndSourceForRepository(ref.Input().Uses, input)
if err != nil {
return nil, fmt.Errorf("can't build %q: %v", ref.Input(), err)
}
// Override resource names from the cli
name = c.Name
if len(name) == 0 {
var ok bool
name, ok = (app.NameSuggestions{source, input}).SuggestName()
if !ok {
return nil, fmt.Errorf("can't suggest a valid name, please specify a name with --name")
}
}
name, err = ensureValidUniqueName(names, name)
source.Name = name
if err != nil {
return nil, err
}
// Append any exposed ports from Dockerfile to input image
if ref.Input().Uses.IsDockerBuild() {
exposed, ok := ref.Input().Uses.Info().Dockerfile.GetDirective("EXPOSE")
if ok {
if input.Info == nil {
input.Info = &imageapi.DockerImage{
Config: &imageapi.DockerConfig{},
}
}
input.Info.Config.ExposedPorts = map[string]struct{}{}
for _, p := range exposed {
input.Info.Config.ExposedPorts[p] = struct{}{}
}
}
}
if pipeline, err = app.NewBuildPipeline(ref.Input().String(), input, c.OutputDocker, strategy, c.GetBuildEnvironment(environment), source); err != nil {
return nil, fmt.Errorf("can't build %q: %v", ref.Input(), err)
}
} else {
glog.V(2).Infof("will include %q", ref)
input, err := app.InputImageFromMatch(ref.Input().ResolvedMatch)
if err != nil {
return nil, fmt.Errorf("can't include %q: %v", ref.Input(), err)
}
name = c.Name
if len(name) == 0 {
var ok bool
name, ok = input.SuggestName()
if !ok {
return nil, fmt.Errorf("can't suggest a valid name, please specify a name with --name")
}
}
name, err = ensureValidUniqueName(names, name)
if err != nil {
return nil, err
}
input.ObjectName = name
if pipeline, err = app.NewImagePipeline(ref.Input().String(), input); err != nil {
return nil, fmt.Errorf("can't include %q: %v", ref.Input(), err)
}
}
if err := pipeline.NeedsDeployment(environment, c.Labels, name); err != nil {
return nil, fmt.Errorf("can't set up a deployment for %q: %v", ref.Input(), err)
}
common = append(common, pipeline)
}
if err := common.Reduce(); err != nil {
return nil, fmt.Errorf("can't create a pipeline from %s: %v", common, err)
}
pipelines = append(pipelines, common...)
}
return pipelines, nil
}
开发者ID:nitintutlani,项目名称:origin,代码行数:92,代码来源:newapp.go
示例5: installComponents
// installComponents attempts to create pods to run installable images identified by the user. If an image
// is installable, we check whether it requires access to the user token. If so, the caller must have
// explicitly granted that access (because the token may be the user's).
func (c *AppConfig) installComponents(components app.ComponentReferences, env app.Environment) ([]runtime.Object, string, error) {
if c.SkipGeneration {
return nil, "", nil
}
jobs := components.InstallableComponentRefs()
switch {
case len(jobs) > 1:
return nil, "", fmt.Errorf("only one installable component may be provided: %s", jobs.HumanString(", "))
case len(jobs) == 0:
return nil, "", nil
}
job := jobs[0]
if len(components) > 1 {
return nil, "", fmt.Errorf("%q is installable and may not be specified with other components", job.Input().Value)
}
input := job.Input()
imageRef, err := app.InputImageFromMatch(input.ResolvedMatch)
if err != nil {
return nil, "", fmt.Errorf("can't include %q: %v", input, err)
}
glog.V(4).Infof("Resolved match for installer %#v", input.ResolvedMatch)
imageRef.AsImageStream = false
imageRef.AsResolvedImage = true
imageRef.Env = env
name := c.Name
if len(name) == 0 {
var ok bool
name, ok = imageRef.SuggestName()
if !ok {
return nil, "", fmt.Errorf("can't suggest a valid name, please specify a name with --name")
}
}
imageRef.ObjectName = name
glog.V(4).Infof("Proposed installable image %#v", imageRef)
secretAccessor := c.SecretAccessor
generatorInput := input.ResolvedMatch.GeneratorInput
token := generatorInput.Token
if token != nil && !c.AllowSecretUse || secretAccessor == nil {
if !c.DryRun {
return nil, "", ErrRequiresExplicitAccess{Match: *input.ResolvedMatch, Input: generatorInput}
}
secretAccessor = &fakeSecretAccessor{token: "FAKE_TOKEN"}
}
objects := []runtime.Object{}
serviceAccountName := "installer"
if token != nil && token.ServiceAccount {
if _, err := c.KubeClient.ServiceAccounts(c.originNamespace).Get(serviceAccountName); err != nil {
if kerrors.IsNotFound(err) {
objects = append(objects,
// create a new service account
&kapi.ServiceAccount{ObjectMeta: kapi.ObjectMeta{Name: serviceAccountName}},
// grant the service account the edit role on the project (TODO: installer)
&authapi.RoleBinding{
ObjectMeta: kapi.ObjectMeta{Name: "installer-role-binding"},
Subjects: []kapi.ObjectReference{{Kind: "ServiceAccount", Name: serviceAccountName}},
RoleRef: kapi.ObjectReference{Name: "edit"},
},
)
}
}
}
pod, secret, err := imageRef.InstallablePod(generatorInput, secretAccessor, serviceAccountName)
if err != nil {
return nil, "", err
}
objects = append(objects, pod)
if secret != nil {
objects = append(objects, secret)
}
for i := range objects {
outil.AddObjectAnnotations(objects[i], map[string]string{
GeneratedForJob: "true",
GeneratedForJobFor: input.String(),
})
}
describeGeneratedJob(c.Out, job, pod, secret, c.originNamespace)
return objects, name, nil
}
开发者ID:arielcarrera,项目名称:origin,代码行数:92,代码来源:newapp.go
示例6: buildPipelines
// buildPipelines converts a set of resolved, valid references into pipelines.
func (c *AppConfig) buildPipelines(components app.ComponentReferences, environment app.Environment) (app.PipelineGroup, error) {
pipelines := app.PipelineGroup{}
pipelineBuilder := app.NewPipelineBuilder(c.Name, c.GetBuildEnvironment(environment), c.OutputDocker).To(c.To)
for _, group := range components.Group() {
glog.V(4).Infof("found group: %v", group)
common := app.PipelineGroup{}
for _, ref := range group {
refInput := ref.Input()
from := refInput.String()
var pipeline *app.Pipeline
switch {
case refInput.ExpectToBuild:
glog.V(4).Infof("will add %q secrets into a build for a source build of %q", strings.Join(c.Secrets, ","), refInput.Uses)
if err := refInput.Uses.AddBuildSecrets(c.Secrets); err != nil {
return nil, fmt.Errorf("unable to add build secrets %q: %v", strings.Join(c.Secrets, ","), err)
}
var (
image *app.ImageRef
err error
)
if refInput.ResolvedMatch != nil {
inputImage, err := app.InputImageFromMatch(refInput.ResolvedMatch)
if err != nil {
return nil, fmt.Errorf("can't build %q: %v", from, err)
}
if !inputImage.AsImageStream && from != "scratch" && (refInput.Uses == nil || refInput.Uses.GetStrategy() != generate.StrategyPipeline) {
msg := "Could not find an image stream match for %q. Make sure that a Docker image with that tag is available on the node for the build to succeed."
glog.Warningf(msg, from)
}
image = inputImage
}
glog.V(4).Infof("will use %q as the base image for a source build of %q", ref, refInput.Uses)
if pipeline, err = pipelineBuilder.NewBuildPipeline(from, image, refInput.Uses); err != nil {
return nil, fmt.Errorf("can't build %q: %v", refInput.Uses, err)
}
default:
inputImage, err := app.InputImageFromMatch(refInput.ResolvedMatch)
if err != nil {
return nil, fmt.Errorf("can't include %q: %v", from, err)
}
if !inputImage.AsImageStream {
msg := "Could not find an image stream match for %q. Make sure that a Docker image with that tag is available on the node for the deployment to succeed."
glog.Warningf(msg, from)
}
glog.V(4).Infof("will include %q", ref)
if pipeline, err = pipelineBuilder.NewImagePipeline(from, inputImage); err != nil {
return nil, fmt.Errorf("can't include %q: %v", refInput, err)
}
}
if c.Deploy {
if err := pipeline.NeedsDeployment(environment, c.Labels, c.AsTestDeployment); err != nil {
return nil, fmt.Errorf("can't set up a deployment for %q: %v", refInput, err)
}
}
if c.NoOutput {
pipeline.Build.Output = nil
}
if refInput.Uses != nil && refInput.Uses.GetStrategy() == generate.StrategyPipeline {
pipeline.Build.Output = nil
pipeline.Deployment = nil
pipeline.Image = nil
pipeline.InputImage = nil
}
common = append(common, pipeline)
if err := common.Reduce(); err != nil {
return nil, fmt.Errorf("can't create a pipeline from %s: %v", common, err)
}
describeBuildPipelineWithImage(c.Out, ref, pipeline, c.OriginNamespace)
}
pipelines = append(pipelines, common...)
}
return pipelines, nil
}
开发者ID:nak3,项目名称:origin,代码行数:78,代码来源:newapp.go
示例7: buildPipelines
// buildPipelines converts a set of resolved, valid references into pipelines.
func (c *AppConfig) buildPipelines(components app.ComponentReferences, environment app.Environment) (app.PipelineGroup, error) {
pipelines := app.PipelineGroup{}
names := map[string]int{}
for _, group := range components.Group() {
glog.V(2).Infof("found group: %#v", group)
common := app.PipelineGroup{}
for _, ref := range group {
if !ref.Input().Match.IsImage() {
continue
}
var pipeline *app.Pipeline
if ref.Input().ExpectToBuild {
glog.V(2).Infof("will use %q as the base image for a source build of %q", ref, ref.Input().Uses)
input, err := app.InputImageFromMatch(ref.Input().Match)
if err != nil {
return nil, fmt.Errorf("can't build %q: %v", ref.Input(), err)
}
strategy, source, err := app.StrategyAndSourceForRepository(ref.Input().Uses, input)
if err != nil {
return nil, fmt.Errorf("can't build %q: %v", ref.Input(), err)
}
// Override resource names from the cli
if len(c.Name) > 0 {
source.Name = c.Name
}
if name, ok := (app.NameSuggestions{source, input}).SuggestName(); ok {
source.Name, err = ensureValidUniqueName(names, name)
if err != nil {
return nil, err
}
}
if pipeline, err = app.NewBuildPipeline(ref.Input().String(), input, c.OutputDocker, strategy, source); err != nil {
return nil, fmt.Errorf("can't build %q: %v", ref.Input(), err)
}
} else {
glog.V(2).Infof("will include %q", ref)
input, err := app.InputImageFromMatch(ref.Input().Match)
if name, ok := input.SuggestName(); ok {
input.ObjectName, err = ensureValidUniqueName(names, name)
if err != nil {
return nil, err
}
}
if err != nil {
return nil, fmt.Errorf("can't include %q: %v", ref.Input(), err)
}
if pipeline, err = app.NewImagePipeline(ref.Input().String(), input); err != nil {
return nil, fmt.Errorf("can't include %q: %v", ref.Input(), err)
}
}
if err := pipeline.NeedsDeployment(environment, c.Name); err != nil {
return nil, fmt.Errorf("can't set up a deployment for %q: %v", ref.Input(), err)
}
common = append(common, pipeline)
}
if err := common.Reduce(); err != nil {
return nil, fmt.Errorf("can't create a pipeline from %s: %v", common, err)
}
pipelines = append(pipelines, common...)
}
return pipelines, nil
}
开发者ID:mignev,项目名称:origin,代码行数:64,代码来源:newapp.go
注:本文中的github.com/openshift/origin/pkg/generate/app.ComponentReferences类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论