Skip to content

Commit

Permalink
refactor: object storage configure (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviderli614 authored Dec 29, 2023
1 parent 6ec8ec5 commit b8ccaba
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 210 deletions.
3 changes: 2 additions & 1 deletion apis/v1alpha1/defaulting.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
defaultDataNodeStorageName = "datanode"
defaultDataNodeStorageSize = "10Gi"
defaultDataNodeStorageMountPath = "/data/greptimedb"
defaultStorageRetainPolicyType = RetainStorageRetainPolicyTypeRetain
defaultStorageRetainPolicyType = StorageRetainPolicyTypeRetain

defaultInitializer = "greptime/greptimedb-initializer:latest"
)
Expand Down Expand Up @@ -139,6 +139,7 @@ func (in *GreptimeDBCluster) SetDefaults() error {
MountPath: defaultDataNodeStorageMountPath,
StorageRetainPolicy: defaultStorageRetainPolicyType,
WalDir: defaultDataNodeStorageMountPath + "/wal",
DataHome: defaultDataNodeStorageMountPath,
},
}
if in.Spec.Datanode.Replicas == nil {
Expand Down
23 changes: 18 additions & 5 deletions apis/v1alpha1/defaulting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func TestSetDefaults(t *testing.T) {
MountPath: defaultDataNodeStorageMountPath,
StorageRetainPolicy: defaultStorageRetainPolicyType,
WalDir: defaultDataNodeStorageMountPath + "/wal",
DataHome: defaultDataNodeStorageMountPath,
},
},
HTTPServicePort: int32(defaultHTTPServicePort),
Expand Down Expand Up @@ -376,6 +377,7 @@ func TestSetDefaults(t *testing.T) {
MountPath: defaultDataNodeStorageMountPath,
StorageRetainPolicy: defaultStorageRetainPolicyType,
WalDir: defaultDataNodeStorageMountPath + "/wal",
DataHome: defaultDataNodeStorageMountPath,
},
},

Expand Down Expand Up @@ -403,6 +405,15 @@ func TestSetDefaults(t *testing.T) {
ComponentSpec: ComponentSpec{
Replicas: proto.Int32(0),
},
Storage: StorageSpec{
Name: "data",
StorageClassName: proto.String("ebs-gp3"),
StorageSize: "20Gi",
MountPath: "/tmp/greptimedb",
StorageRetainPolicy: StorageRetainPolicyTypeDelete,
WalDir: "tmp/greptimedb/wal",
DataHome: "/tmp/greptimedb",
},
},
Frontend: &FrontendSpec{
ComponentSpec: ComponentSpec{
Expand Down Expand Up @@ -530,11 +541,13 @@ func TestSetDefaults(t *testing.T) {
},
},
Storage: StorageSpec{
Name: defaultDataNodeStorageName,
StorageSize: defaultDataNodeStorageSize,
MountPath: defaultDataNodeStorageMountPath,
StorageRetainPolicy: defaultStorageRetainPolicyType,
WalDir: defaultDataNodeStorageMountPath + "/wal",
Name: "data",
StorageClassName: proto.String("ebs-gp3"),
StorageSize: "20Gi",
MountPath: "/tmp/greptimedb",
StorageRetainPolicy: StorageRetainPolicyTypeDelete,
WalDir: "tmp/greptimedb/wal",
DataHome: "/tmp/greptimedb",
},
},

Expand Down
43 changes: 15 additions & 28 deletions apis/v1alpha1/greptimedbcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
type StorageRetainPolicyType string

const (
// RetainStorageRetainPolicyTypeRetain is the default options.
// StorageRetainPolicyTypeRetain is the default options.
// The storage(PVCs) will be retained when the cluster is deleted.
RetainStorageRetainPolicyTypeRetain StorageRetainPolicyType = "Retain"
StorageRetainPolicyTypeRetain StorageRetainPolicyType = "Retain"

// RetainStorageRetainPolicyTypeDelete specify that the storage will be deleted when the associated StatefulSet delete.
RetainStorageRetainPolicyTypeDelete StorageRetainPolicyType = "Delete"
// StorageRetainPolicyTypeDelete specify that the storage will be deleted when the associated StatefulSet delete.
StorageRetainPolicyTypeDelete StorageRetainPolicyType = "Delete"
)

// ComponentKind is the kind of the component in the cluster.
Expand Down Expand Up @@ -330,11 +330,14 @@ type StorageSpec struct {
// The PVCs will retain or delete when the cluster is deleted, default to Retain.
// +optional
// +kubebuilder:validation:Enum:={"Retain", "Delete"}
// +kubebuilder:default:="Retain"
StorageRetainPolicy StorageRetainPolicyType `json:"storageRetainPolicy,omitempty"`

// The wal directory of the storage.
WalDir string `json:"walDir,omitempty"`

// The datahome directory.
// +optional
DataHome string `json:"dataHome,omitempty"`
}

type ServiceSpec struct {
Expand Down Expand Up @@ -390,13 +393,12 @@ type InitializerSpec struct {
Image string `json:"image,omitempty"`
}

// StorageProvider defines the storage provider for the cluster. The data will be stored in the storage.
type StorageProvider struct {
S3 *S3StorageProvider `json:"s3,omitempty"`
OSS *OSSStorageProvider `json:"oss,omitempty"`
Local *LocalStorageProvider `json:"local,omitempty"`
CachePath string `json:"cachePath,omitempty"`
CacheCapacity string `json:"cacheCapacity,omitempty"`
// ObjectStorageProvider defines the storage provider for the cluster. The data will be stored in the storage.
type ObjectStorageProvider struct {
S3 *S3StorageProvider `json:"s3,omitempty"`
OSS *OSSStorageProvider `json:"oss,omitempty"`
CachePath string `json:"cachePath,omitempty"`
CacheCapacity string `json:"cacheCapacity,omitempty"`
}

type S3StorageProvider struct {
Expand All @@ -420,11 +422,6 @@ type S3StorageProvider struct {
// The S3 directory path.
// +optional
Root string `json:"root,omitempty"`

// The datahome directory
// +optional
// +kubebuilder:default:="/data/greptimedb"
DataHome string `json:"dataHome,omitempty"`
}

type OSSStorageProvider struct {
Expand All @@ -448,16 +445,6 @@ type OSSStorageProvider struct {
// The OSS directory path.
// +optional
Root string `json:"root,omitempty"`

// The datahome directory
// +optional
// +kubebuilder:default:="/data/greptimedb"
DataHome string `json:"dataHome,omitempty"`
}

type LocalStorageProvider struct {
// The local directory to store the data.
DataHome string `json:"dataHome,omitempty"`
}

// GreptimeDBClusterSpec defines the desired state of GreptimeDBCluster
Expand Down Expand Up @@ -510,7 +497,7 @@ type GreptimeDBClusterSpec struct {
Initializer *InitializerSpec `json:"initializer,omitempty"`

// +optional
StorageProvider *StorageProvider `json:"storage,omitempty"`
ObjectStorageProvider *ObjectStorageProvider `json:"objectStorage,omitempty"`

// More cluster settings can be added here.
}
Expand Down
76 changes: 28 additions & 48 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 23 additions & 33 deletions config/crd/resources/greptime.io_greptimedbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2695,14 +2695,15 @@ spec:
type: integer
storage:
properties:
dataHome:
type: string
mountPath:
type: string
name:
type: string
storageClassName:
type: string
storageRetainPolicy:
default: Retain
enum:
- Retain
- Delete
Expand Down Expand Up @@ -10690,44 +10691,16 @@ spec:
mysqlServicePort:
format: int32
type: integer
openTSDBServicePort:
format: int32
type: integer
postgresServicePort:
format: int32
type: integer
prometheusMonitor:
properties:
enabled:
type: boolean
interval:
type: string
labels:
additionalProperties:
type: string
type: object
type: object
prometheusServicePort:
format: int32
type: integer
storage:
objectStorage:
properties:
cacheCapacity:
type: string
cachePath:
type: string
local:
properties:
dataHome:
type: string
type: object
oss:
properties:
bucket:
type: string
dataHome:
default: /data/greptimedb
type: string
endpoint:
type: string
region:
Expand All @@ -10741,9 +10714,6 @@ spec:
properties:
bucket:
type: string
dataHome:
default: /data/greptimedb
type: string
endpoint:
type: string
region:
Expand All @@ -10754,6 +10724,26 @@ spec:
type: string
type: object
type: object
openTSDBServicePort:
format: int32
type: integer
postgresServicePort:
format: int32
type: integer
prometheusMonitor:
properties:
enabled:
type: boolean
interval:
type: string
labels:
additionalProperties:
type: string
type: object
type: object
prometheusServicePort:
format: int32
type: integer
version:
type: string
type: object
Expand Down
2 changes: 1 addition & 1 deletion config/samples/cluster-with-oss/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
- "etcd.default:2379"
datanode:
replicas: 3
storage:
objectStorage:
oss:
bucket: "greptimedb"
secretName: "oss-credentials"
Expand Down
2 changes: 1 addition & 1 deletion config/samples/cluster-with-s3/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
- "etcd.default:2379"
datanode:
replicas: 3
storage:
objectStorage:
s3:
bucket: "greptimedb"
region: "ap-southeast-1"
Expand Down
2 changes: 1 addition & 1 deletion controllers/greptimedbcluster/deployers/datanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *DatanodeDeployer) CleanUp(ctx context.Context, crdObject client.Object)
}

if cluster.Spec.Datanode != nil {
if cluster.Spec.Datanode.Storage.StorageRetainPolicy == v1alpha1.RetainStorageRetainPolicyTypeDelete {
if cluster.Spec.Datanode.Storage.StorageRetainPolicy == v1alpha1.StorageRetainPolicyTypeDelete {
if err := d.deleteStorage(ctx, cluster); err != nil {
return err
}
Expand Down
Loading

0 comments on commit b8ccaba

Please sign in to comment.