Skip to content

Commit 878012b

Browse files
author
Jan Wozniak
committed
WIP: simple BC test only
1 parent 464544f commit 878012b

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

pkg/oc/cli/cmd/newapp.go

+19-30
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2222
"k8s.io/apimachinery/pkg/runtime"
23-
"k8s.io/apimachinery/pkg/runtime/schema"
2423
"k8s.io/apimachinery/pkg/util/errors"
2524
"k8s.io/apimachinery/pkg/util/sets"
2625
"k8s.io/apimachinery/pkg/util/wait"
@@ -156,41 +155,33 @@ type NewAppOptions struct {
156155
*ObjectGeneratorOptions
157156
}
158157

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+
160172
resources, err := discoveryClient.ServerResources()
161173
if err != nil {
162174
return fmt.Errorf("Unable to to get list of available resources: %v", err)
163175
}
164176

165-
resourceMap := make(map[schema.GroupVersionKind]bool)
166177
for _, resourceList := range resources {
167178
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
172181
}
173-
resourceMap[gvk] = true
174182
}
175183
}
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")
194185
}
195186

196187
//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
223214
return err
224215
}
225216

226-
mapper, typer := f.Object()
227-
228-
discoveryClient, err := f.DiscoveryClient()
217+
discoveryClient, err := discovery.NewDiscoveryClientForConfig(clientConfig)
229218
if err != nil {
230219
return fmt.Errorf("Unable to validate if required resources are available: %v", err)
231220
}
@@ -354,7 +343,7 @@ func (o *NewAppOptions) RunNewApp() error {
354343
if err := handleError(err, o.BaseName, o.CommandName, o.CommandPath, config, transformRunError); err != nil {
355344
return err
356345
}
357-
if err := checkResources(config.DiscoveryClient, result.List.Items); err != nil {
346+
if err := checkBuildEnabled(config.DiscoveryClient, result.List.Items); err != nil {
358347
return err
359348
}
360349

0 commit comments

Comments
 (0)