@@ -11,37 +11,34 @@ import (
11
11
"github.com/golang/glog"
12
12
"k8s.io/kubernetes/pkg/api/legacyscheme"
13
13
14
- "k8s.io/apimachinery/pkg/api/errors"
15
14
"k8s.io/apimachinery/pkg/runtime"
16
- "k8s.io/apimachinery/pkg/runtime/schema"
17
15
restclient "k8s.io/client-go/rest"
18
16
19
17
s2iapi "github.com/openshift/source-to-image/pkg/api"
20
18
s2igit "github.com/openshift/source-to-image/pkg/scm/git"
21
19
22
- buildapi "github.com/openshift/origin/pkg/ build/apis/build "
23
- "github.com/openshift/origin/pkg/ build/apis/ build/validation "
20
+ buildapiv1 "github.com/openshift/api/ build/v1 "
21
+ buildclientv1 "github.com/openshift/client-go/ build/clientset/versioned/typed/ build/v1 "
24
22
bld "github.com/openshift/origin/pkg/build/builder"
25
23
"github.com/openshift/origin/pkg/build/builder/cmd/scmauth"
26
24
"github.com/openshift/origin/pkg/build/builder/timing"
27
- buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset"
28
- buildinternalversion "github.com/openshift/origin/pkg/build/generated/internalclientset/typed/build/internalversion"
25
+ builderutil "github.com/openshift/origin/pkg/build/builder/util"
29
26
buildutil "github.com/openshift/origin/pkg/build/util"
30
27
"github.com/openshift/origin/pkg/generate/git"
31
28
"github.com/openshift/origin/pkg/version"
32
29
)
33
30
34
31
type builder interface {
35
- Build (dockerClient bld.DockerClient , sock string , buildsClient buildinternalversion. BuildResourceInterface , build * buildapi .Build , cgLimits * s2iapi.CGroupLimits ) error
32
+ Build (dockerClient bld.DockerClient , sock string , buildsClient buildclientv1. BuildInterface , build * buildapiv1 .Build , cgLimits * s2iapi.CGroupLimits ) error
36
33
}
37
34
38
35
type builderConfig struct {
39
36
out io.Writer
40
- build * buildapi .Build
37
+ build * buildapiv1 .Build
41
38
sourceSecretDir string
42
39
dockerClient * docker.Client
43
40
dockerEndpoint string
44
- buildsClient buildinternalversion. BuildResourceInterface
41
+ buildsClient buildclientv1. BuildInterface
45
42
}
46
43
47
44
func newBuilderConfigFromEnvironment (out io.Writer , needsDocker bool ) (* builderConfig , error ) {
@@ -51,16 +48,17 @@ func newBuilderConfigFromEnvironment(out io.Writer, needsDocker bool) (*builderC
51
48
cfg .out = out
52
49
53
50
buildStr := os .Getenv ("BUILD" )
54
- cfg .build = & buildapi.Build {}
55
51
56
- obj , groupVersionKind , err := legacyscheme .Codecs .UniversalDecoder ().Decode ([]byte (buildStr ), nil , nil )
52
+ cfg .build = & buildapiv1.Build {}
53
+
54
+ obj , groupVersionKind , err := legacyscheme .Codecs .UniversalDecoder ().Decode ([]byte (buildStr ), nil , cfg .build )
57
55
if err != nil {
58
56
return nil , fmt .Errorf ("unable to parse build string: %v" , err )
59
57
}
60
58
ok := false
61
- cfg .build , ok = obj .(* buildapi .Build )
59
+ cfg .build , ok = obj .(* buildapiv1 .Build )
62
60
if ! ok {
63
- return nil , fmt .Errorf ("build string is not a build: %v" , err )
61
+ return nil , fmt .Errorf ("build string %s is not a build: %# v" , buildStr , obj )
64
62
}
65
63
if glog .V (4 ) {
66
64
redactedBuild := buildutil .SafeForLoggingBuild (cfg .build )
@@ -73,11 +71,8 @@ func newBuilderConfigFromEnvironment(out io.Writer, needsDocker bool) (*builderC
73
71
}
74
72
glog .V (4 ).Infof ("redacted build: %v" , string (bytes ))
75
73
}
76
- if errs := validation .ValidateBuild (cfg .build ); len (errs ) > 0 {
77
- return nil , errors .NewInvalid (schema.GroupKind {Kind : "Build" }, cfg .build .Name , errs )
78
- }
79
74
80
- masterVersion := os .Getenv (buildapi .OriginVersion )
75
+ masterVersion := os .Getenv (builderutil .OriginVersion )
81
76
thisVersion := version .Get ().String ()
82
77
if len (masterVersion ) != 0 && masterVersion != thisVersion {
83
78
glog .V (3 ).Infof ("warning: OpenShift server version %q differs from this image %q\n " , masterVersion , thisVersion )
@@ -102,11 +97,11 @@ func newBuilderConfigFromEnvironment(out io.Writer, needsDocker bool) (*builderC
102
97
if err != nil {
103
98
return nil , fmt .Errorf ("cannot connect to the server: %v" , err )
104
99
}
105
- buildsClient , err := buildclient .NewForConfig (clientConfig )
100
+ buildsClient , err := buildclientv1 .NewForConfig (clientConfig )
106
101
if err != nil {
107
102
return nil , fmt .Errorf ("failed to get client: %v" , err )
108
103
}
109
- cfg .buildsClient = buildsClient .Build (). Builds (cfg .build .Namespace )
104
+ cfg .buildsClient = buildsClient .Builds (cfg .build .Namespace )
110
105
111
106
return cfg , nil
112
107
}
@@ -158,7 +153,7 @@ func (c *builderConfig) setupGitEnvironment() (string, []string, error) {
158
153
// clone is responsible for cloning the source referenced in the buildconfig
159
154
func (c * builderConfig ) clone () error {
160
155
ctx := timing .NewContext (context .Background ())
161
- var sourceRev * buildapi .SourceRevision
156
+ var sourceRev * buildapiv1 .SourceRevision
162
157
defer func () {
163
158
c .build .Status .Stages = timing .GetStages (ctx )
164
159
bld .HandleBuildStatusUpdate (c .build , c .buildsClient , sourceRev )
@@ -174,9 +169,9 @@ func (c *builderConfig) clone() error {
174
169
buildDir := buildutil .InputContentPath
175
170
sourceInfo , err := bld .GitClone (ctx , gitClient , c .build .Spec .Source .Git , c .build .Spec .Revision , buildDir )
176
171
if err != nil {
177
- c .build .Status .Phase = buildapi .BuildPhaseFailed
178
- c .build .Status .Reason = buildapi .StatusReasonFetchSourceFailed
179
- c .build .Status .Message = buildapi .StatusMessageFetchSourceFailed
172
+ c .build .Status .Phase = buildapiv1 .BuildPhaseFailed
173
+ c .build .Status .Reason = buildapiv1 .StatusReasonFetchSourceFailed
174
+ c .build .Status .Message = builderutil .StatusMessageFetchSourceFailed
180
175
return err
181
176
}
182
177
@@ -186,18 +181,18 @@ func (c *builderConfig) clone() error {
186
181
187
182
err = bld .ExtractInputBinary (os .Stdin , c .build .Spec .Source .Binary , buildDir )
188
183
if err != nil {
189
- c .build .Status .Phase = buildapi .BuildPhaseFailed
190
- c .build .Status .Reason = buildapi .StatusReasonFetchSourceFailed
191
- c .build .Status .Message = buildapi .StatusMessageFetchSourceFailed
184
+ c .build .Status .Phase = buildapiv1 .BuildPhaseFailed
185
+ c .build .Status .Reason = buildapiv1 .StatusReasonFetchSourceFailed
186
+ c .build .Status .Message = builderutil .StatusMessageFetchSourceFailed
192
187
return err
193
188
}
194
189
195
190
if len (c .build .Spec .Source .ContextDir ) > 0 {
196
191
if _ , err := os .Stat (filepath .Join (buildDir , c .build .Spec .Source .ContextDir )); os .IsNotExist (err ) {
197
192
err = fmt .Errorf ("provided context directory does not exist: %s" , c .build .Spec .Source .ContextDir )
198
- c .build .Status .Phase = buildapi .BuildPhaseFailed
199
- c .build .Status .Reason = buildapi .StatusReasonInvalidContextDirectory
200
- c .build .Status .Message = buildapi .StatusMessageInvalidContextDirectory
193
+ c .build .Status .Phase = buildapiv1 .BuildPhaseFailed
194
+ c .build .Status .Reason = buildapiv1 .StatusReasonInvalidContextDirectory
195
+ c .build .Status .Message = builderutil .StatusMessageInvalidContextDirectory
201
196
return err
202
197
}
203
198
}
@@ -238,14 +233,14 @@ func (c *builderConfig) execute(b builder) error {
238
233
type dockerBuilder struct {}
239
234
240
235
// Build starts a Docker build.
241
- func (dockerBuilder ) Build (dockerClient bld.DockerClient , sock string , buildsClient buildinternalversion. BuildResourceInterface , build * buildapi .Build , cgLimits * s2iapi.CGroupLimits ) error {
236
+ func (dockerBuilder ) Build (dockerClient bld.DockerClient , sock string , buildsClient buildclientv1. BuildInterface , build * buildapiv1 .Build , cgLimits * s2iapi.CGroupLimits ) error {
242
237
return bld .NewDockerBuilder (dockerClient , buildsClient , build , cgLimits ).Build ()
243
238
}
244
239
245
240
type s2iBuilder struct {}
246
241
247
242
// Build starts an S2I build.
248
- func (s2iBuilder ) Build (dockerClient bld.DockerClient , sock string , buildsClient buildinternalversion. BuildResourceInterface , build * buildapi .Build , cgLimits * s2iapi.CGroupLimits ) error {
243
+ func (s2iBuilder ) Build (dockerClient bld.DockerClient , sock string , buildsClient buildclientv1. BuildInterface , build * buildapiv1 .Build , cgLimits * s2iapi.CGroupLimits ) error {
249
244
return bld .NewS2IBuilder (dockerClient , sock , buildsClient , build , cgLimits ).Build ()
250
245
}
251
246
0 commit comments