diff --git a/pkg/storage/internalstorage/config.go b/pkg/storage/internalstorage/config.go index 81823c32b..3d175bcbe 100644 --- a/pkg/storage/internalstorage/config.go +++ b/pkg/storage/internalstorage/config.go @@ -15,6 +15,8 @@ import ( "gopkg.in/natefinch/lumberjack.v2" "gorm.io/gorm/logger" "k8s.io/klog/v2" + + clusterv1alpha2 "github.com/clusterpedia-io/api/cluster/v1alpha2" ) const ( @@ -24,6 +26,14 @@ const ( databasePasswordEnvName = "DB_PASSWORD" ) +type DivisionPolicy string + +const ( + DivisionPolicyNone DivisionPolicy = "None" + DivisionPolicyGroupResource DivisionPolicy = "GroupResource" + DivisionPolicyCustom DivisionPolicy = "Custom" +) + type Config struct { Type string `env:"DB_TYPE" required:"true"` DSN string `env:"DB_DSN"` @@ -48,9 +58,30 @@ type Config struct { Params map[string]string `yaml:"params"` + AutoMigration *bool `yaml:"autoMigration"` // If set to false, no tables will be created + DivisionPolicy DivisionPolicy `yaml:"divisionPolicy"` + Mapper []ResourceMapper `yaml:"mapper"` // Only DivisionPolicy is DivisionPolicyCustom it need to specify the mapping between resource and table + Log *LogConfig `yaml:"log"` } +type ResourceMapper struct { + Table *Table `yaml:"table"` + Resources []clusterv1alpha2.ClusterGroupResources `yaml:"resources"` +} + +type Table struct { + Name string `yaml:"name"` + ExtraFields []ExtraField `yaml:"extraFields"` +} + +type ExtraField struct { + Name string `yaml:"name"` + PlainPath string `yaml:"plainPath"` + Type string `yaml:"type"` + Index string `yaml:"index"` +} + type LogConfig struct { Stdout bool `yaml:"stdout"` Level string `yaml:"level"`