Skip to content

Commit

Permalink
Merge pull request #21704 from bparees/instancefail
Browse files Browse the repository at this point in the history
properly handle object creation error in template instantiate
  • Loading branch information
openshift-merge-robot committed Dec 26, 2018
2 parents 85a0623 + 0b08b1c commit 23c8cff
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/template/controller/templateinstance_controller.go
Expand Up @@ -501,7 +501,7 @@ func (c *TemplateInstanceController) instantiate(templateInstance *templatev1.Te
}
}
if createErr != nil {
allErrors = append(allErrors, mappingErr)
allErrors = append(allErrors, createErr)
continue
}

Expand Down
56 changes: 56 additions & 0 deletions test/extended/templates/templateinstance_fail.go
@@ -0,0 +1,56 @@
package templates

import (
"fmt"
"time"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

templatev1 "github.com/openshift/api/template/v1"
templatecontroller "github.com/openshift/origin/pkg/template/controller"
exutil "github.com/openshift/origin/test/extended/util"
)

var _ = g.Describe("[Conformance][templates] templateinstance creation with invalid object reports error", func() {
defer g.GinkgoRecover()

var (
cli = exutil.NewCLI("templates", exutil.KubeConfigPath())
templatefixture = exutil.FixturePath("testdata", "templates", "templateinstance_badobject.yaml")
)

g.Context("", func() {
g.BeforeEach(func() {
g.By("waiting for default service account")
err := exutil.WaitForServiceAccount(cli.KubeClient().Core().ServiceAccounts(cli.Namespace()), "default")
o.Expect(err).NotTo(o.HaveOccurred())
})

g.It("should report a failure on creation", func() {
err := cli.Run("create").Args("-f", templatefixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("waiting for error to appear")
var templateinstance *templatev1.TemplateInstance
err = wait.Poll(time.Second, 1*time.Minute, func() (bool, error) {
templateinstance, err = cli.TemplateClient().TemplateV1().TemplateInstances(cli.Namespace()).Get("invalidtemplateinstance", metav1.GetOptions{})
if err != nil {
return false, err
}
if templatecontroller.TemplateInstanceHasCondition(templateinstance, templatev1.TemplateInstanceInstantiateFailure, corev1.ConditionTrue) {
return true, nil
}
return false, nil
})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "error waiting for instantiate failure: %v\n%#v", err, templateinstance)
}
o.Expect(err).NotTo(o.HaveOccurred())
})
})
})
51 changes: 51 additions & 0 deletions test/extended/testdata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions test/extended/testdata/templates/templateinstance_badobject.yaml
@@ -0,0 +1,31 @@
kind: List
apiVersion: v1
items:
- kind: TemplateInstance
apiVersion: template.openshift.io/v1
metadata:
name: invalidtemplateinstance
spec:
template:
kind: Template
apiVersion: v1
metadata:
name: template
objects:
- kind: Deployment
apiVersion: apps/v1
metadata:
name: "invalidname!@#$%^&*"
spec:
replicas: 0
selector:
matchLabels:
key: value
template:
metadata:
labels:
key: value
spec:
containers:
- name: hello-openshift
image: openshift/hello-openshift

0 comments on commit 23c8cff

Please sign in to comment.