Skip to content
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

[FIX] Fixed issues with infrastructure provider: #50

Merged
merged 3 commits into from
Apr 25, 2024
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 @@ -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;
};