Documentation
¶
Index ¶
- Constants
- func InterpretDBError(key string, err error) error
- func InterpretMysqlError(key string, err error) error
- func InterpretPostgresError(key string, err error) error
- func InterpretResourceDBError(cluster, name string, err error) error
- func NewCollectionResourceStorage(db *gorm.DB, cr *internal.CollectionResource) storage.CollectionResourceStorage
- func NewGormTrace(excludeQueryVars bool) gorm.Plugin
- func NewStorageFactory(configPath string) (storage.StorageFactory, error)
- type Bytes
- func (bytes Bytes) ConvertTo(codec runtime.Codec, object runtime.Object) (runtime.Object, error)
- func (bytes Bytes) ConvertToUnstructured() (*unstructured.Unstructured, error)
- func (bytes Bytes) GetEvents() []*corev1.Event
- func (bytes Bytes) GetResourceType() ResourceType
- func (bytes *Bytes) Scan(data any) error
- func (bytes Bytes) Value() (driver.Value, error)
- type BytesList
- type BytesWithEvents
- func (bytes BytesWithEvents) ConvertTo(codec runtime.Codec, object runtime.Object) (runtime.Object, error)
- func (bytes BytesWithEvents) ConvertToUnstructured() (*unstructured.Unstructured, error)
- func (bytes BytesWithEvents) GetEvents() []*corev1.Event
- func (bytes BytesWithEvents) GetResourceType() ResourceType
- type BytesWithEventsList
- type CollectionResourceStorage
- type Config
- type ConnPoolConfig
- type DBStats
- type EventsBytes
- type JSONMap
- func (m JSONMap) GormDBDataType(db *gorm.DB, field *gormschema.Field) string
- func (m JSONMap) GormDataType() string
- func (m JSONMap) GormValue(ctx context.Context, db *gorm.DB) clause.Expr
- func (m JSONMap) MarshalJSON() ([]byte, error)
- func (m *JSONMap) Scan(val interface{}) error
- func (m *JSONMap) UnmarshalJSON(b []byte) error
- func (m JSONMap) Value() (driver.Value, error)
- type JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) Build(builder clause.Builder)
- func (jsonQuery *JSONQueryExpression) Equal(value string) *JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) Exist() *JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) In(values ...string) *JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) NotEqual(value string) *JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) NotExist() *JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) NotIn(values ...string) *JSONQueryExpression
- type JSONUpdateExpression
- type LogConfig
- type MetricsConfig
- type MySQLConfig
- type Object
- type ObjectList
- type PostgresConfig
- type Prometheus
- type Resource
- func (res Resource) ConvertTo(codec runtime.Codec, object runtime.Object) (runtime.Object, error)
- func (res Resource) ConvertToUnstructured() (*unstructured.Unstructured, error)
- func (res Resource) GetEvents() []*corev1.Event
- func (res Resource) GetResourceType() ResourceType
- func (res Resource) GroupVersionResource() schema.GroupVersionResource
- type ResourceList
- type ResourceMetadata
- func (data ResourceMetadata) ConvertTo(codec runtime.Codec, object runtime.Object) (runtime.Object, error)
- func (data ResourceMetadata) ConvertToUnstructured() (*unstructured.Unstructured, error)
- func (data ResourceMetadata) GetEvents() []*corev1.Event
- func (data ResourceMetadata) GetResourceType() ResourceType
- type ResourceMetadataList
- type ResourceMetadataWithEvents
- func (bytes ResourceMetadataWithEvents) ConvertTo(codec runtime.Codec, object runtime.Object) (runtime.Object, error)
- func (bytes ResourceMetadataWithEvents) ConvertToUnstructured() (*unstructured.Unstructured, error)
- func (bytes ResourceMetadataWithEvents) GetEvents() []*corev1.Event
- func (bytes ResourceMetadataWithEvents) GetResourceType() ResourceType
- type ResourceMetadataWithEventsList
- type ResourceStorage
- func (s *ResourceStorage) ConvertDeletedObject(obj interface{}) (runtime.Object, error)
- func (s *ResourceStorage) Create(ctx context.Context, cluster string, obj runtime.Object) error
- func (s *ResourceStorage) Delete(ctx context.Context, cluster string, obj runtime.Object) error
- func (s *ResourceStorage) Get(ctx context.Context, cluster, namespace, name string, into runtime.Object) error
- func (s *ResourceStorage) GetResourceEvents(ctx context.Context, cluster, namespace, name string) ([]*corev1.Event, error)
- func (s *ResourceStorage) GetStorageConfig() *storage.ResourceStorageConfig
- func (s *ResourceStorage) List(ctx context.Context, listObject runtime.Object, opts *internal.ListOptions) error
- func (s *ResourceStorage) RecordEvent(ctx context.Context, cluster string, event *corev1.Event) error
- func (s *ResourceStorage) Update(ctx context.Context, cluster string, obj runtime.Object) error
- func (s *ResourceStorage) Watch(_ context.Context, _ *internal.ListOptions) (watch.Interface, error)
- type ResourceType
- type StorageFactory
- func (s *StorageFactory) CleanCluster(ctx context.Context, cluster string) error
- func (s *StorageFactory) CleanClusterResource(ctx context.Context, cluster string, gvr schema.GroupVersionResource) error
- func (s *StorageFactory) GetCollectionResources(ctx context.Context) ([]*internal.CollectionResource, error)
- func (s *StorageFactory) GetResourceVersions(ctx context.Context, cluster string) (map[schema.GroupVersionResource]storage.ClusterResourceVersions, error)
- func (s *StorageFactory) GetSupportedRequestVerbs() []string
- func (s *StorageFactory) NewCollectionResourceStorage(cr *internal.CollectionResource) (storage.CollectionResourceStorage, error)
- func (s *StorageFactory) NewResourceStorage(config *storage.ResourceStorageConfig) (storage.ResourceStorage, error)
- func (s *StorageFactory) PrepareCluster(cluster string) error
- func (s *StorageFactory) Shutdown() error
- type URLQueryWhereSQLParams
Constants ¶
View Source
const ( CollectionResourceAny = "any" CollectionResourceWorkloads = "workloads" CollectionResourceKubeResources = "kuberesources" )
View Source
const ( URLQueryGroups = "groups" URLQueryResources = "resources" )
View Source
const ( // AllowRawSQLQuery is a feature gate for the apiserver to allow querying by the raw sql. // // owner: @cleverhu // alpha: v0.3.0 AllowRawSQLQuery featuregate.Feature = "AllowRawSQLQuery" // AllowParameterizedSQLQuery is a feature gate for the apiserver to allow querying by the parameterized SQL // for better defense against SQL injection. // // Use either single whereSQLStatement field, a pair of whereSQLStatement with whereSQLParam, or // whereSQLStatement with whereSQLJSONParams to pass the SQL itself and parameters. // // owner: @nekomeowww // alpha: v0.8.0 AllowParameterizedSQLQuery featuregate.Feature = "AllowParameterizedSQLQuery" )
View Source
const ( SearchLabelFuzzyName = "internalstorage.clusterpedia.io/fuzzy-name" // Raw query URLQueryWhereSQL = "whereSQL" // Parameterized query URLQueryFieldWhereSQLStatement = "whereSQLStatement" URLQueryFieldWhereSQLParam = "whereSQLParam" URLQueryFieldWhereSQLJSONParams = "whereSQLJSONParams" )
View Source
const (
StorageName = "internal"
)
Variables ¶
This section is empty.
Functions ¶
func InterpretDBError ¶ added in v0.4.0
func InterpretMysqlError ¶ added in v0.4.0
func InterpretPostgresError ¶ added in v0.4.0
func InterpretResourceDBError ¶ added in v0.4.0
func NewCollectionResourceStorage ¶ added in v0.3.0
func NewCollectionResourceStorage(db *gorm.DB, cr *internal.CollectionResource) storage.CollectionResourceStorage
func NewGormTrace ¶ added in v0.9.0
func NewStorageFactory ¶
func NewStorageFactory(configPath string) (storage.StorageFactory, error)
Types ¶
type Bytes ¶ added in v0.4.0
func (Bytes) ConvertToUnstructured ¶ added in v0.4.0
func (bytes Bytes) ConvertToUnstructured() (*unstructured.Unstructured, error)
func (Bytes) GetResourceType ¶ added in v0.4.0
func (bytes Bytes) GetResourceType() ResourceType
type BytesWithEvents ¶ added in v0.9.0
type BytesWithEvents struct {
Object Bytes
Events EventsBytes
}
func (BytesWithEvents) ConvertToUnstructured ¶ added in v0.9.0
func (bytes BytesWithEvents) ConvertToUnstructured() (*unstructured.Unstructured, error)
func (BytesWithEvents) GetEvents ¶ added in v0.9.0
func (bytes BytesWithEvents) GetEvents() []*corev1.Event
func (BytesWithEvents) GetResourceType ¶ added in v0.9.0
func (bytes BytesWithEvents) GetResourceType() ResourceType
type BytesWithEventsList ¶ added in v0.9.0
type BytesWithEventsList []BytesWithEvents
func (*BytesWithEventsList) From ¶ added in v0.9.0
func (list *BytesWithEventsList) From(db *gorm.DB) error
func (BytesWithEventsList) Items ¶ added in v0.9.0
func (list BytesWithEventsList) Items() []Object
type CollectionResourceStorage ¶
type CollectionResourceStorage struct {
// contains filtered or unexported fields
}
func (*CollectionResourceStorage) Get ¶
func (s *CollectionResourceStorage) Get(ctx context.Context, opts *internal.ListOptions) (*internal.CollectionResource, error)
type Config ¶
type Config struct {
Type string `env:"DB_TYPE" required:"true"`
DSN string `env:"DB_DSN"`
Network string `env:"DB_NETWORK"` // Network type, either tcp or unix, Default is tcp
Host string `env:"DB_HOST"` // TCP host:port or Unix socket depending on Network
Port string `env:"DB_PORT"`
User string `env:"DB_USER"`
Password string `env:"DB_PASSWORD"`
Database string `env:"DB_DATABASE"`
SSLMode string `yaml:"sslMode"`
CertFile string `yaml:"sslCertFile"`
KeyFile string `yaml:"sslKeyFile"`
RootCertFile string `yaml:"sslRootCertFile"`
ConnPool ConnPoolConfig `yaml:"connPool"`
MySQL *MySQLConfig `yaml:"mysql"`
Postgres *PostgresConfig `yaml:"postgres"`
Params map[string]string `yaml:"params"`
Log *LogConfig `yaml:"log"`
Metrics MetricsConfig `yaml:"metrics"`
}
type ConnPoolConfig ¶ added in v0.3.0
type DBStats ¶ added in v0.9.0
type DBStats struct {
MaxOpenConnections prometheus.Gauge // Maximum number of open connections to the database.
// Pool status
OpenConnections prometheus.Gauge // The number of established connections both in use and idle.
InUse prometheus.Gauge // The number of connections currently in use.
Idle prometheus.Gauge // The number of idle connections.
// Counters
WaitCount prometheus.Gauge // The total number of connections waited for.
WaitDuration prometheus.Gauge // The total time blocked waiting for a new connection.
MaxIdleClosed prometheus.Gauge // The total number of connections closed due to SetMaxIdleConns.
MaxLifetimeClosed prometheus.Gauge // The total number of connections closed due to SetConnMaxLifetime.
MaxIdleTimeClosed prometheus.Gauge // The total number of connections closed due to SetConnMaxIdleTime.
}
type EventsBytes ¶ added in v0.9.0
type EventsBytes Bytes
func (EventsBytes) Decode ¶ added in v0.9.0
func (bytes EventsBytes) Decode() ([]*corev1.Event, error)
func (*EventsBytes) Scan ¶ added in v0.9.0
func (bytes *EventsBytes) Scan(data any) error
type JSONMap ¶ added in v0.9.0
func (JSONMap) GormDBDataType ¶ added in v0.9.0
func (JSONMap) GormDataType ¶ added in v0.9.0
func (JSONMap) MarshalJSON ¶ added in v0.9.0
func (*JSONMap) UnmarshalJSON ¶ added in v0.9.0
type JSONQueryExpression ¶
type JSONQueryExpression struct {
// contains filtered or unexported fields
}
func JSONQuery ¶
func JSONQuery(column string, keys ...string) *JSONQueryExpression
func (*JSONQueryExpression) Build ¶
func (jsonQuery *JSONQueryExpression) Build(builder clause.Builder)
func (*JSONQueryExpression) Equal ¶
func (jsonQuery *JSONQueryExpression) Equal(value string) *JSONQueryExpression
func (*JSONQueryExpression) Exist ¶ added in v0.1.0
func (jsonQuery *JSONQueryExpression) Exist() *JSONQueryExpression
func (*JSONQueryExpression) In ¶
func (jsonQuery *JSONQueryExpression) In(values ...string) *JSONQueryExpression
func (*JSONQueryExpression) NotEqual ¶
func (jsonQuery *JSONQueryExpression) NotEqual(value string) *JSONQueryExpression
func (*JSONQueryExpression) NotExist ¶ added in v0.1.0
func (jsonQuery *JSONQueryExpression) NotExist() *JSONQueryExpression
func (*JSONQueryExpression) NotIn ¶
func (jsonQuery *JSONQueryExpression) NotIn(values ...string) *JSONQueryExpression
type JSONUpdateExpression ¶ added in v0.9.0
type JSONUpdateExpression struct {
// contains filtered or unexported fields
}
func JSONUpdate ¶ added in v0.9.0
func JSONUpdate(column string, key string, value []byte) *JSONUpdateExpression
func (*JSONUpdateExpression) Build ¶ added in v0.9.0
func (jsonUpdate *JSONUpdateExpression) Build(builder clause.Builder)
type MetricsConfig ¶ added in v0.9.0
type MySQLConfig ¶
type MySQLConfig struct {
DialTimeout *time.Duration `yaml:"dialTimeout"`
ReadTimeout *time.Duration `yaml:"readTimeout"`
WriteTimeout *time.Duration `yaml:"writeTimeout"`
ServerPubKey *string `yaml:"serverPubKey"`
Loc *string `yaml:"loc"`
MaxAllowedPacket *int `yaml:"maxAllowedPacket"`
AllowAllFiles *bool `yaml:"allowAllFiles"` // Allow all files to be used with LOAD DATA LOCAL INFILE
AllowCleartextPasswords *bool `yaml:"allowCleartextPasswords"` // Allows the cleartext client side plugin
AllowNativePasswords *bool `yaml:"allowNativePasswords"` // Allows the native password authentication method
AllowOldPasswords *bool `yaml:"allowOldPasswords"` // Allows the old insecure password method
CheckConnLiveness *bool `yaml:"checkConnLiveness"` // Check connections for liveness before using them
ClientFoundRows *bool `yaml:"clientFoundRows"` // Return number of matching rows instead of rows changed
ColumnsWithAlias *bool `yaml:"columnsWithAlias"` // Prepend table alias to column names
InterpolateParams *bool `yaml:"interpolateParams"` // Interpolate placeholders into query string
MultiStatements *bool `yaml:"multiStatements"` // Allow multiple statements in one query
ParseTime *bool `yaml:"parseTime"` // Parse time values to time.Time
RejectReadOnly *bool `yaml:"rejectReadOnly"` // Reject read-only connections
RecoverableErrNumbers []int `yaml:"recoverableErrNumbers"`
}
type Object ¶ added in v0.3.0
type Object interface {
GetResourceType() ResourceType
ConvertToUnstructured() (*unstructured.Unstructured, error)
ConvertTo(codec runtime.Codec, object runtime.Object) (runtime.Object, error)
GetEvents() []*corev1.Event
}
type ObjectList ¶ added in v0.3.0
type PostgresConfig ¶
type PostgresConfig struct {
RecoverableErrCodes []string `yaml:"recoverableErrCodes"`
}
type Prometheus ¶ added in v0.9.0
type Prometheus struct {
*gorm.DB
*DBStats
Labels map[string]string
// contains filtered or unexported fields
}
Prometheus implements the gorm.Plugin and provides db metrics. The `Prometheus` structure name is preserved, and this file may be moved to a separate package in the future to be made available to other gorm-based storage layers.
func NewGormMetrics ¶ added in v0.9.0
func NewGormMetrics(dbName string, refreshInterval time.Duration) *Prometheus
func (*Prometheus) Initialize ¶ added in v0.9.0
func (p *Prometheus) Initialize(db *gorm.DB) error
func (*Prometheus) Name ¶ added in v0.9.0
func (p *Prometheus) Name() string
type Resource ¶
type Resource struct {
ID uint `gorm:"primaryKey"`
Group string `` /* 171-byte string literal not displayed */
Version string `` /* 171-byte string literal not displayed */
Resource string `` /* 171-byte string literal not displayed */
Kind string `gorm:"size:63;not null"`
Cluster string `gorm:"size:253;not null;uniqueIndex:uni_group_version_resource_cluster_namespace_name,length:100;index:idx_cluster"`
Namespace string `` /* 144-byte string literal not displayed */
Name string `` /* 183-byte string literal not displayed */
OwnerUID types.UID `gorm:"column:owner_uid;size:36;not null;default:''"`
UID types.UID `gorm:"size:36;not null"`
ResourceVersion string `gorm:"size:30;not null"`
Object datatypes.JSON `gorm:"not null"`
// Since MySQL doesn't allow setting default values for JSON fields, we can only avoid using NOT NULL and DEFAULT.
Events JSONMap
EventResourceVersions JSONMap
CreatedAt time.Time `gorm:"not null"`
SyncedAt time.Time `gorm:"not null;autoUpdateTime"`
DeletedAt sql.NullTime
}
func (Resource) ConvertToUnstructured ¶ added in v0.3.0
func (res Resource) ConvertToUnstructured() (*unstructured.Unstructured, error)
func (Resource) GetResourceType ¶ added in v0.3.0
func (res Resource) GetResourceType() ResourceType
func (Resource) GroupVersionResource ¶
func (res Resource) GroupVersionResource() schema.GroupVersionResource
type ResourceList ¶ added in v0.3.0
type ResourceList []Resource
func (ResourceList) Items ¶ added in v0.3.0
func (list ResourceList) Items() []Object
type ResourceMetadata ¶ added in v0.3.0
type ResourceMetadata struct {
ResourceType `gorm:"embedded"`
Metadata datatypes.JSON
}
func (ResourceMetadata) ConvertToUnstructured ¶ added in v0.3.0
func (data ResourceMetadata) ConvertToUnstructured() (*unstructured.Unstructured, error)
func (ResourceMetadata) GetEvents ¶ added in v0.9.0
func (data ResourceMetadata) GetEvents() []*corev1.Event
func (ResourceMetadata) GetResourceType ¶ added in v0.3.0
func (data ResourceMetadata) GetResourceType() ResourceType
type ResourceMetadataList ¶ added in v0.3.0
type ResourceMetadataList []ResourceMetadata
func (*ResourceMetadataList) From ¶ added in v0.3.0
func (list *ResourceMetadataList) From(db *gorm.DB) error
func (ResourceMetadataList) Items ¶ added in v0.3.0
func (list ResourceMetadataList) Items() []Object
type ResourceMetadataWithEvents ¶ added in v0.9.0
type ResourceMetadataWithEvents struct {
ResourceMetadata `gorm:"embedded"`
Events EventsBytes
}
func (ResourceMetadataWithEvents) ConvertToUnstructured ¶ added in v0.9.0
func (bytes ResourceMetadataWithEvents) ConvertToUnstructured() (*unstructured.Unstructured, error)
func (ResourceMetadataWithEvents) GetEvents ¶ added in v0.9.0
func (bytes ResourceMetadataWithEvents) GetEvents() []*corev1.Event
func (ResourceMetadataWithEvents) GetResourceType ¶ added in v0.9.0
func (bytes ResourceMetadataWithEvents) GetResourceType() ResourceType
type ResourceMetadataWithEventsList ¶ added in v0.9.0
type ResourceMetadataWithEventsList []ResourceMetadata
func (*ResourceMetadataWithEventsList) From ¶ added in v0.9.0
func (list *ResourceMetadataWithEventsList) From(db *gorm.DB) error
func (ResourceMetadataWithEventsList) Items ¶ added in v0.9.0
func (list ResourceMetadataWithEventsList) Items() []Object
type ResourceStorage ¶
type ResourceStorage struct {
// contains filtered or unexported fields
}
func (*ResourceStorage) ConvertDeletedObject ¶ added in v0.8.0
func (s *ResourceStorage) ConvertDeletedObject(obj interface{}) (runtime.Object, error)
func (*ResourceStorage) GetResourceEvents ¶ added in v0.9.0
func (*ResourceStorage) GetStorageConfig ¶
func (s *ResourceStorage) GetStorageConfig() *storage.ResourceStorageConfig
func (*ResourceStorage) List ¶
func (s *ResourceStorage) List(ctx context.Context, listObject runtime.Object, opts *internal.ListOptions) error
func (*ResourceStorage) RecordEvent ¶ added in v0.9.0
func (*ResourceStorage) Watch ¶ added in v0.6.0
func (s *ResourceStorage) Watch(_ context.Context, _ *internal.ListOptions) (watch.Interface, error)
type ResourceType ¶ added in v0.3.0
func (ResourceType) Empty ¶ added in v0.4.0
func (rt ResourceType) Empty() bool
func (ResourceType) GroupVersionResource ¶ added in v0.3.0
func (rt ResourceType) GroupVersionResource() schema.GroupVersionResource
type StorageFactory ¶
type StorageFactory struct {
// contains filtered or unexported fields
}
func (*StorageFactory) CleanCluster ¶
func (s *StorageFactory) CleanCluster(ctx context.Context, cluster string) error
func (*StorageFactory) CleanClusterResource ¶
func (s *StorageFactory) CleanClusterResource(ctx context.Context, cluster string, gvr schema.GroupVersionResource) error
func (*StorageFactory) GetCollectionResources ¶
func (s *StorageFactory) GetCollectionResources(ctx context.Context) ([]*internal.CollectionResource, error)
func (*StorageFactory) GetResourceVersions ¶
func (s *StorageFactory) GetResourceVersions(ctx context.Context, cluster string) (map[schema.GroupVersionResource]storage.ClusterResourceVersions, error)
func (*StorageFactory) GetSupportedRequestVerbs ¶ added in v0.6.0
func (s *StorageFactory) GetSupportedRequestVerbs() []string
func (*StorageFactory) NewCollectionResourceStorage ¶
func (s *StorageFactory) NewCollectionResourceStorage(cr *internal.CollectionResource) (storage.CollectionResourceStorage, error)
func (*StorageFactory) NewResourceStorage ¶
func (s *StorageFactory) NewResourceStorage(config *storage.ResourceStorageConfig) (storage.ResourceStorage, error)
func (*StorageFactory) PrepareCluster ¶ added in v0.6.0
func (s *StorageFactory) PrepareCluster(cluster string) error
func (*StorageFactory) Shutdown ¶ added in v0.9.0
func (s *StorageFactory) Shutdown() error
type URLQueryWhereSQLParams ¶ added in v0.7.1
type URLQueryWhereSQLParams struct {
// Raw query
WhereSQL string
// Parameterized query
WhereSQLStatement string
WhereSQLParams []string
WhereSQLJSONParams []any
}
func NewURLQueryWhereSQLParamsFromURLValues ¶ added in v0.7.1
func NewURLQueryWhereSQLParamsFromURLValues(urlQuery url.Values) (URLQueryWhereSQLParams, error)
NewURLQueryWhereSQLParamsFromURLValues resolves parameters from passed in url.Values. A k8s.io/apimachinery/pkg/api/errors.StatusError will be returned if decoding or unmarshalling failed only when the value of "whereSQLJSONParams" is present.
It recognizes the following query fields for parameters:
"whereSQL" "whereSQLStatement" "whereSQLParam" "whereSQLJSONParams"
Click to show internal directories.
Click to hide internal directories.