Skip to content

Commit

Permalink
Merge pull request #50 from eva-vashkevich/iss45
Browse files Browse the repository at this point in the history
[FIX] Fixed issues with infrastructure provider
  • Loading branch information
eva-vashkevich authored Apr 25, 2024
2 parents 7bd9907 + 7cbaddf commit 0d3ec5b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default (Vue as VueConstructor<
{ path: 'metadata.name', rules: ['required'] },
{ path: 'spec.name', rules: ['required'] },
{ path: 'spec.version', rules: ['version'] },
{ path: 'spec.fetchConfig.url', rules: ['required', 'url'] },
{ path: 'spec.fetchConfig.url', rules: ['url'] },
],
allNamespaces: [],
needCredential: providerDetails?.needCredentials || false,
Expand Down Expand Up @@ -153,10 +153,10 @@ export default (Vue as VueConstructor<
const defaultsFromCoreProvider = this.getSpecFromCoreSecret();
if ( this.provider !== 'custom') {
set(this.value, 'spec', { ...defaultSpec, ...defaultsFromCoreProvider });
set(this.value, 'spec', { ...clone(defaultSpec), ...defaultsFromCoreProvider });
set(this.value.spec, 'name', this.provider); // Defines the provider kind to provision.
} else {
set(this.value, 'spec', { ...customProviderSpec, ...defaultsFromCoreProvider });
set(this.value, 'spec', { ...clone(customProviderSpec), ...defaultsFromCoreProvider });
}
}
if (!this.value.spec.configSecret.name) {
Expand Down Expand Up @@ -214,7 +214,7 @@ export default (Vue as VueConstructor<
this.value.spec.credentials = null;
}
try {
await this.value.save();
await this.save();
return this.done();
} catch (err) {
Expand All @@ -223,8 +223,8 @@ export default (Vue as VueConstructor<
}
},
cancelCredential() {
if ( this.$refs.cruresource ) {
this.$refs.cruresource.emitOrRoute();
if ( this.$refs.providercruresource ) {
this.$refs.providercruresource.emitOrRoute();
}
}
}
Expand All @@ -235,6 +235,7 @@ export default (Vue as VueConstructor<
<Loading v-if="loading" />
<CruResource
v-else
ref="providercruresource"
:mode="mode"
:validation-passed="fvFormIsValid"
:resource="value"
Expand Down Expand Up @@ -270,6 +271,7 @@ export default (Vue as VueConstructor<
v-model="value.spec.name"
:mode="mode"
label-key="capi.provider.label"
placeholder-key="capi.provider.placeholder"
required
:rules="fvGetAndReportPathRules('spec.name')"
/>
Expand All @@ -282,6 +284,7 @@ export default (Vue as VueConstructor<
:mode="mode"
:options="typeOptions"
label-key="capi.provider.type.label"
:disabled="isEdit"
required
/>
</div>
Expand All @@ -292,7 +295,7 @@ export default (Vue as VueConstructor<
v-model="value.spec.version"
:mode="mode"
label-key="capi.provider.version.label"
required
placeholder-key="capi.provider.version.placeholder"
:rules="fvGetAndReportPathRules('spec.version')"
/>
</div>
Expand All @@ -305,7 +308,7 @@ export default (Vue as VueConstructor<
v-model="value.spec.fetchConfig.url"
:mode="mode"
label-key="capi.provider.fetchConfigURL.label"
required
placeholder-key="capi.provider.fetchConfigURL.placeholder"
:rules="fvGetAndReportPathRules('spec.fetchConfig.url')"
/>
</div>
Expand Down
12 changes: 10 additions & 2 deletions pkg/capi/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ capi:
provider:
title: Provider
label: Provider
placeholder: eg. custom-provider
banner: Editing configuration will affect all clusters that are using this provider and may cause errors.
name:
label: Name
Expand All @@ -95,8 +96,10 @@ capi:
label: Provider type
version:
label: Version
placeholder: eg. v1.0.0
fetchConfigURL:
label: URL
placeholder: https://github.com/example/releases/latest/client.yaml
cloudCredential:
title: Cloud Credential
features:
Expand All @@ -119,10 +122,15 @@ nav:
CAPITurtles: CAPI

typeLabel:
cluster.x-k8s.io.cluster: |-
{count, plural,
one { Cluster }
other { Clusters }
}
turtles-capi.cattle.io.capiprovider: |-
{count, plural,
one { Infrastructure Provider }
other { Infrastructure Providers }
one { Provider }
other { Providers }
}
cluster.x-k8s.io.machineset: |-
{count, plural,
Expand Down
2 changes: 1 addition & 1 deletion pkg/capi/util/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ export const urlValidator = function(t: Translation): Validator {
};

export const providerVersionValidator = function(t: Translation, required: boolean): Validator {
return (val: string) => required && !val.match(/^v(\d+.){2}\d*$/) ? t('validation.version') : undefined;
return (val: string) => required && !val.match(/^(\.*\w*)*$/) ? t('validation.version') : undefined;
};

0 comments on commit 0d3ec5b

Please sign in to comment.