本文整理汇总了Golang中github.com/openshift/origin/pkg/build/util.GetInputReference函数的典型用法代码示例。如果您正苦于以下问题:Golang GetInputReference函数的具体用法?Golang GetInputReference怎么用?Golang GetInputReference使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetInputReference函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ValidateBuildConfig
// ValidateBuildConfig tests required fields for a Build.
func ValidateBuildConfig(config *buildapi.BuildConfig) field.ErrorList {
allErrs := field.ErrorList{}
allErrs = append(allErrs, validation.ValidateObjectMeta(&config.ObjectMeta, true, validation.NameIsDNSSubdomain, field.NewPath("metadata"))...)
// image change triggers that refer
fromRefs := map[string]struct{}{}
specPath := field.NewPath("spec")
triggersPath := specPath.Child("triggers")
buildFrom := buildutil.GetInputReference(config.Spec.Strategy)
for i, trg := range config.Spec.Triggers {
allErrs = append(allErrs, validateTrigger(&trg, buildFrom, triggersPath.Index(i))...)
if trg.Type != buildapi.ImageChangeBuildTriggerType || trg.ImageChange == nil {
continue
}
from := trg.ImageChange.From
if from == nil {
from = buildFrom
}
fromKey := refKey(config.Namespace, from)
_, exists := fromRefs[fromKey]
if exists {
allErrs = append(allErrs, field.Invalid(triggersPath, config.Spec.Triggers, "multiple ImageChange triggers refer to the same image stream tag"))
}
fromRefs[fromKey] = struct{}{}
}
allErrs = append(allErrs, validateBuildSpec(&config.Spec.BuildSpec, specPath)...)
return allErrs
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:31,代码来源:validation.go
示例2: ImageStreamReferenceIndexFunc
// ImageStreamReferenceIndexFunc is a default index function that indexes based on image stream references.
func ImageStreamReferenceIndexFunc(obj interface{}) ([]string, error) {
switch t := obj.(type) {
case *buildapi.BuildConfig:
var keys []string
for _, trigger := range t.Spec.Triggers {
if trigger.Type != buildapi.ImageChangeBuildTriggerType {
continue
}
from := trigger.ImageChange.From
// We're indexing on the imagestream referenced by the imagechangetrigger,
// however buildconfigs allow one "default" imagechangetrigger in which
// the ICT does not explicitly indicate the image it is triggering on,
// instead it triggers on the image being used as the builder/base image
// as referenced in the build strategy, so if this is an ICT w/ no
// explicit image reference, use the image referenced by the strategy
// because this is the default ICT.
if from == nil {
from = buildutil.GetInputReference(t.Spec.Strategy)
if from == nil || from.Kind != "ImageStreamTag" {
continue
}
}
name, _, _ := imageapi.SplitImageStreamTag(from.Name)
namespace := from.Namespace
// if the imagestream reference has no namespace, use the
// namespace of the buildconfig.
if len(namespace) == 0 {
namespace = t.Namespace
}
keys = append(keys, namespace+"/"+name)
}
if len(keys) == 0 {
// Return an empty key for configs that don't hold object references.
keys = append(keys, "")
}
return keys, nil
case *deployapi.DeploymentConfig:
var keys []string
for _, trigger := range t.Spec.Triggers {
if trigger.Type != deployapi.DeploymentTriggerOnImageChange {
continue
}
params := trigger.ImageChangeParams
name, _, _ := imageapi.SplitImageStreamTag(params.From.Name)
keys = append(keys, params.From.Namespace+"/"+name)
}
if len(keys) == 0 {
// Return an empty key for configs that don't hold object references.
keys = append(keys, "")
}
return keys, nil
}
return nil, fmt.Errorf("image stream reference index not implemented for %#v", obj)
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:60,代码来源:index.go
示例3: AddInputEdges
// AddInputEdges links the build config to its input image and source nodes.
func AddInputEdges(g osgraph.MutableUniqueGraph, node *buildgraph.BuildConfigNode) {
if in := buildgraph.EnsureSourceRepositoryNode(g, node.BuildConfig.Spec.Source); in != nil {
g.AddEdge(in, node, BuildInputEdgeKind)
}
inputImage := buildutil.GetInputReference(node.BuildConfig.Spec.Strategy)
if input := imageRefNode(g, inputImage, node.BuildConfig); input != nil {
g.AddEdge(input, node, BuildInputImageEdgeKind)
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:10,代码来源:edges.go
示例4: checkCircularReferences
// checkCircularReferences ensures there are no builds that can trigger themselves
// due to an imagechangetrigger that matches the output destination of the image.
// objects is a list of api objects produced by new-app.
func (c *AppConfig) checkCircularReferences(objects app.Objects) error {
for i, obj := range objects {
if glog.V(5) {
json, _ := json.MarshalIndent(obj, "", "\t")
glog.Infof("\n\nCycle check input object %v:\n%v\n", i, string(json))
}
if bc, ok := obj.(*buildapi.BuildConfig); ok {
input := buildutil.GetInputReference(bc.Spec.Strategy)
output := bc.Spec.Output.To
if output == nil || input == nil {
return nil
}
dockerInput, err := c.followRefToDockerImage(input, nil, objects)
if err != nil {
glog.Warningf("Unable to check for circular build input: %v", err)
return nil
}
glog.V(5).Infof("Post follow input:\n%#v\n", dockerInput)
dockerOutput, err := c.followRefToDockerImage(output, nil, objects)
if err != nil {
glog.Warningf("Unable to check for circular build output: %v", err)
return nil
}
glog.V(5).Infof("Post follow:\n%#v\n", dockerOutput)
if dockerInput != nil && dockerOutput != nil {
if reflect.DeepEqual(dockerInput, dockerOutput) {
return app.CircularOutputReferenceError{Reference: fmt.Sprintf("%s", dockerInput.Name)}
}
}
// If it is not possible to follow input and output out to DockerImages,
// it is likely they are referencing newly created ImageStreams. Just
// make sure they are not the same image stream.
inCopy := *input
outCopy := *output
for _, ref := range []*kapi.ObjectReference{&inCopy, &outCopy} {
// Some code paths add namespace and others don't. Make things
// consistent.
if len(ref.Namespace) == 0 {
ref.Namespace = c.OriginNamespace
}
}
if reflect.DeepEqual(inCopy, outCopy) {
return app.CircularOutputReferenceError{Reference: fmt.Sprintf("%s/%s", inCopy.Namespace, inCopy.Name)}
}
}
}
return nil
}
开发者ID:nak3,项目名称:origin,代码行数:59,代码来源:newapp.go
示例5: strategyTrigger
// strategyTrigger returns a synthetic ImageChangeTrigger that represents the image stream tag the build strategy
// points to, or nil if no such strategy trigger is possible (if the build doesn't point to an ImageStreamTag).
func strategyTrigger(config *buildapi.BuildConfig) *ImageChangeTrigger {
if from := buildutil.GetInputReference(config.Spec.Strategy); from != nil {
if from.Kind == "ImageStreamTag" {
// normalize the strategy object reference
from.Namespace = defaultNamespace(from.Namespace, config.Namespace)
return &ImageChangeTrigger{From: from.Name, Namespace: from.Namespace}
}
}
return nil
}
开发者ID:mffiedler,项目名称:origin,代码行数:12,代码来源:triggers.go
示例6: AddTriggerEdges
// AddTriggerEdges links the build config to its trigger input image nodes.
func AddTriggerEdges(g osgraph.MutableUniqueGraph, node *buildgraph.BuildConfigNode) {
for _, trigger := range node.BuildConfig.Spec.Triggers {
if trigger.Type != buildapi.ImageChangeBuildTriggerType {
continue
}
from := trigger.ImageChange.From
if trigger.ImageChange.From == nil {
from = buildutil.GetInputReference(node.BuildConfig.Spec.Strategy)
}
triggerNode := imageRefNode(g, from, node.BuildConfig)
g.AddEdge(triggerNode, node, BuildTriggerImageEdgeKind)
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:14,代码来源:edges.go
示例7: checkCircularReferences
// checkCircularReferences ensures there are no builds that can trigger themselves
// due to an imagechangetrigger that matches the output destination of the image.
// objects is a list of api objects produced by new-app.
func (c *AppConfig) checkCircularReferences(objects app.Objects) error {
for _, obj := range objects {
if bc, ok := obj.(*buildapi.BuildConfig); ok {
input := buildutil.GetInputReference(bc.Spec.Strategy)
if bc.Spec.Output.To != nil && input != nil &&
reflect.DeepEqual(input, bc.Spec.Output.To) {
ns := input.Namespace
if len(ns) == 0 {
ns = c.OriginNamespace
}
return app.CircularOutputReferenceError{Reference: fmt.Sprintf("%s/%s", ns, input.Name)}
}
}
}
return nil
}
开发者ID:Xmagicer,项目名称:origin,代码行数:19,代码来源:newapp.go
示例8: addBuildStrategyImageReferencesToGraph
// addBuildStrategyImageReferencesToGraph ads references from the build strategy's parent node to the image
// the build strategy references.
//
// Edges are added to the graph from each predecessor (build or build config)
// to the image specified by strategy.from, as long as the image is managed by
// OpenShift.
func addBuildStrategyImageReferencesToGraph(g graph.Graph, strategy buildapi.BuildStrategy, predecessor gonum.Node) {
from := buildutil.GetInputReference(strategy)
if from == nil {
glog.V(4).Infof("Unable to determine 'from' reference - skipping")
return
}
glog.V(4).Infof("Examining build strategy with from: %#v", from)
var imageID string
switch from.Kind {
case "ImageStreamImage":
_, id, err := imagestreamimage.ParseNameAndID(from.Name)
if err != nil {
glog.V(2).Infof("Error parsing ImageStreamImage name %q: %v - skipping", from.Name, err)
return
}
imageID = id
case "DockerImage":
ref, err := imageapi.ParseDockerImageReference(from.Name)
if err != nil {
glog.V(2).Infof("Error parsing DockerImage name %q: %v - skipping", from.Name, err)
return
}
imageID = ref.ID
default:
return
}
glog.V(4).Infof("Looking for image %q in graph", imageID)
imageNode := imagegraph.FindImage(g, imageID)
if imageNode == nil {
glog.V(4).Infof("Unable to find image %q in graph - skipping", imageID)
return
}
glog.V(4).Infof("Adding edge from %v to %v", predecessor, imageNode)
g.AddEdge(predecessor, imageNode, ReferencedImageEdgeKind)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:46,代码来源:imagepruner.go
示例9: Convert_v1_BuildConfig_To_api_BuildConfig
func Convert_v1_BuildConfig_To_api_BuildConfig(in *BuildConfig, out *newer.BuildConfig, s conversion.Scope) error {
if err := autoConvert_v1_BuildConfig_To_api_BuildConfig(in, out, s); err != nil {
return err
}
newTriggers := []newer.BuildTriggerPolicy{}
// strip off any default imagechange triggers where the buildconfig's
// "from" is not an ImageStreamTag, because those triggers
// will never be invoked.
imageRef := buildutil.GetInputReference(out.Spec.Strategy)
hasIST := imageRef != nil && imageRef.Kind == "ImageStreamTag"
for _, trigger := range out.Spec.Triggers {
if trigger.Type != newer.ImageChangeBuildTriggerType {
newTriggers = append(newTriggers, trigger)
continue
}
if (trigger.ImageChange == nil || trigger.ImageChange.From == nil) && !hasIST {
continue
}
newTriggers = append(newTriggers, trigger)
}
out.Spec.Triggers = newTriggers
return nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:24,代码来源:conversion.go
示例10: HandleImageStream
// HandleImageStream processes the next ImageStream event.
func (c *ImageChangeController) HandleImageStream(stream *imageapi.ImageStream) error {
glog.V(4).Infof("Build image change controller detected ImageStream change %s", stream.Status.DockerImageRepository)
// Loop through all build configurations and record if there was an error
// instead of breaking the loop. The error will be returned in the end, so the
// retry controller can retry. Any BuildConfigs that were processed successfully
// should have had their LastTriggeredImageID updated, so the retry should result
// in a no-op for them.
hasError := false
bcs, err := c.BuildConfigIndex.GetConfigsForImageStreamTrigger(stream.Namespace, stream.Name)
if err != nil {
return err
}
for _, config := range bcs {
var (
from *kapi.ObjectReference
shouldBuild = false
triggeredImage = ""
latest *imageapi.TagEvent
)
// For every ImageChange trigger find the latest tagged image from the image stream and
// invoke a build using that image id. A new build is triggered only if the latest tagged image id or pull spec
// differs from the last triggered build recorded on the build config for that trigger
for _, trigger := range config.Spec.Triggers {
if trigger.Type != buildapi.ImageChangeBuildTriggerType {
continue
}
if trigger.ImageChange.From != nil {
from = trigger.ImageChange.From
} else {
from = buildutil.GetInputReference(config.Spec.Strategy)
}
if from == nil || from.Kind != "ImageStreamTag" {
continue
}
fromStreamName, tag, ok := imageapi.SplitImageStreamTag(from.Name)
if !ok {
glog.Errorf("Invalid image stream tag: %s in build config %s/%s", from.Name, config.Name, config.Namespace)
continue
}
fromNamespace := from.Namespace
if len(fromNamespace) == 0 {
fromNamespace = config.Namespace
}
// only trigger a build if this image stream matches the name and namespace of the stream ref in the build trigger
// also do not trigger if the imagerepo does not have a valid DockerImageRepository value for us to pull
// the image from
if len(stream.Status.DockerImageRepository) == 0 || fromStreamName != stream.Name || fromNamespace != stream.Namespace {
continue
}
// This split is safe because ImageStreamTag names always have the form
// name:tag.
latest = imageapi.LatestTaggedImage(stream, tag)
if latest == nil {
glog.V(4).Infof("unable to find tagged image: no image recorded for %s/%s:%s", stream.Namespace, stream.Name, tag)
continue
}
glog.V(4).Infof("Found ImageStream %s/%s with tag %s", stream.Namespace, stream.Name, tag)
// (must be different) to trigger a build
last := trigger.ImageChange.LastTriggeredImageID
next := latest.DockerImageReference
if len(last) == 0 || (len(next) > 0 && next != last) {
triggeredImage = next
shouldBuild = true
// it doesn't really make sense to have multiple image change triggers any more,
// so just exit the loop now
break
}
}
if shouldBuild {
glog.V(4).Infof("Running build for BuildConfig %s/%s", config.Namespace, config.Name)
buildCauses := []buildapi.BuildTriggerCause{}
// instantiate new build
request := &buildapi.BuildRequest{
ObjectMeta: kapi.ObjectMeta{
Name: config.Name,
Namespace: config.Namespace,
},
TriggeredBy: append(buildCauses,
buildapi.BuildTriggerCause{
Message: "Image change",
ImageChangeBuild: &buildapi.ImageChangeCause{
ImageID: latest.DockerImageReference,
FromRef: from,
},
},
),
TriggeredByImage: &kapi.ObjectReference{
Kind: "DockerImage",
Name: triggeredImage,
},
//.........这里部分代码省略.........
开发者ID:pweil-,项目名称:origin,代码行数:101,代码来源:image_change_controller.go
示例11: generateBuildFromConfig
// generateBuildFromConfig generates a build definition based on the current imageid
// from any ImageStream that is associated to the BuildConfig by From reference in
// the Strategy, or uses the Image field of the Strategy. If binary is provided, override
// the current build strategy with a binary artifact for this specific build.
// Takes a BuildConfig to base the build on, and an optional SourceRevision to build.
func (g *BuildGenerator) generateBuildFromConfig(ctx kapi.Context, bc *buildapi.BuildConfig, revision *buildapi.SourceRevision, binary *buildapi.BinaryBuildSource) (*buildapi.Build, error) {
serviceAccount := bc.Spec.ServiceAccount
if len(serviceAccount) == 0 {
serviceAccount = g.DefaultServiceAccountName
}
if len(serviceAccount) == 0 {
serviceAccount = bootstrappolicy.BuilderServiceAccountName
}
// Need to copy the buildConfig here so that it doesn't share pointers with
// the build object which could be (will be) modified later.
obj, _ := kapi.Scheme.Copy(bc)
bcCopy := obj.(*buildapi.BuildConfig)
build := &buildapi.Build{
Spec: buildapi.BuildSpec{
CommonSpec: buildapi.CommonSpec{
ServiceAccount: serviceAccount,
Source: bcCopy.Spec.Source,
Strategy: bcCopy.Spec.Strategy,
Output: bcCopy.Spec.Output,
Revision: revision,
Resources: bcCopy.Spec.Resources,
PostCommit: bcCopy.Spec.PostCommit,
CompletionDeadlineSeconds: bcCopy.Spec.CompletionDeadlineSeconds,
},
},
ObjectMeta: kapi.ObjectMeta{
Labels: bcCopy.Labels,
},
Status: buildapi.BuildStatus{
Phase: buildapi.BuildPhaseNew,
Config: &kapi.ObjectReference{
Kind: "BuildConfig",
Name: bc.Name,
Namespace: bc.Namespace,
},
},
}
if binary != nil {
build.Spec.Source.Git = nil
build.Spec.Source.Binary = binary
if build.Spec.Source.Dockerfile != nil && binary.AsFile == "Dockerfile" {
build.Spec.Source.Dockerfile = nil
}
} else {
// must explicitly set this because we copied the source values from the buildconfig.
build.Spec.Source.Binary = nil
}
build.Name = getNextBuildName(bc)
if build.Annotations == nil {
build.Annotations = make(map[string]string)
}
build.Annotations[buildapi.BuildNumberAnnotation] = strconv.FormatInt(bc.Status.LastVersion, 10)
build.Annotations[buildapi.BuildConfigAnnotation] = bcCopy.Name
if build.Labels == nil {
build.Labels = make(map[string]string)
}
build.Labels[buildapi.BuildConfigLabelDeprecated] = buildapi.LabelValue(bcCopy.Name)
build.Labels[buildapi.BuildConfigLabel] = buildapi.LabelValue(bcCopy.Name)
build.Labels[buildapi.BuildRunPolicyLabel] = string(bc.Spec.RunPolicy)
builderSecrets, err := g.FetchServiceAccountSecrets(bc.Namespace, serviceAccount)
if err != nil {
return nil, err
}
if build.Spec.Output.PushSecret == nil {
build.Spec.Output.PushSecret = g.resolveImageSecret(ctx, builderSecrets, build.Spec.Output.To, bc.Namespace)
}
strategyImageChangeTrigger := getStrategyImageChangeTrigger(bc)
// Resolve image source if present
for i, sourceImage := range build.Spec.Source.Images {
if sourceImage.PullSecret == nil {
sourceImage.PullSecret = g.resolveImageSecret(ctx, builderSecrets, &sourceImage.From, bc.Namespace)
}
var sourceImageSpec string
// if the imagesource matches the strategy from, and we have a trigger for the strategy from,
// use the imageid from the trigger rather than resolving it.
if strategyFrom := buildutil.GetInputReference(bc.Spec.Strategy); reflect.DeepEqual(sourceImage.From, *strategyFrom) &&
strategyImageChangeTrigger != nil {
sourceImageSpec = strategyImageChangeTrigger.LastTriggeredImageID
} else {
refImageChangeTrigger := getImageChangeTriggerForRef(bc, &sourceImage.From)
// if there is no trigger associated with this imagesource, resolve the imagesource reference now.
// otherwise use the imageid from the imagesource trigger.
if refImageChangeTrigger == nil {
sourceImageSpec, err = g.resolveImageStreamReference(ctx, sourceImage.From, bc.Namespace)
if err != nil {
return nil, err
}
} else {
sourceImageSpec = refImageChangeTrigger.LastTriggeredImageID
}
}
//.........这里部分代码省略.........
开发者ID:abhgupta,项目名称:origin,代码行数:101,代码来源:generator.go
示例12: TestInstantiateWithImageTrigger
//.........这里部分代码省略.........
},
{
name: "trigger with from",
reqFrom: &kapi.ObjectReference{
Kind: "ImageStreamTag",
Name: "image1:tag1",
},
triggerIndex: 2,
triggers: defaultTriggers(),
},
{
name: "trigger with from and namespace",
reqFrom: &kapi.ObjectReference{
Kind: "ImageStreamTag",
Name: "image2:tag2",
Namespace: "image2ns",
},
triggerIndex: 3,
triggers: defaultTriggers(),
},
{
name: "existing image id",
reqFrom: &kapi.ObjectReference{
Kind: "ImageStreamTag",
Name: "image1:tag1",
},
triggers: triggersWithImageID(),
errorExpected: true,
},
}
for _, tc := range tests {
bc := &buildapi.BuildConfig{
Spec: buildapi.BuildConfigSpec{
BuildSpec: buildapi.BuildSpec{
Strategy: buildapi.BuildStrategy{
SourceStrategy: &buildapi.SourceBuildStrategy{
From: kapi.ObjectReference{
Name: "image3:tag3",
Kind: "ImageStreamTag",
},
},
},
},
Triggers: tc.triggers,
},
}
generator := mockBuildGeneratorForInstantiate()
client := generator.Client.(Client)
client.GetBuildConfigFunc =
func(ctx kapi.Context, name string) (*buildapi.BuildConfig, error) {
return bc, nil
}
client.UpdateBuildConfigFunc =
func(ctx kapi.Context, buildConfig *buildapi.BuildConfig) error {
bc = buildConfig
return nil
}
generator.Client = client
req := &buildapi.BuildRequest{
TriggeredByImage: &kapi.ObjectReference{
Kind: "DockerImage",
Name: imageID,
},
From: tc.reqFrom,
}
_, err := generator.Instantiate(kapi.NewDefaultContext(), req)
if err != nil && !tc.errorExpected {
t.Errorf("%s: unexpected error %v", tc.name, err)
continue
}
if err == nil && tc.errorExpected {
t.Errorf("%s: expected error but didn't get one", tc.name)
continue
}
if tc.errorExpected {
continue
}
for i := range bc.Spec.Triggers {
if i == tc.triggerIndex {
// Verify that the trigger got updated
if bc.Spec.Triggers[i].ImageChange.LastTriggeredImageID != imageID {
t.Errorf("%s: expeccted trigger at index %d to contain imageID %s", tc.name, i, imageID)
}
continue
}
// Ensure that other triggers are updated with the latest docker image ref
if bc.Spec.Triggers[i].Type == buildapi.ImageChangeBuildTriggerType {
from := bc.Spec.Triggers[i].ImageChange.From
if from == nil {
from = buildutil.GetInputReference(bc.Spec.Strategy)
}
if bc.Spec.Triggers[i].ImageChange.LastTriggeredImageID != ("[email protected]" + from.Name) {
t.Errorf("%s: expected LastTriggeredImageID for trigger at %d to be %s. Got: %s", tc.name, i, "[email protected]"+from.Name, bc.Spec.Triggers[i].ImageChange.LastTriggeredImageID)
}
}
}
}
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:101,代码来源:generator_test.go
注:本文中的github.com/openshift/origin/pkg/build/util.GetInputReference函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论