Skip to content

Error Handling for Creating Operator Custom Resources with Invalid Templates #1171

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ describe(CreateCRDYAML.displayName, () => {
expect(createYAML.props().template).toEqual(safeDump(testResourceInstance));
});

it('handles invalid JSON example object on annotation', () => {
const data = _.cloneDeep(testClusterServiceVersion);
data.metadata.annotations = {'alm-examples': 'invalid === true'};
wrapper = wrapper.setProps({ClusterServiceVersion: {loaded: true, data}} as any);

const createYAML = wrapper.find(Firehose).childAt(0).dive<CreateYAMLProps, {}>();

expect(createYAML.props().template).toEqual(null);
});

it('does not render YAML editor component if ClusterServiceVersion has not loaded yet', () => {
wrapper = wrapper.setProps({ClusterServiceVersion: {loaded: false}} as any);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ export const CreateCRDYAML: React.SFC<CreateCRDYAMLProps> = (props) => {

const Create = (createProps: {ClusterServiceVersion: {loaded: boolean, data: ClusterServiceVersionKind}}) => {
if (createProps.ClusterServiceVersion.loaded && createProps.ClusterServiceVersion.data) {
const templates = _.get(createProps.ClusterServiceVersion.data.metadata.annotations, annotationKey, '[]');
const templateObj = (JSON.parse(templates) as K8sResourceKind[])
.find(obj => referenceFor(obj) === props.match.params.plural);
const template = templateObj ? _.attempt(() => safeDump(templateObj)) : null;
const templatesJSON = _.get(createProps.ClusterServiceVersion.data.metadata.annotations, annotationKey, '[]');
const template = _.attempt(() => safeDump((JSON.parse(templatesJSON) as K8sResourceKind[]).find(obj => referenceFor(obj) === props.match.params.plural)));
if (_.isError(template)) {
// eslint-disable-next-line no-console
console.error('Error parsing example JSON from annotation. Falling back to default.');
}

return <CreateYAML {...props as any} template={!_.isError(template) ? template : null} />;
}
Expand Down