Fix Logging Output buffer YAML view

This commit is contained in:
Francesco Torchia 2024-10-21 19:24:04 +02:00
parent 0fcf630daa
commit c85a76a2d4
No known key found for this signature in database
GPG Key ID: E6D011B7415D4393

View File

@ -1,6 +1,6 @@
<script>
import CreateEditView from '@shell/mixins/create-edit-view';
import { SECRET, LOGGING, SCHEMA } from '@shell/config/types';
import { LOGGING, SCHEMA } from '@shell/config/types';
import Tabbed from '@shell/components/Tabbed';
import Tab from '@shell/components/Tabbed/Tab';
import CruResource from '@shell/components/CruResource';
@ -34,12 +34,43 @@ export default {
inheritAttrs: false,
async fetch() {
await this.$store.dispatch('harvester/findAll', { type: SECRET });
const schemas = this.$store.getters['harvester/all'](SCHEMA);
const resourceSchema = this.$store.getters['harvester/byId'](SCHEMA, LOGGING.OUTPUT);
const schemaDefinition = await resourceSchema.fetchResourceFields();
let bufferYaml = '';
if ( !isEmpty(this.value.spec[this.selectedProvider]?.buffer) ) {
bufferYaml = jsyaml.dump(this.value.spec[this.selectedProvider].buffer);
} else if (schemaDefinition) {
bufferYaml = createYaml(
schemas,
`io.banzaicloud.logging.v1beta1.Output.spec.${ this.selectedProvider }.buffer`,
{},
true,
1,
'',
LOGGING.OUTPUT
);
// createYaml doesn't support passing reference types (array, map) as the first type. As such
// I'm manipulating the output since I'm not sure it's something we want to actually support
// seeing as it's really createResourceYaml and this here is a gray area between spoofed types
// and just a field within a spec.
bufferYaml = bufferYaml.substring(bufferYaml.indexOf('\n') + 1).replace(/# {2}/g, '#');
}
if (bufferYaml.length) {
this.bufferYaml = bufferYaml;
this.initialBufferYaml = bufferYaml;
this.$refs.yaml.updateValue(this.bufferYaml);
}
},
data() {
const schemas = this.$store.getters['harvester/all'](SCHEMA);
if (this.isCreate) {
this.value.metadata.namespace = 'default';
}
@ -69,22 +100,9 @@ export default {
const selectedProvider = selectedProviders?.[0]?.value || providers[0].value;
let bufferYaml;
if ( !isEmpty(this.value.spec[selectedProvider]?.buffer) ) {
bufferYaml = jsyaml.dump(this.value.spec[selectedProvider].buffer);
} else {
bufferYaml = createYaml(schemas, `logging.banzaicloud.io.v1beta1.output.spec.${ selectedProvider }.buffer`, []);
// createYaml doesn't support passing reference types (array, map) as the first type. As such
// I'm manipulating the output since I'm not sure it's something we want to actually support
// seeing as it's really createResourceYaml and this here is a gray area between spoofed types
// and just a field within a spec.
bufferYaml = bufferYaml.substring(bufferYaml.indexOf('\n') + 1).replaceAll('# ', '#');
}
return {
bufferYaml,
initialBufferYaml: bufferYaml,
bufferYaml: '',
initialBufferYaml: '',
providers,
selectedProvider,
hasMultipleProvidersSelected: selectedProviders.length > 1,