forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.vue
More file actions
2365 lines (2063 loc) · 76.2 KB
/
install.vue
File metadata and controls
2365 lines (2063 loc) · 76.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<script>
import jsyaml from 'js-yaml';
import merge from 'lodash/merge';
import isEqual from 'lodash/isEqual';
import { mapPref, DIFF } from '@shell/store/prefs';
import { mapFeature, MULTI_CLUSTER, LEGACY } from '@shell/store/features';
import { mapGetters } from 'vuex';
import { markRaw } from 'vue';
import { Banner } from '@components/Banner';
import ButtonGroup from '@shell/components/ButtonGroup';
import ChartReadme from '@shell/components/ChartReadme';
import { Checkbox } from '@components/Form/Checkbox';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import { LabeledInput } from '@components/Form/LabeledInput';
import { LabeledTooltip } from '@components/LabeledTooltip';
import LazyImage from '@shell/components/LazyImage';
import Loading from '@shell/components/Loading';
import NameNsDescription from '@shell/components/form/NameNsDescription';
import ResourceCancelModal from '@shell/components/ResourceCancelModal';
import Questions from '@shell/components/Questions';
import Tabbed from '@shell/components/Tabbed';
import UnitInput from '@shell/components/form/UnitInput';
import YamlEditor, { EDITOR_MODES } from '@shell/components/YamlEditor';
import Wizard from '@shell/components/Wizard';
import TypeDescription from '@shell/components/TypeDescription';
import ChartMixin from '@shell/mixins/chart';
import ChildHook, { BEFORE_SAVE_HOOKS, AFTER_SAVE_HOOKS } from '@shell/mixins/child-hook';
import {
CLUSTER_REPO_APPCO_AUTH_GENERATE_NAME, CATALOG, MANAGEMENT, DEFAULT_WORKSPACE, CAPI, SECRET,
AUTH_TYPE, NAMESPACE as NAMESPACE_TYPE
} from '@shell/config/types';
import {
CHART, FROM_CLUSTER, FROM_TOOLS, HIDE_SIDE_NAV, NEW_APP_INSTANCE, NAMESPACE, REPO, REPO_TYPE, VERSION, _FLAGGED
} from '@shell/config/query-params';
import { CATALOG as CATALOG_ANNOTATIONS, PROJECT } from '@shell/config/labels-annotations';
import { exceptionToErrorsArray } from '@shell/utils/error';
import {
clone, diff, get, mergeWithReplace, set
} from '@shell/utils/object';
import { ignoreVariables } from './install.helpers';
import { findBy, insertAt } from '@shell/utils/array';
import { saferDump } from '@shell/utils/create-yaml';
import { WINDOWS, isRancherRepo, getPermittedOSs } from '@shell/store/catalog';
import { SETTING } from '@shell/config/settings';
import SelectOrCreateAuthSecret from '@shell/components/form/SelectOrCreateAuthSecret.vue';
import { generateRandomAlphaString } from '@shell/utils/string';
const VALUES_STATE = {
FORM: 'FORM',
YAML: 'YAML',
DIFF: 'DIFF'
};
/**
* Helm CLI options that are not persisted on the back end,
* but are used for the final install/upgrade operation.
*/
export const defaultCmdOpts = {
cleanupOnFail: false,
crds: true,
hooks: true,
force: false,
resetValues: false,
openApi: true,
wait: true,
timeout: 600,
historyMax: 5,
};
function isPlainLayout(query) {
return Object.keys(query).includes(HIDE_SIDE_NAV);
}
export default {
name: 'Install',
layout(context) {
return isPlainLayout(context.query) ? 'plain' : '';
},
components: {
Banner,
ButtonGroup,
ChartReadme,
Checkbox,
LabeledInput,
LabeledSelect,
LabeledTooltip,
LazyImage,
Loading,
NameNsDescription,
ResourceCancelModal,
Questions,
Tabbed,
UnitInput,
YamlEditor,
Wizard,
TypeDescription,
SelectOrCreateAuthSecret
},
mixins: [
ChildHook,
ChartMixin
],
async fetch() {
this.errors = [];
// IMPORTANT! Any exception thrown before this.value is set will result in an empty page
/*
fetchChart is defined in shell/mixins. It first checks the URL
query for an app name and namespace. It uses those values to check
for a catalog app resource. If found, it sets the form to edit
mode. If not, it sets the form to create mode.
If the app and app namespace are not provided in the query,
it checks for target name and namespace values defined in the
Helm chart itself.
*/
try {
await this.fetchChart();
} catch (e) {
console.warn('Unable to fetch chart: ', e); // eslint-disable-line no-console
}
try {
await this.fetchAutoInstallInfo();
} catch (e) {
console.warn('Unable to determine if other charts require install: ', e); // eslint-disable-line no-console
}
// If the chart doesn't contain system `systemDefaultRegistry` properties there's no point applying them
if (this.showCustomRegistry) {
// Note: Cluster scoped registry is only supported for node driver clusters
try {
this.clusterRegistry = await this.getClusterRegistry();
} catch (e) {
console.warn('Unable to get cluster registry: ', e); // eslint-disable-line no-console
}
try {
this.globalRegistry = await this.getGlobalRegistry();
} catch (e) {
console.warn('Unable to get global registry: ', e); // eslint-disable-line no-console
}
this.defaultRegistrySetting = this.clusterRegistry || this.globalRegistry;
}
try {
this.serverUrlSetting = await this.$store.dispatch('management/find', {
type: MANAGEMENT.SETTING,
id: SETTING.SERVER_URL,
});
} catch (e) {
console.error('Unable to fetch `server-url` setting: ', e); // eslint-disable-line no-console
}
/*
Figure out the namespace where the chart is
being installed or upgraded.
*/
if ( this.existing ) {
/*
If the Helm chart is already installed,
use the existing namespace by default.
*/
this.forceNamespace = this.existing.metadata.namespace;
this.nameDisabled = true;
} else if (this.$route.query[FROM_CLUSTER] === _FLAGGED) {
/* For Fleet, use the fleet-default namespace. */
this.forceNamespace = DEFAULT_WORKSPACE;
} else if ( this.version?.annotations?.[CATALOG_ANNOTATIONS.NAMESPACE] ) {
/* If a target namespace is defined in the chart,
set the target namespace as default. */
this.forceNamespace = this.version.annotations[CATALOG_ANNOTATIONS.NAMESPACE];
} else if ( this.query.appNamespace ) {
/* If a namespace is defined in the URL query,
use that namespace as default. */
this.forceNamespace = this.query.appNamespace;
} else {
this.forceNamespace = null;
}
/* Check if the app is deprecated. */
try {
this.legacyApp = this.existing ? await this.existing.deployedAsLegacy() : false;
} catch (e) {
this.legacyApp = false;
console.warn('Unable to determine if existing install is a legacy app: ', e); // eslint-disable-line no-console
}
/* Check if the app is a multicluster deprecated app.
(Multicluster apps were replaced by Fleet.) */
try {
this.mcapp = this.existing ? await this.existing.deployedAsMultiCluster() : false;
} catch (e) {
this.mcapp = false;
console.warn('Unable to determine if existing install is a mc app: ', e); // eslint-disable-line no-console
}
/* The form state is intialized as a chartInstallAction resource. */
try {
this.value = await this.$store.dispatch('cluster/create', {
type: 'chartInstallAction',
metadata: {
namespace: this.forceNamespace || this.$store.getters['defaultNamespace'],
name: this.existing?.spec?.name || this.query.appName || '',
}
});
} catch (e) {
console.error('Unable to create object of type `chartInstallAction`: ', e); // eslint-disable-line no-console
// Nothing's going to work without a `value`. See https://github.com/rancher/dashboard/issues/9452 to handle this and other catches.
return;
}
/* Logic for when the Helm chart is not already installed */
if ( !this.existing) {
/*
The target name is used for Git repos for Fleet.
The target name indicates the name of the cluster
group that the chart is meant to be installed in.
*/
if ( this.version?.annotations?.[CATALOG_ANNOTATIONS.RELEASE_NAME] ) {
/*
Set the name of the chartInstallAction
to the name of the cluster group
where the chart should be installed.
*/
this.value.metadata.name = this.version.annotations[CATALOG_ANNOTATIONS.RELEASE_NAME];
this.nameDisabled = true;
} else if ( this.query.appName ) {
this.value.metadata.name = this.query.appName;
} else {
this.nameDisabled = false;
}
if ( this.query.description ) {
this.customCmdOpts.description = this.query.description;
}
} /* End of logic for when chart is already installed */
/*
Logic for what to do if the user is installing
the Helm chart for the first time and a default
namespace has been set.
*/
if (this.forceNamespace && !this.existing) {
let ns;
/*
Before moving forward, check to make sure the
default namespace exists and the logged-in user
has permission to see it.
*/
try {
ns = await this.$store.dispatch('cluster/find', { type: NAMESPACE, id: this.forceNamespace });
const project = ns.metadata.annotations?.[PROJECT];
if (project) {
this.project = project.replace(':', '/');
}
} catch {}
}
/* If no chart by the given app name and namespace
can be found, or if no version is found, do nothing. */
if ( !this.chart || !this.query.versionName) {
return;
}
if ( this.version ) {
/*
Check if the Helm chart has provided the name
of a Vue component to use for configuring
chart values. If so, load that component.
This will set this.valuesComponent,
this.showValuesComponent.
*/
await this.loadValuesComponent();
}
/*
this.loadedVersion will only be true if you select a non-defalut
option from the "Version" dropdown menu in Apps & Marketplace
when updating a previously installed app.
*/
if ( !this.loadedVersion || this.loadedVersion !== this.version.key ) {
let userValues;
/*
When you select a version, a new chart is loaded. Then
Rancher anticipates that you probably want to port all of your
previously customized, non-default values from the old chart
version to the new chart version, so it applies the previous
chart's customization to the new chart values before
you see the values form on the next page in the workflow.
*/
if ( this.loadedVersion ) {
if ( this.showingYaml ) {
this.applyYamlToValues();
}
/*
this.loadedVersionValues is taken from versionInfo,
which contains everything there is to know about a specific
version of a Helm chart, including all chart values,
chart metadata, a short app README and a more
version-specific README called the chart README.
Here we assume that any difference between the values in
two different Helm chart versions is a "user value," or
a user-selected customization.
*/
this.preserveCustomRegistryValue();
userValues = diff(this.loadedVersionValues, this.chartValues);
} else if ( this.existing ) {
await this.existing.fetchValues(); // In theory this has already been called, but do again to be safe
/* For an already installed app, use the values from the previous install. */
userValues = clone(this.existing.values || {});
} else {
/* For an new app, start empty. */
userValues = {};
}
this.userValues = userValues;
/*
Remove global values if they are identical to
the currently available information about the cluster
and Rancher settings.
Immediately before the Helm chart is installed or
upgraded, the global values are re-added.
*/
this.removeGlobalValuesFrom(userValues);
this.chartValues = mergeWithReplace(
merge({}, this.versionInfo?.values || {}),
userValues,
);
if (this.showCustomRegistry) {
/**
* The input to configure the registry should never be
* shown for third-party charts, which don't have Rancher
* global values.
*/
const existingRegistry = this.chartValues?.global?.systemDefaultRegistry || this.chartValues?.global?.cattle?.systemDefaultRegistry;
delete this.chartValues?.global?.systemDefaultRegistry;
delete this.chartValues?.global?.cattle?.systemDefaultRegistry;
this.customRegistrySetting = existingRegistry || this.defaultRegistrySetting;
this.showCustomRegistryInput = !!this.customRegistrySetting;
}
/* Serializes an object as a YAML document */
this.valuesYaml = saferDump(this.chartValues);
/* For YAML diff */
if ( !this.loadedVersion ) {
this.originalYamlValues = this.valuesYaml;
}
this.loadedVersionValues = this.versionInfo?.values || {};
this.loadedVersion = this.version?.key;
}
/* Check if chart exists and if required values exist */
this.updateStepOneReady();
this.preFormYamlOption = this.valuesComponent || this.hasQuestions ? VALUES_STATE.FORM : VALUES_STATE.YAML;
/* Look for annotation to say this app is a legacy migrated app (we look in either place for now) */
this.migratedApp = (this.existing?.spec?.chart?.metadata?.annotations?.[CATALOG_ANNOTATIONS.MIGRATED] === 'true');
if (this.repo?.isSuseAppCollection) {
let defaultSelectedSecret = await this.$store.getters['cluster/byId'](SECRET, `cattle-system/${ this.repo.spec.clientSecret.name }`);
if (!defaultSelectedSecret) {
try {
defaultSelectedSecret = (await this.$store.dispatch('cluster/find', { type: SECRET, id: `cattle-system/${ this.repo.spec.clientSecret.name }` }));
} catch (e) {
// If cannot get the secret for any reason, permission or doesn't exist
// We can fallback to use the name only and with that name move forward.
// On only other required data is the DecodedData but not having it will only trigger a different flow.
defaultSelectedSecret = { name: this.repo.spec.clientSecret.name };
}
}
this.selectedSecret = defaultSelectedSecret;
this.defaultGeneratedNameForImagePullSecret = `${ this.selectedSecret.name }-image-pull-secret`;
this.generatedNameForImagePullSecret = `${ this.selectedSecret.name }-image-pull-secret-${ generateRandomAlphaString(5) }`;
this.appCoDataFetched = true;
await this.initializeDataForNamespaceChanges();
await this.setImagePullSecretData();
}
},
data() {
return {
defaultRegistrySetting: '',
customRegistrySetting: '',
serverUrlSetting: null,
chartValues: null,
clusterRegistry: '',
originalYamlValues: null,
previousYamlValues: null,
errors: null,
existing: null,
globalRegistry: '',
forceNamespace: null,
loadedVersion: null,
loadedVersionValues: null,
legacyApp: null,
mcapp: null,
mode: null,
value: null,
valuesComponent: null,
valuesYaml: '',
project: null,
migratedApp: false,
defaultCmdOpts,
customCmdOpts: { ...defaultCmdOpts },
autoInstallInfo: [],
nameDisabled: false,
preFormYamlOption: VALUES_STATE.YAML,
formYamlOption: VALUES_STATE.YAML,
showDiff: false,
showValuesComponent: true,
showQuestions: true,
showSlideIn: false,
shownReadmeWindows: [],
showCommandStep: false,
showCustomRegistryInput: false,
isNamespaceNew: false,
selectedSecret: null,
secrets: [],
secretsView: [],
appCoSecretsView: [],
selectedImagePullSecret: null,
appCoImagePullSecretView: [],
generatedNameForImagePullSecret: null,
defaultGeneratedNameForImagePullSecret: null,
defaultImagePullSecret: null,
clientSecret: null,
showCreateAuthSecret: false,
dontUseDefaultOption: null,
disabledCheckbox: false,
appCoDataFetched: false,
AUTH_TYPE,
CLUSTER_REPO_APPCO_AUTH_GENERATE_NAME,
stepBasic: {
name: 'basics',
label: this.t('catalog.install.steps.basics.label'),
subtext: this.t('catalog.install.steps.basics.subtext'),
descriptionKey: 'catalog.install.steps.basics.description',
ready: true,
weight: 30
},
stepClusterTplVersion: {
name: 'clusterTplVersion',
label: this.t('catalog.install.steps.clusterTplVersion.label'),
subtext: this.t('catalog.install.steps.clusterTplVersion.subtext'),
descriptionKey: 'catalog.install.steps.helmValues.description',
ready: true,
weight: 30
},
stepValues: {
name: 'helmValues',
label: this.t('catalog.install.steps.helmValues.label'),
subtext: this.t('catalog.install.steps.helmValues.subtext'),
descriptionKey: 'catalog.install.steps.helmValues.description',
ready: true,
weight: 20
},
stepCommands: {
name: 'helmCli',
label: this.t('catalog.install.steps.helmCli.label'),
subtext: this.t('catalog.install.steps.helmCli.subtext'),
descriptionKey: 'catalog.install.steps.helmCli.description',
ready: true,
weight: 10
},
isPlainLayout: isPlainLayout(this.$route.query),
legacyDefs: {
legacy: this.t('catalog.install.error.legacy.category.legacy'),
mcm: this.t('catalog.install.error.legacy.category.mcm')
}
};
},
computed: {
...mapGetters({ inStore: 'catalog/inStore', features: 'features/get' }),
mcm: mapFeature(MULTI_CLUSTER),
/**
* Return list of variables to filter chart questions
*/
ignoreVariables() {
return ignoreVariables(this.versionInfo);
},
hasDecodedDataAvailable() {
// Will return false if doesn't have access to neither the decodedData or the selectedSecret, or if the decodedData is empty
return this.selectedSecret?.decodedData;
},
namespaceIsNew() {
const all = this.$store.getters['cluster/all'](NAMESPACE);
const want = this.value?.metadata?.namespace;
if ( !want ) {
return false;
}
return !findBy(all, 'id', want);
},
showProject() {
return this.isRancher && !this.existing && this.forceNamespace;
},
selectedRepoAuthBanner() {
if (!this.selectedSecret) {
return '';
}
if (!this.dontUseDefaultOption && !this.selectedImagePullSecret) {
return `${ this.t('catalog.install.steps.basics.generatedImagePullSecretBannerFromPreviousAuth', { imagePullSecretName: this.defaultGeneratedNameForImagePullSecret, repoAuthenticationName: this.selectedSecret.name }, {}, true) }`;
} else if (!this.selectedImagePullSecret) {
return `${ this.t('catalog.install.steps.basics.generatedNewImagePullSecret', { imagePullSecretName: this.generatedNameForImagePullSecret }, {}, true) }`;
} else if (this.selectedImagePullSecret === this.defaultImagePullSecret?.name) {
return `${ this.t('catalog.install.steps.basics.usePreviouslyGeneratedImagePullSecretBanner', { imagePullSecretName: this.selectedImagePullSecret, repoAuthenticationName: this.selectedSecret.name }, {}, true) }`;
}
return '';
},
projectOpts() {
const cluster = this.currentCluster;
const projects = this.$store.getters['management/all'](MANAGEMENT.PROJECT);
const out = projects.filter((x) => x.spec.clusterName === cluster?.id).map((project) => {
return {
id: project.id,
label: project.nameDisplay,
value: project.id
};
});
out.unshift({
id: 'none',
label: `(${ this.t('generic.none') })`,
value: '',
});
return out;
},
charts() {
const current = this.existing?.matchingCharts(true)[0];
const out = this.$store.getters['catalog/charts'].filter((x) => {
if ( x.key === current?.key || x.chartName === current?.chartName ) {
return true;
}
if ( x.hidden && !this.showHidden ) {
return false;
}
if ( x.deprecated && !this.showDeprecated ) {
return false;
}
return true;
});
let last = '';
for ( let i = 0 ; i < out.length ; i++ ) {
if ( out[i].repoName !== last ) {
last = out[i].repoName;
insertAt(out, i, {
kind: 'label',
label: out[i].repoNameDisplay,
disabled: true
});
i++;
}
}
return out;
},
showSelectVersionOrChart() {
// Allow the user to choose a version if:
// - the app exists (editing/upgrading)
// - OR they've come from tools
// - OR they're installing a new instance of an already-installed chart
return this.existing || (FROM_TOOLS in this.$route.query) || (NEW_APP_INSTANCE in this.$route.query);
},
showNameEditor() {
return !this.nameDisabled || !this.forceNamespace;
},
showVersions() {
return this.chart?.versions.length > 1;
},
targetNamespace() {
if ( this.forceNamespace ) {
return this.forceNamespace;
} else if ( this.value?.metadata.namespace ) {
return this.value.metadata.namespace;
}
return 'default';
},
editorMode() {
if ( this.showDiff ) {
return EDITOR_MODES.DIFF_CODE;
}
return EDITOR_MODES.EDIT_CODE;
},
showingYaml() {
return this.formYamlOption === VALUES_STATE.YAML || ( !this.valuesComponent && !this.hasQuestions );
},
showingYamlDiff() {
return this.formYamlOption === VALUES_STATE.DIFF;
},
formYamlOptions() {
const options = [];
if (this.valuesComponent || this.hasQuestions) {
options.push({
labelKey: 'catalog.install.section.chartOptions',
value: VALUES_STATE.FORM,
});
}
options.push({
labelKey: 'catalog.install.section.valuesYaml',
value: VALUES_STATE.YAML,
}, {
labelKey: 'catalog.install.section.diff',
value: VALUES_STATE.DIFF,
// === quite obviously shouldn't work, but has been and still does. When the magic breaks address with heavier stringify/jsyaml.dump
disabled: this.formYamlOption === VALUES_STATE.FORM ? this.originalYamlValues === jsyaml.dump(this.chartValues || {}) : this.originalYamlValues === this.valuesYaml,
});
return options;
},
yamlDiffModeOptions() {
return [{
labelKey: 'resourceYaml.buttons.unified',
value: 'unified',
}, {
labelKey: 'resourceYaml.buttons.split',
value: 'split',
}];
},
stepperName() {
return this.existing?.nameDisplay || this.chart?.chartNameDisplay;
},
stepperSubtext() {
return this.existing && this.currentVersion !== this.targetVersion ? `${ this.currentVersion } > ${ this.targetVersion }` : this.targetVersion;
},
readmeWindowName() {
// Version can change, so allow multiple WM tabs for different versions
return `${ this.stepperName }-${ this.version?.version }`;
},
showingReadmeWindow() {
return !!this.$store.getters['wm/byId'](this.readmeWindowName);
},
diffMode: mapPref(DIFF),
step1Description() {
const descriptionKey = this.steps.find((s) => s.name === 'basics').descriptionKey;
return this.$store.getters['i18n/withFallback'](descriptionKey, { action: this.action.name, existing: !!this.existing }, '');
},
step2Description() {
const descriptionKey = this.steps.find((s) => s.name === 'helmValues').descriptionKey;
return this.$store.getters['i18n/withFallback'](descriptionKey, { action: this.action.name, existing: !!this.existing }, '');
},
step3Description() {
const descriptionKey = this.steps.find((s) => s.name === 'helmCli').descriptionKey;
return this.$store.getters['i18n/withFallback'](descriptionKey, { action: this.action.name, existing: !!this.existing }, '');
},
steps() {
const steps = [];
const type = this.version?.annotations?.[CATALOG_ANNOTATIONS.TYPE];
if ( type === CATALOG_ANNOTATIONS._CLUSTER_TPL ) {
if (this.filteredVersions?.length > 1) {
steps.push(this.stepClusterTplVersion);
}
steps.push({
...this.stepValues,
label: this.t('catalog.install.steps.clusterTplValues.label'),
subtext: this.t('catalog.install.steps.clusterTplValues.subtext'),
descriptionKey: 'catalog.install.steps.clusterTplValues.description',
});
} else {
steps.push(
this.stepBasic,
this.stepValues,
);
}
if (this.showCommandStep) {
steps.push(this.stepCommands);
}
return steps.sort((a, b) => (b.weight || 0) - (a.weight || 0));
},
cmdOptions() {
return this.showCommandStep ? this.customCmdOpts : this.defaultCmdOpts;
},
namespaceNewAllowed() {
return !this.existing && !this.forceNamespace;
},
legacyEnabled() {
// Check for the legacy feature flag in the settings
return this.features(LEGACY);
},
legacyFeatureRoute() {
return {
name: 'c-cluster-product-resource',
params: { product: 'settings', resource: 'management.cattle.io.feature' }
};
},
legacyAppRoute() {
return { name: 'c-cluster-legacy-project' };
},
windowsIncompatible() {
if (this.versionInfo) {
const isRancher = isRancherRepo(this.repo, this.chart);
const permittedSystems = getPermittedOSs(this.versionInfo?.chart?.annotations, isRancher);
const incompatibleVersion = permittedSystems.length > 0 && !permittedSystems.includes('windows');
if (incompatibleVersion) {
if (!this.chart?.windowsIncompatible) {
return this.t('catalog.charts.versionWindowsIncompatible');
}
return this.t('catalog.charts.windowsIncompatible');
}
}
return null;
},
/**
* Check if the chart contains `systemDefaultRegistry` properties.
* If not we shouldn't apply the setting, because if the option
* is exposed for third-party Helm charts, it confuses users because
* it shows a private registry setting that is never used
* by the chart they are installing. If not hidden, the setting
* does nothing, and if the user changes it, it will look like
* there is a bug in the UI when it doesn't work, because UI is
* exposing a feature that the chart does not have.
*/
showCustomRegistry() {
const global = this.versionInfo?.values?.global || {};
return global.systemDefaultRegistry !== undefined || global.cattle?.systemDefaultRegistry !== undefined;
},
setImagePullSecretDataTrigger() {
return `
${ this.defaultImagePullSecret?.name }
${ this.dontUseDefaultOption }
${ this.selectedImagePullSecret }`;
}
},
watch: {
'$route.query'(neu, old) {
// If the query changes, refetch the chart
// When going back to app list, the query is empty and we don't want to refetch
if ( !isEqual(neu, old) && Object.keys(neu).length > 0 ) {
this.$fetch();
this.showSlideIn = false;
}
},
async 'value.metadata.namespace'(neu, old) {
if (neu) {
const ns = this.$store.getters['cluster/byId'](NAMESPACE, this.value.metadata.namespace);
const project = ns?.metadata.annotations?.[PROJECT];
if (project) {
this.project = project.replace(':', '/');
}
}
if (this.repo?.isSuseAppCollection) {
await this.initializeDataForNamespaceChanges();
}
},
async setImagePullSecretDataTrigger() {
await this.setImagePullSecretData();
},
preFormYamlOption(neu, old) {
if (neu === VALUES_STATE.FORM && this.valuesYaml !== this.previousYamlValues && !!this.$refs.cancelModal) {
this.$refs.cancelModal.show();
} else {
this.formYamlOption = neu;
}
},
formYamlOption(neu, old) {
switch (neu) {
case VALUES_STATE.FORM:
// Return to form, reset everything back to starting point
this.valuesYaml = this.previousYamlValues;
this.showValuesComponent = true;
this.showQuestions = true;
this.showDiff = false;
break;
case VALUES_STATE.YAML:
// Show the YAML preview
if (old === VALUES_STATE.FORM) {
this.valuesYaml = jsyaml.dump(this.chartValues || {});
this.previousYamlValues = this.valuesYaml;
}
this.showValuesComponent = false;
this.showQuestions = false;
this.showDiff = false;
break;
case VALUES_STATE.DIFF:
// Show the YAML diff
if (old === VALUES_STATE.FORM) {
this.valuesYaml = jsyaml.dump(this.chartValues || {});
this.previousYamlValues = this.valuesYaml;
}
this.showValuesComponent = false;
this.showQuestions = false;
this.updateValue(this.valuesYaml);
this.showDiff = true;
break;
}
},
requires() {
this.updateStepOneReady();
},
warnings() {
this.updateStepOneReady();
},
},
async mounted() {
// Load a Vue component named in the Helm chart
// for editing values
await this.loadValuesComponent();
window.scrollTop = 0;
this.preFormYamlOption = this.valuesComponent || this.hasQuestions ? VALUES_STATE.FORM : VALUES_STATE.YAML;
// Register the image pull secret creation hook with lower priority (runs after SelectOrCreateAuthSecret at 99)
this.registerBeforeHook(this.createImagePullSecret, 'createImagePullSecret', 150);
},
beforeUnmount() {
this.shownReadmeWindows.forEach((name) => this.$store.dispatch('wm/close', name, { root: true }));
},
methods: {
/**
* The custom registry UI fields (checkbox and input) are not directly bound to chartValues.
* Before calculating the diff to carry over user customizations, we must
* first synchronize the state of these UI fields with chartValues. This
* ensures any user changes to the custom registry settings are
* included in the diff and preserved when changing versions.
*/
preserveCustomRegistryValue() {
if (!this.showCustomRegistry) {
return;
}
if (this.showCustomRegistryInput) {
set(this.chartValues, 'global.systemDefaultRegistry', this.customRegistrySetting);
set(this.chartValues, 'global.cattle.systemDefaultRegistry', this.customRegistrySetting);
} else {
// Note: Using `delete` here is safe because this is not a reactive property update
// that the UI needs to track. This is a one-time mutation before a diff.
if (get(this.chartValues, 'global.systemDefaultRegistry')) {
delete this.chartValues.global.systemDefaultRegistry;
}
if (get(this.chartValues, 'global.cattle.systemDefaultRegistry')) {
// It's possible `this.chartValues.global.cattle` doesn't exist,
// but `get` ensures we only proceed if the full path exists.
delete this.chartValues.global.cattle.systemDefaultRegistry;
}
}
},
async initializeDataForNamespaceChanges() {
// Skip the flow if the data still not fetched, it will trigger after fetching manually
if (this.appCoDataFetched) {
try {
this.defaultImagePullSecret = await this.$store.dispatch('cluster/find', { type: SECRET, id: `${ this.targetNamespace }/${ this.repo.spec.clientSecret.name }-image-pull-secret` });
} catch (e) {
// If the secret doesn't exist, that's fine, we'll just create a new one later
this.defaultImagePullSecret = null;
}
// Reset if doesnt have the defaultImagePullSecret and doesn't have decoded data
// Disable the checkbox
const previousDontUseDefaultOption = this.dontUseDefaultOption;
let dontUseDefaultOption = false;
if (!this.hasDecodedDataAvailable && !this.defaultImagePullSecret) {
dontUseDefaultOption = true;
this.disabledCheckbox = true;
} else {
dontUseDefaultOption = false;
this.disabledCheckbox = false;
}
// On upgrade mode you cannot change namespace so this works as a full setup
if (!!this.existing) {
if (this.userValues?.global?.imagePullSecrets?.[0]) {
this.selectedImagePullSecret = this.userValues?.global?.imagePullSecrets[0];
}
this.dontUseDefaultOption = true;
return;
}
this.dontUseDefaultOption = dontUseDefaultOption;
// Setting default values if changing to avoid duplicated trigger
if (this.dontUseDefaultOption !== previousDontUseDefaultOption) {
if (this.defaultImagePullSecret) {
// If the default option is used and the default secret already exists, use it
this.selectedImagePullSecret = this.defaultImagePullSecret.name;
this.chartValues.global.imagePullSecrets = [this.selectedImagePullSecret];
} else if (!this.defaultImagePullSecret) {
// Create new option with default generated name if the default option is selected
this.selectedImagePullSecret = null;
this.chartValues.global.imagePullSecrets = [this.defaultGeneratedNameForImagePullSecret];
}
}
}
},
async getClusterRegistry() {
const hasPermissionToSeeProvCluster = this.$store.getters[`management/schemaFor`](CAPI.RANCHER_CLUSTER);
if (hasPermissionToSeeProvCluster) {
const mgmCluster = this.$store.getters['currentCluster'];
const provClusterId = mgmCluster?.provClusterId;
let provCluster;