Skip to content

Commit

Permalink
feat(oss): add bucket crd
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Aug 25, 2022
1 parent 7cfe30e commit cc0c982
Show file tree
Hide file tree
Showing 16 changed files with 537 additions and 34 deletions.
9 changes: 9 additions & 0 deletions controllers/oss/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ resources:
kind: User
path: github.com/labring/laf/controllers/oss/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: laf.dev
group: oss
kind: Bucket
path: github.com/labring/laf/controllers/oss/api/v1
version: v1
version: "3"
111 changes: 111 additions & 0 deletions controllers/oss/api/v1/bucket_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// BucketPolicy mode
type BucketPolicy string

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

// 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 BucketPolicy `json:"policy"`

// Storage space of this bucket, in MB. It defaults to 0, which means no limit.
//+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"`
}

// 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

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

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"`

// The user's number of objects.
//+optional
//+kubebuilder:validation:Minimum=0
//+kubebuilder:default=0
ObjectCount int64 `json:"objectCount,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Bucket is the Schema for the buckets API
type Bucket struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BucketSpec `json:"spec,omitempty"`
Status BucketStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// BucketList contains a list of Bucket
type BucketList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Bucket `json:"items"`
}

func init() {
SchemeBuilder.Register(&Bucket{}, &BucketList{})
}
27 changes: 14 additions & 13 deletions controllers/oss/api/v1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ type UserSpec struct {
//+kubebuilder:validation:Required
Region string `json:"region"`

// AccessKey for this user. It's read-only after creation.
// This field is used to specify the user's access Key. This key is used to access OSS.
// If you do not specify an accesskey, the accessKey will be automatically generated by Controller.
//+optional
AccessKey string `json:"accessKey,omitempty"`

// SecretKey for this user. It's read-only after creation.
// This field is used to specify the user's secret Key. This key is used to access OSS.
// If you do not specify an secretkey, the secretKey will be automatically generated by Controller.
//+optional
SecretKey string `json:"secretKey,omitempty"`

// Capacity that user desired.
Capacity UserCapacity `json:"capacity,omitempty"`
}
Expand All @@ -65,12 +53,25 @@ type UserStatus struct {
// 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.
// The controller has created the corresponding storage resources based on this store.
//+kubebuilder:validation:Required
Store string `json:"store,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"`

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

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

// UserCapacity is used to obtain the user's used capacity.
Expand Down
105 changes: 105 additions & 0 deletions controllers/oss/api/v1/zz_generated.deepcopy.go

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

91 changes: 91 additions & 0 deletions controllers/oss/config/crd/bases/oss.laf.dev_buckets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: buckets.oss.laf.dev
spec:
group: oss.laf.dev
names:
kind: Bucket
listKind: BucketList
plural: buckets
singular: bucket
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: Bucket is the Schema for the buckets API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: BucketSpec defines the desired state of Bucket
properties:
name:
description: 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 (-).
maxLength: 64
minLength: 3
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
policy:
description: Policy of bucket in oss. required.
type: string
storage:
default: 0
description: Storage space of this bucket, in MB. It defaults to 0,
which means no limit.
format: int64
minimum: 0
type: integer
user:
description: The name of oss user.
type: string
required:
- name
- policy
- storage
- user
type: object
status:
description: BucketStatus defines the observed state of Bucket
properties:
capacity:
description: Capacity of this bucket.
properties:
objectCount:
default: 0
description: The user's number of objects.
format: int64
minimum: 0
type: integer
storage:
default: 0
description: The user's storage space. The unit is MB. The default
value is 0 which means unlimited.
format: int64
minimum: 0
type: integer
type: object
type: object
type: object
served: true
storage: true
subresources:
status: {}
Loading

0 comments on commit cc0c982

Please sign in to comment.