feat: redis and dyminic dbversion #3449
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🤖 Generated by Copilot at cf8bd5d
Summary
🌐🗄️🚀
This pull request adds frontend support for Redis databases, which are a new type of database supported by the backend. It updates the components, pages, constants, types, and utils files to render the UI elements, fetch the data, and generate the YAML files for the Redis database features. It also adds internationalization support for the Redis-related texts, and refactors the kubernetes client function.
Walkthrough
common.json
files for the English and Chinese locales, which are used to display the labels and messages for the Redis HA feature in the frontend (link, link)platform.ts
file, which is used to define the API functions for the platform-related features, to import the type definition for the response of thegetVersion
API, which is used to get the available versions of the database types (link)RangeInput
component, which is used to render a slider for selecting the number of replicas for the database, to specify the width of the component based on the number of marks on the slider (link)Tip
component, which is used to render a tooltip with an icon and a text, to import theuseTranslation
hook from thenext-i18next
library, which is used to get the translation function for the current locale (link)Tip
component, which is used to render a tooltip with an icon and a text, to invoke theuseTranslation
hook and assign the returned translation function to a variable namedt
, which is then used to translate thetext
prop of the component (link)text
prop of theTip
component, which is used to display the tooltip content, to wrap thetext
prop with thet
function, which is the translation function for the current locale, to ensure that the text is translated according to the user's language preference (link)DBTypeEnum
enum, which is an enum of the supported database types, to represent the Redis database type, and use it to identify and handle the Redis-specific features and logic in the frontend (link, link, link, link, link, link, link, link, link, link, link, link)DBTypeList
array, which is an array of objects that map the database type ids to their labels, to render the option for selecting the Redis database type in the frontend (link)db.ts
file, which is used to define the constants and types related to the database features, to return the configuration for the Redis HA nodes, which are additional nodes that provide fault tolerance and load balancing for the Redis database, and use it to calculate the resource and price requirements for the Redis HA feature in the frontend (link, link, link, link, link, link, link, link, link)Form
component, which is used to render the form for creating or editing the database instances in the frontend, to import theSwitch
component from thechakra-ui
library, which is used to render a toggle switch for enabling or disabling the Redis HA feature in the frontend (link)Form
component, which is used to render the form for creating or editing the database instances in the frontend, to remove the import of theBackupStatusMapType
, which is no longer used in this file, and add the import of theDBTypeEnum
, theRedisHAConfig
, and theTip
component, which are used to implement the Redis HA feature and its logic in the frontend (link)PriceBox
component, which is used to display the estimated price for the database instances in the frontend, to change the props of thePriceBox
component from the cpu, memory, storage, and pods to the components, which is an array of objects that specify the cpu, memory, storage, and replicas for each component of the database cluster, and add a condition to check if the database type isDBTypeEnum.redis
, and if so, add an additional component object to the array, which has the configuration for the Redis HA nodes, to calculate and display the price for the Redis HA feature in the frontend (link)MySelect
component, which is used to render the options for selecting the database version in the frontend, to add a new prop to theMySelect
component, which is the width of the component, and set the value to a template literal that interpolates the width of the component based on the number of options in theDBVersionMap
, to adjust the width of the component according to the length of the version labels (link)RangeInput
component, which is used to render a slider for selecting the number of replicas for the database in the frontend, to add a new prop to theRangeInput
component, which is the width of the component, and set the value to a template literal that interpolates the width of the component based on the number of marks on the slider, to adjust the width of the component according to the range of the replicas, and add a newTip
component after theRangeInput
component, which is used to render a tooltip with an icon and a text, to inform the user that the multi-replica Redis includes HA nodes, and that the price already includes the cost for the HA nodes, to provide the user with more information about the Redis HA feature and its pricing in the frontend (link)FormControl
component, which is used to render the input for selecting the storage size for the database in the frontend, to add a new prop to theFormControl
component, which is the width of the component, and set the value to a template literal that interpolates the width of the component based on the number of marks on the slider, to adjust the width of the component according to the range of the storage size (link)PriceBox
component, which is used to display the estimated price for the database instances in the frontend, to remove the import of theDBVersionMap
from the constants file, and add the import of theDBVersionMap
from the static store, and add the import of thelodash
library, which is used to throttle the price calculation function to improve the performance, to use the latest version information and optimize the rendering of thePriceBox
component in the frontend (link)PriceBox
component from the cpu, memory, storage, and pods to the components, which is an array of objects that specify the cpu, memory, storage, and replicas for each component of the database cluster, and change the logic of the price calculation function, which loops over the components array and accumulates the price for each resource and each replica, and change thepodScale
function, which takes an array of prices instead of a single price, and returns the formatted price range based on the minimum and maximum values, to calculate and display the price for the multiple components of the database cluster, including the Redis HA nodes, in the frontend (link)json2Yaml.ts
file, which is used to define the helper functions for converting the JSON data to YAML format for the database features, to import theRedisHAConfig
function from the constants file, which is used to get the configuration for the Redis HA nodes, to generate the YAML files for the Redis HA feature in the frontend (link)json2Yaml.ts
file, which is used to define the helper functions for converting the JSON data to YAML format for the database features, to store the configuration for the Redis HA nodes, and use it to generate the YAML files for the Redis HA feature in the frontend (link, link)json2CreateCluster
function, which is used to generate the YAML file for creating the database cluster in the frontend, to handle the logic for generating the YAML file for the Redis database cluster, which includes theCluster
, theServiceAccount
, theRole
, and theRoleBinding
resources, to define the spec for the Redis cluster, which includes theclusterDefinitionRef
, theclusterVersionRef
, thecomponentSpecs
, and theterminationPolicy
, and the RBAC rules for the Redis cluster, which allow the cluster to create events in the kubernetes cluster, to generate the YAML file for the Redis database cluster in the frontend (link)json2Account
function, which is used to generate the YAML file for creating the database account in the frontend, to handle the logic for generating the YAML file for the Redis database account, which includes theSecret
and theConfigMap
resources, to define the data for the password and the connection string for the Redis database, which are encoded in base64 format, and the data for the host and the port for the Redis database, which are plain text, to generate the YAML file for the Redis database account in the frontend (link)getVersion
API, and use them to set the default values for the database version in the frontend (link, link, link, link, link, link, link, link, link, link)_app.tsx
file, which is the custom App component for the Next.js framework, to import thegetDBVersion
function from the static store, which is used to fetch and store the available versions of the database types from the backend (link)getDBVersion
function, which is used to fetch and store the available versions of the database types from the backend, when the component mounts, to ensure that the frontend has the latest version information for the database features (link)getVersion.ts
, which is used to define the handler function for thegetVersion
API, which is used to get the available versions of the database types from the backend, and import the type definitions, the libraries, and the constants that are needed for the handler function, and define the response type, which is a record of the database types and their corresponding arrays of version objects, and define the handler function, which uses the kubernetes client to list the cluster custom objects that represent the database versions, and maps them to the response type, and handles the error cases and returns the response using thejsonRes
helper function (link)index.tsx
file, which is used to render the database edit page in the frontend, to import theDBVersionMap
from the static store, which is used to get the available versions of the database types from the backend, to set the default value for the database version in the frontend (link)index.tsx
file, which is used to render the database edit page in the frontend, to store the default values for the database edit form, and override thedbVersion
property with the first item of theDBVersionMap.postgresql
array, to set the default value for the database version in the frontend, based on the latest version information from the backend (link)defaultValues
property of the form hook from thedefaultDBEditValue
to thedefaultEdit
variable, to use the updated default value for the database version in the frontend (link)value
property of the YAML files from thedefaultDBEditValue
to thedefaultEdit
variable, to use the updated default value for the database version in the frontend (link)static.ts
file, which is used to define the static store for the frontend, to import thegetDBVersionMap
function from the API file, which is used to fetch the available versions of the database types from the backend, and import theDBTypeEnum
from the constants file, which is an enum of the supported database types, and import the response type for thegetVersion
API, which is used to store the version information in the static store (link)static.ts
file, which is used to define the static store for the frontend, to indicate how many times the frontend will retry to fetch the version information from the backend if the request fails, and initialize it to 3, which means the frontend will retry up to 3 times (link)static.ts
file, which is used to define the static store for the frontend, to store the available versions of the database types from the backend, and initialize it to an empty object with the keys of theDBTypeEnum
values, and the values of empty arrays, to prepare the data structure for storing the version information in the static store (link)static.ts
file, which is used to define the static store for the frontend, to fetch the available versions of the database types from the backend using thegetDBVersionMap
API function, and assign the response to theDBVersionMap
variable, and handle the error cases, and decrement theretryVersion
variable and retry the request if the variable is greater than or equal to zero, and use a timeout of 1000 milliseconds between each retry, to implement the logic of fetching and storing the version information in the static store (link)K8sApi
function from the config string to an optional config string, and check if the config parameter is provided, and if so, load the kubernetes config from the string, otherwise, load the kubernetes config from the cluster, and check if the cluster is in the cluster and has the hosts value, and if so, use the hosts value, otherwise, use the default server value, to support the in-cluster mode of the kubernetes client (link)K8sApi
function, to simplify the logic of the function and avoid unnecessary mutations of the config object (link)localStorage
, which is used to store the user's session information, when the user logs out from the frontend, to clear the session data and prevent unauthorized access (link)DBTypeEnum.redis
, and if so, return a toast message that warns the user that Redis does not support backup at this time, to prevent the user from attempting to backup the Redis database, which is not supported by the backend (link)