Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly handle object creation error in template instantiate #21704

Merged
merged 1 commit into from Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
coreydaley marked this conversation as resolved.
Show resolved Hide resolved
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