Skip to content

Commit

Permalink
0.3.5: Improved error handling on mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
sebt3 committed Jun 18, 2024
1 parent 7a0ead8 commit 87a0e88
Show file tree
Hide file tree
Showing 59 changed files with 46,478 additions and 18,443 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
/front/pages/**/*.vue
!/front/pages/core/*.vue
!/front/pages/install/vynil/InstallNew.vue
core
1 change: 1 addition & 0 deletions back/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const typeDefs = gqlWrapper(
importGraphQL('operators.graphql'),
importGraphQL('whereabouts.graphql'),
importGraphQL('kubevirt.graphql'),
importGraphQL('kuberest.graphql'),
importGraphQL('networkaddonsoperator.graphql'),
);

Expand Down
24 changes: 12 additions & 12 deletions back/resolvers/core/CrdObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ export const mutations = {
}
try {
const res = await k8sApi.createClusterCustomObject(args['group'],args['version'],args['plural'], payload)
return res.body
return {object: res.body}
} catch (err) {
if (typeof err === 'object' && (err as object)['body'] !=undefined && (err as object)['statusCode'] !=undefined) {
if ((err as object)['statusCode'] != 404 && (err as object)['body']['reason']!='Forbidden') {
log.error('error', (err as object)['body']);
}
} else {log.error('error', err)}
if (typeof err === 'object') return {error: err}; else return {error: {err}}
}
return null
},
clusteredCrdObjectDelete: async (_parent, args: object) => {
try {
const res = await k8sApi.deleteClusterCustomObject(args['group'],args['version'],args['plural'], args['name'])
return res.body
return {object: res.body}
} catch (err) {
if (typeof err === 'object' && (err as object)['body'] !=undefined && (err as object)['statusCode'] !=undefined) {
if ((err as object)['statusCode'] != 404 && (err as object)['body']['reason']!='Forbidden') {
log.error('error', (err as object)['body']);
}
} else {log.error('error', err)}
if (typeof err === 'object') return {error: err}; else return {error: {err}}
}
return null
},
clusteredCrdObjectPatch: async (_parent, args: object) => {
const request = {
Expand All @@ -50,15 +50,15 @@ export const mutations = {
const payload = rfc6902.createPatch(resGet.body,request).filter(rule => !rule.path.startsWith('/status') && !['/metadata/creationTimestamp', '/metadata/finalizers', '/metadata/generation', '/metadata/managedFields', '/metadata/resourceVersion','/metadata/uid'].includes(rule.path) )
const options = { "headers": { "Content-type": k8s.PatchUtils.PATCH_FORMAT_JSON_PATCH}};
const res = await k8sApi.patchClusterCustomObject(args['group'],args['version'],args['plural'], args['metadata']['name'], payload, undefined, undefined, undefined, options)
return res.body
return {object: res.body}
} catch (err) {
if (typeof err === 'object' && (err as object)['body'] !=undefined && (err as object)['statusCode'] !=undefined) {
if ((err as object)['statusCode'] != 404 && (err as object)['body']['reason']!='Forbidden') {
log.error('error', (err as object)['body']);
}
} else {log.error('error', err)}
if (typeof err === 'object') return {error: err}; else return {error: {err}}
}
return null
},
namespacedCrdObjectCreate: async (_parent, args: object) => {
const payload = {
Expand All @@ -69,28 +69,28 @@ export const mutations = {
}
try {
const res = await k8sApi.createNamespacedCustomObject(args['group'],args['version'],args['metadata']['namespace'],args['plural'], payload)
return res.body
return {object: res.body}
} catch (err) {
if (typeof err === 'object' && (err as object)['body'] !=undefined && (err as object)['statusCode'] !=undefined) {
if ((err as object)['statusCode'] != 404 && (err as object)['body']['reason']!='Forbidden') {
log.error('error', (err as object)['body']);
}
} else {log.error('error', err)}
if (typeof err === 'object') return {error: err}; else return {error: {err}}
}
return null
},
namespacedCrdObjectDelete: async (_parent, args: object) => {
try {
const res = await k8sApi.deleteNamespacedCustomObject(args['group'],args['version'],args['namespace'],args['plural'], args['name'])
return res.body
return {object: res.body}
} catch (err) {
if (typeof err === 'object' && (err as object)['body'] !=undefined && (err as object)['statusCode'] !=undefined) {
if ((err as object)['statusCode'] != 404 && (err as object)['body']['reason']!='Forbidden') {
log.error('error', (err as object)['body']);
}
} else {log.error('error', err)}
if (typeof err === 'object') return {error: err}; else return {error: {err}}
}
return null
},
namespacedCrdObjectPatch: async (_parent, args: object) => {
const request = {
Expand All @@ -105,15 +105,15 @@ export const mutations = {
const payload = rfc6902.createPatch(resGet.body,request).filter(rule => !rule.path.startsWith('/status') && !['/metadata/creationTimestamp', '/metadata/finalizers', '/metadata/generation', '/metadata/managedFields', '/metadata/resourceVersion','/metadata/uid'].includes(rule.path) )
const options = { "headers": { "Content-type": k8s.PatchUtils.PATCH_FORMAT_JSON_PATCH}};
const res = await k8sApi.patchNamespacedCustomObject(args['group'],args['version'],args['metadata']['namespace'],args['plural'], args['metadata']['name'], payload, undefined, undefined, undefined, options)
return res.body
return {object: res.body}
} catch (err) {
if (typeof err === 'object' && (err as object)['body'] !=undefined && (err as object)['statusCode'] !=undefined) {
if ((err as object)['statusCode'] != 404 && (err as object)['body']['reason']!='Forbidden') {
log.error('error', (err as object)['body']);
}
} else {log.error('error', err)}
if (typeof err === 'object') return {error: err}; else return {error: {err}}
}
return null
},
};
export const lists = {
Expand Down
20 changes: 12 additions & 8 deletions back/schema/core.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ input metadataInput {
resourceVersion: String
uid: String
}
type ownerReference {
type ownerRef {
apiVersion: String!
blockOwnerDeletion: Boolean
controller: Boolean
Expand All @@ -71,7 +71,7 @@ type metadata {
annotations: JSONObject
labels: JSONObject
creationTimestamp: String
ownerReferences: [ownerReference]
ownerReferences: [ownerRef]
resourceVersion: String
uid: String
}
Expand Down Expand Up @@ -176,13 +176,17 @@ type Query {
vynilCategory(params: queryParameters): [vynilCategory]
vynilPackage(params: queryParameters): [vynilPackage]
}
type MutationResponse {
object: JSONObject
error: JSONObject
}
type Mutation {
namespacedCrdObjectCreate(group: String!, version: String!, plural: String!, kind: String!, metadata: metadataInput!, spec: JSONObject): coreCrdObject
namespacedCrdObjectPatch(group: String!, version: String!, plural: String!, kind: String!, metadata: metadataInput!, spec: JSONObject): coreCrdObject
namespacedCrdObjectDelete(group: String!, version: String!, plural: String!, namespace: String!, name: String!): coreCrdObject
clusteredCrdObjectCreate(group: String!, version: String!, plural: String!, kind: String!, metadata: metadataInput!, spec: JSONObject): coreCrdObject
clusteredCrdObjectPatch(group: String!, version: String!, plural: String!, kind: String!, metadata: metadataInput!, spec: JSONObject): coreCrdObject
clusteredCrdObjectDelete(group: String!, version: String!, plural: String!, name: String!): coreCrdObject
namespacedCrdObjectCreate(group: String!, version: String!, plural: String!, kind: String!, metadata: metadataInput!, spec: JSONObject): MutationResponse
namespacedCrdObjectPatch(group: String!, version: String!, plural: String!, kind: String!, metadata: metadataInput!, spec: JSONObject): MutationResponse
namespacedCrdObjectDelete(group: String!, version: String!, plural: String!, namespace: String!, name: String!): MutationResponse
clusteredCrdObjectCreate(group: String!, version: String!, plural: String!, kind: String!, metadata: metadataInput!, spec: JSONObject): MutationResponse
clusteredCrdObjectPatch(group: String!, version: String!, plural: String!, kind: String!, metadata: metadataInput!, spec: JSONObject): MutationResponse
clusteredCrdObjectDelete(group: String!, version: String!, plural: String!, name: String!): MutationResponse
}
type Subscription {
onLog(namespace: String!,pod_name: String!,name: String!): coreLog
Expand Down
Loading

0 comments on commit 87a0e88

Please sign in to comment.