@@ -20,7 +20,6 @@ import (
20
20
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
21
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
22
22
"k8s.io/apimachinery/pkg/runtime"
23
- "k8s.io/apimachinery/pkg/runtime/schema"
24
23
"k8s.io/apimachinery/pkg/util/errors"
25
24
"k8s.io/apimachinery/pkg/util/sets"
26
25
"k8s.io/apimachinery/pkg/util/wait"
@@ -156,41 +155,33 @@ type NewAppOptions struct {
156
155
* ObjectGeneratorOptions
157
156
}
158
157
159
- func checkResources (discoveryClient discovery.DiscoveryInterface , items []runtime.Object ) error {
158
+ func checkBuildEnabled (discoveryClient discovery.DiscoveryInterface , items []runtime.Object ) error {
159
+ hasBC := false
160
+ ItemsLoop:
161
+ for _ , item := range items {
162
+ switch item .(type ) {
163
+ case * buildapi.BuildConfig :
164
+ hasBC = true
165
+ break ItemsLoop
166
+ }
167
+ }
168
+ if ! hasBC {
169
+ return nil
170
+ }
171
+
160
172
resources , err := discoveryClient .ServerResources ()
161
173
if err != nil {
162
174
return fmt .Errorf ("Unable to to get list of available resources: %v" , err )
163
175
}
164
176
165
- resourceMap := make (map [schema.GroupVersionKind ]bool )
166
177
for _ , resourceList := range resources {
167
178
for _ , resource := range resourceList .APIResources {
168
- gvk := schema.GroupVersionKind {
169
- Group : resource .Group ,
170
- Version : resource .Version ,
171
- Kind : resource .Kind ,
179
+ if resource .Kind == "BuildConfig" {
180
+ return nil
172
181
}
173
- resourceMap [gvk ] = true
174
182
}
175
183
}
176
-
177
- declaredResources := make (map [schema.GroupVersionKind ]bool )
178
- for _ , item := range items {
179
- declaredResources [item .GetObjectKind ().GroupVersionKind ()] = true
180
- }
181
- missingResources := make ([]string , 0 )
182
- for r , _ := range declaredResources {
183
- if present := resourceMap [r ]; ! present {
184
- missingResources = append (missingResources , r .String ())
185
- }
186
- }
187
-
188
- if len (missingResources ) > 0 {
189
- //TODO: ideally here it would have failed but iterating over items makes it to always fail
190
- // with "error: Missing declared resources: /, Kind="
191
- //return fmt.Errorf("Missing declared resources: %v", strings.Join(missingResources, `, `))
192
- }
193
- return nil
184
+ return fmt .Errorf ("Missing BuildConfig, enable Build API" )
194
185
}
195
186
196
187
//Complete sets all common default options for commands (new-app and new-build)
@@ -223,9 +214,7 @@ func (o *ObjectGeneratorOptions) Complete(baseName, commandName string, f kcmdut
223
214
return err
224
215
}
225
216
226
- mapper , typer := f .Object ()
227
-
228
- discoveryClient , err := f .DiscoveryClient ()
217
+ discoveryClient , err := discovery .NewDiscoveryClientForConfig (clientConfig )
229
218
if err != nil {
230
219
return fmt .Errorf ("Unable to validate if required resources are available: %v" , err )
231
220
}
@@ -354,7 +343,7 @@ func (o *NewAppOptions) RunNewApp() error {
354
343
if err := handleError (err , o .BaseName , o .CommandName , o .CommandPath , config , transformRunError ); err != nil {
355
344
return err
356
345
}
357
- if err := checkResources (config .DiscoveryClient , result .List .Items ); err != nil {
346
+ if err := checkBuildEnabled (config .DiscoveryClient , result .List .Items ); err != nil {
358
347
return err
359
348
}
360
349
0 commit comments