-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove build helpers from api packages
- Loading branch information
Showing
48 changed files
with
340 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package buildapihelpers | ||
|
||
import ( | ||
coreinternalapi "k8s.io/kubernetes/pkg/apis/core" | ||
|
||
buildinternalapi "github.com/openshift/origin/pkg/build/apis/build" | ||
) | ||
|
||
// BuildToPodLogOptions builds a PodLogOptions object out of a BuildLogOptions. | ||
// Currently BuildLogOptions.Container and BuildLogOptions.Previous aren't used | ||
// so they won't be copied to PodLogOptions. | ||
func BuildToPodLogOptions(opts *buildinternalapi.BuildLogOptions) *coreinternalapi.PodLogOptions { | ||
return &coreinternalapi.PodLogOptions{ | ||
Follow: opts.Follow, | ||
SinceSeconds: opts.SinceSeconds, | ||
SinceTime: opts.SinceTime, | ||
Timestamps: opts.Timestamps, | ||
TailLines: opts.TailLines, | ||
LimitBytes: opts.LimitBytes, | ||
} | ||
} | ||
|
||
// FindTriggerPolicy retrieves the BuildTrigger(s) of a given type from a build configuration. | ||
// Returns nil if no matches are found. | ||
func FindTriggerPolicy(triggerType buildinternalapi.BuildTriggerType, config *buildinternalapi.BuildConfig) (buildTriggers []buildinternalapi.BuildTriggerPolicy) { | ||
for _, specTrigger := range config.Spec.Triggers { | ||
if specTrigger.Type == triggerType { | ||
buildTriggers = append(buildTriggers, specTrigger) | ||
} | ||
} | ||
return buildTriggers | ||
} | ||
|
||
func HasTriggerType(triggerType buildinternalapi.BuildTriggerType, bc *buildinternalapi.BuildConfig) bool { | ||
matches := FindTriggerPolicy(triggerType, bc) | ||
return len(matches) > 0 | ||
} | ||
|
||
// GetInputReference returns the From ObjectReference associated with the | ||
// BuildStrategy. | ||
func GetInputReference(strategy buildinternalapi.BuildStrategy) *coreinternalapi.ObjectReference { | ||
switch { | ||
case strategy.SourceStrategy != nil: | ||
return &strategy.SourceStrategy.From | ||
case strategy.DockerStrategy != nil: | ||
return strategy.DockerStrategy.From | ||
case strategy.CustomStrategy != nil: | ||
return &strategy.CustomStrategy.From | ||
default: | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package buildapihelpers | ||
|
||
import buildinternalapi "github.com/openshift/origin/pkg/build/apis/build" | ||
|
||
// BuildSliceByCreationTimestamp implements sort.Interface for []Build | ||
// based on the CreationTimestamp field. | ||
type BuildSliceByCreationTimestamp []buildinternalapi.Build | ||
|
||
func (b BuildSliceByCreationTimestamp) Len() int { | ||
return len(b) | ||
} | ||
|
||
func (b BuildSliceByCreationTimestamp) Less(i, j int) bool { | ||
return b[i].CreationTimestamp.Before(&b[j].CreationTimestamp) | ||
} | ||
|
||
func (b BuildSliceByCreationTimestamp) Swap(i, j int) { | ||
b[i], b[j] = b[j], b[i] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package buildapihelpers | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
"time" | ||
|
||
buildinternalapi "github.com/openshift/origin/pkg/build/apis/build" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestSortBuildSliceByCreationTimestamp(t *testing.T) { | ||
present := metav1.Now() | ||
past := metav1.NewTime(present.Add(-time.Minute)) | ||
builds := []buildinternalapi.Build{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "present", | ||
CreationTimestamp: present, | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "past", | ||
CreationTimestamp: past, | ||
}, | ||
}, | ||
} | ||
sort.Sort(BuildSliceByCreationTimestamp(builds)) | ||
if [2]string{builds[0].Name, builds[1].Name} != [2]string{"past", "present"} { | ||
t.Errorf("Unexpected sort order") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package buildapihelpers | ||
|
||
import ( | ||
"testing" | ||
|
||
buildinternalapi "github.com/openshift/origin/pkg/build/apis/build" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestGetBuildPodName(t *testing.T) { | ||
if expected, actual := "mybuild-build", GetBuildPodName(&buildinternalapi.Build{ObjectMeta: metav1.ObjectMeta{Name: "mybuild"}}); expected != actual { | ||
t.Errorf("Expected %s, got %s", expected, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.