Skip to content

Commit

Permalink
feat(oss): impl oss store, user, bucket controllers (#306)
Browse files Browse the repository at this point in the history
Signed-off-by: maslow <wangfugen@126.com>

Signed-off-by: maslow <wangfugen@126.com>
  • Loading branch information
maslow authored Sep 1, 2022
1 parent 6f2d672 commit d854642
Show file tree
Hide file tree
Showing 22 changed files with 1,082 additions and 166 deletions.
4 changes: 2 additions & 2 deletions controllers/application/api/v1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ type ApplicationStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Appid
// AppId
//+kubebuilder:validation:MinLength=3
//+kubebuilder:validation:MaxLength=16
//+kubebuilder:validation:Required
Appid string `json:"appid"`
AppId string `json:"appid"`

// Specification for the application
Specification SpecificationSpec `json:"specification"`
Expand Down
2 changes: 1 addition & 1 deletion controllers/database/api/v1/database_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type DatabaseStatus struct {
// Store name of this database.
// The controller has created the corresponding storage resources based on this store.
//+kubebuilder:validation:Required
StoreName string `json:"store,omitempty"`
StoreName string `json:"storeName,omitempty"`

//+kubebuilder:validation:Required
StoreNamespace string `json:"storeNamespace,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ spec:
connectionURI:
description: ConnectionURI of the database.
type: string
store:
storeName:
description: Store name of this database. The controller has created
the corresponding storage resources based on this store.
type: string
Expand Down
1 change: 0 additions & 1 deletion controllers/database/controllers/database_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ func (r *DatabaseReconciler) selectStore(ctx context.Context, database *database

// select the store:
// - match the provider
// - match the region
// - have enough capacity
// - have the higher priority
var store databasev1.Store
Expand Down
54 changes: 25 additions & 29 deletions controllers/oss/api/v1/bucket_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -27,56 +28,51 @@ import (
type BucketPolicy string

const (
BucketPolicyReadOnly BucketPolicy = "readonly"
BucketPolicyReadWrite BucketPolicy = "public"
BucketPolicyPrivate BucketPolicy = "private"
BucketPolicyPrivate BucketPolicy = "private"
BucketPolicyReadOnly BucketPolicy = "readonly"
BucketPolicyPublic BucketPolicy = "readwrite"
)

// BucketSpec defines the desired state of Bucket
type BucketSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Name of bucket in oss. It's read-only after creation.
// This will be used as the bucket name in storage store.
// The length is between 3-63 and can only include letters, numbers and short horizontal lines (-).
//+kubebuilder:validation:Required
//+kubebuilder:validation:MinLength=3
//+kubebuilder:validation:MaxLength=64
//+kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
Name string `json:"name"`

// Policy of bucket in oss. required.
//+kubebuilder:validation:Required
// Policy of bucket in oss, defaults to 'private'.
//+kubebuilder:validation:Enum=private;readonly;readwrite
//+kubebuilder:validation:Default=private
//+optional
Policy BucketPolicy `json:"policy"`

// Storage space of this bucket, in MB. It defaults to 0, which means no limit.
// Storage space of this bucket.
//+kubebuilder:validation:Required
//+kubebuilder:validation:Minimum=0
//+kubebuilder:default=0
Storage int64 `json:"storage"`

// The name of oss user.
//+kubebuilder:validation:Required
User string `json:"user"`
Storage resource.Quantity `json:"storage"`
}

// BucketStatus defines the observed state of Bucket
type BucketStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Username of bucket in oss.
User string `json:"user"`

// Policy of bucket in oss.
Policy BucketPolicy `json:"policy"`

// Versioning of bucket in oss.
Versioning bool `json:"versioning"`

// Capacity of this bucket.
Capacity BucketCapacity `json:"capacity,omitempty"`
Capacity BucketCapacity `json:"capacity"`
}

type BucketCapacity struct {
// The user's storage space. The unit is MB.
// The default value is 0 which means unlimited.
//+kubebuilder:validation:Minimum=0
//+kubebuilder:default=0
//+optional
Storage int64 `json:"storage,omitempty"`
// Storage space of this bucket.
MaxStorage resource.Quantity `json:"maxStorage,omitempty"`

// The used storage space.
UsedStorage resource.Quantity `json:"storage,omitempty"`

// The user's number of objects.
//+optional
Expand Down
27 changes: 23 additions & 4 deletions controllers/oss/api/v1/store_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -32,10 +33,8 @@ type StoreCapacity struct {

// The storage space. The unit is MB.
// The default value is 0 which means unlimited.
//+kubebuilder:validation:Minimum=0
//+kubebuilder:default=0
//+optional
Storage int64 `json:"storage,omitempty"`
Storage resource.Quantity `json:"storage,omitempty"`

// The number of objects. The default value is 0 which means unlimited.
//+optional
Expand All @@ -50,6 +49,16 @@ type StoreCapacity struct {
BucketCount int64 `json:"bucketCount,omitempty"`
}

type StoreState string

const (
// StoreStateEnabled means the store is enabled.
StoreStateEnabled StoreState = "Enabled"

// StoreStateDisabled means the store is disabled.
StoreStateDisabled StoreState = "Disabled"
)

// StoreSpec defines the desired state of Store
type StoreSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
Expand Down Expand Up @@ -85,6 +94,11 @@ type StoreSpec struct {
//+kubebuilder:validation:Required
Endpoint string `json:"endpoint,omitempty"`

// UseSSL indicates whether to use ssl to connect to the store service.
//+kubebuilder:validation:Required
//+kubebuilder:default=false
UseSSL bool `json:"useSSL,omitempty"`

// AccessKey is the access key which have admin rights of the store service.
//+kubebuilder:validation:Required
AccessKey string `json:"accessKey,omitempty"`
Expand All @@ -99,7 +113,7 @@ type StoreSpec struct {

// Priority is used to guide the allocation of resources.
// The higher the priority, the first to allocate resources in.
// If this value is 0, this store will not be selected for allocating new user.
// If this value is 0, this store will not be selected for allocating new user.
//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Maximum=100
//+kubebuilder:default=10
Expand All @@ -115,6 +129,11 @@ type StoreStatus struct {
// The observed capacity of Store.
//+optional
Capacity StoreCapacity `json:"capacity,omitempty"`

// The state of the store, defaults to "Pending".
//+kubebuilder:default=Pending
//+kubebuilder:validation:Enum=Pending;Enabled;Disabled
State StoreState `json:"state,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
51 changes: 28 additions & 23 deletions controllers/oss/api/v1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -28,16 +29,23 @@ type UserSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// AppId is the unique identifier for the app, usually used as the username of this User.
//+kubebuilder:validation:MinLength=3
//+kubebuilder:validation:MaxLength=32
//+kubebuilder:validation:Required
AppId string `json:"appid"`

// Password is the secret name of the user, which is used to authenticate the user.
//+kubebuilder:validation:MinLength=3
//+kubebuilder:validation:MaxLength=32
//+kubebuilder:validation:Required
Password string `json:"password"`

// Provider name of a oss store. It's read-only after creation.
// The controller will create the corresponding storage resources based on this provider.
//+kubebuilder:validation:Required
Provider string `json:"provider"`

// Region of oss store. It's read-only after creation.
// The controller will create the corresponding storage resources based on this region.
//+kubebuilder:validation:Required
Region string `json:"region"`

// Capacity that user desired.
Capacity UserCapacity `json:"capacity,omitempty"`
}
Expand All @@ -47,41 +55,38 @@ type UserStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// AccessKey for this user. This field might be generated by controller if accessKey not given in spec.
AccessKey string `json:"accessKey,omitempty"`

// SecretKey for this user. This field might be generated by controller if accessKey not given in spec.
SecretKey string `json:"secretKey,omitempty"`

// Store name of a oss store. It's read-only after creation.
// StoreName of the oss store. It's read-only after creation.
// The controller has created the corresponding storage resources based on this store.
//+kubebuilder:validation:Required
Store string `json:"store,omitempty"`
StoreName string `json:"storeName,omitempty"`

// The region name identifies the location of the store.
//+kubebuilder:validation:Required
//+kubebuilder:validation:MinLength=2
//+kubebuilder:validation:MaxLength=64
//+kubebuilder:default=default
//+kubebuilder:validation:Pattern=[a-zA-Z0-9-]+
Region string `json:"region,omitempty"`
StoreNamespace string `json:"storeNamespace,omitempty"`

// AccessKey is the access key of the user
AccessKey string `json:"accessKey,omitempty"`

// SecretKey is the secret key of the user
SecretKey string `json:"secretKey,omitempty"`

// Endpoint is the store service endpoint.
//+kubebuilder:validation:Required
Endpoint string `json:"endpoint,omitempty"`

// Region of oss store.
//+kubebuilder:validation:Required
Region string `json:"region"`

// The user's capacity observed by the controller.
Capacity UserCapacity `json:"capacity,omitempty"`
}

// UserCapacity is used to obtain the user's used capacity.
type UserCapacity struct {
// The user's storage space. The unit is MB.
// The user's storage space.
// The default value is 0 which means unlimited.
//+kubebuilder:validation:Minimum=0
//+kubebuilder:default=0
//+optional
Storage int64 `json:"storage,omitempty"`
Storage resource.Quantity `json:"storage,omitempty"`

// The user's number of objects.
//+optional
Expand Down
Loading

0 comments on commit d854642

Please sign in to comment.