-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
properly handle object creation error in template instantiate
- Loading branch information
Showing
4 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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" | ||
) | ||
|
||
// ensure that template instantiation waits for annotated objects | ||
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_objectkinds.yaml") | ||
template *templatev1.Template | ||
templateinstance *templatev1.TemplateInstance | ||
) | ||
|
||
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()) | ||
|
||
err = cli.Run("create").Args("-f", templatefixture).Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
template, err = cli.TemplateClient().TemplateV1().Templates(cli.Namespace()).Get("invalidtemplateinstance", metav1.GetOptions{}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
}) | ||
|
||
g.AfterEach(func() { | ||
if g.CurrentGinkgoTestDescription().Failed { | ||
exutil.DumpPodStates(cli) | ||
exutil.DumpConfigMapStates(cli) | ||
exutil.DumpPodLogsStartingWith("", cli) | ||
} | ||
}) | ||
|
||
g.It("should report report a failure on creation", func() { | ||
var err error | ||
|
||
templateinstance = &templatev1.TemplateInstance{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "invalidtemplateinstance", | ||
}, | ||
Spec: templatev1.TemplateInstanceSpec{ | ||
Template: *template, | ||
}, | ||
} | ||
|
||
g.By("instantiating the invalid templateinstance") | ||
templateinstance, err = cli.TemplateClient().TemplateV1().TemplateInstances(cli.Namespace()).Create(templateinstance) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
g.By("waiting for error to appear") | ||
err = wait.Poll(time.Second, 1*time.Minute, func() (bool, error) { | ||
templateinstance, err = cli.TemplateClient().TemplateV1().TemplateInstances(cli.Namespace()).Get(templateinstance.Name, 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()) | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
test/extended/testdata/templates/templateinstance_badobject.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
kind: List | ||
apiVersion: v1 | ||
items: | ||
- kind: TemplateInstance | ||
apiVersion: template.openshift.io/v1 | ||
metadata: | ||
name: templateinstance | ||
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 |