Skip to content

Commit

Permalink
初次提交
Browse files Browse the repository at this point in the history
  • Loading branch information
cmjzzx committed Aug 30, 2024
1 parent ac3a270 commit 281ac9b
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 31 deletions.
8 changes: 4 additions & 4 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: zwjk.com
domain: leqiutong.xyz
layout:
- go.kubebuilder.io/v4
projectName: k8s-database-operator
repo: git.ucmed.cn/pdd/k8s-database-operator
repo: github.com/cmjzzx/k8s-database-operator
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: zwjk.com
domain: leqiutong.xyz
group: apps
kind: DatabaseInstance
path: git.ucmed.cn/pdd/k8s-database-operator/api/v1
path: github.com/cmjzzx/k8s-database-operator/api/v1
version: v1
version: "3"
4 changes: 2 additions & 2 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

// Package v1 contains API Schema definitions for the apps v1 API group
// +kubebuilder:object:generate=true
// +groupName=apps.zwjk.com
// +groupName=apps.leqiutong.xyz
package v1

import (
Expand All @@ -26,7 +26,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "apps.zwjk.com", Version: "v1"}
GroupVersion = schema.GroupVersion{Group: "apps.leqiutong.xyz", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

appsv1 "git.ucmed.cn/pdd/k8s-database-operator/api/v1"
"git.ucmed.cn/pdd/k8s-database-operator/internal/controller"
appsv1 "github.com/cmjzzx/k8s-database-operator/api/v1"
"github.com/cmjzzx/k8s-database-operator/internal/controller"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -126,7 +126,7 @@ func main() {
WebhookServer: webhookServer,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "7e722def.zwjk.com",
LeaderElectionID: "7e722def.leqiutong.xyz",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
Expand Down
141 changes: 141 additions & 0 deletions config/crd/bases/apps.leqiutong.xyz_databaseinstances.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
name: databaseinstances.apps.leqiutong.xyz
spec:
group: apps.leqiutong.xyz
names:
kind: DatabaseInstance
listKind: DatabaseInstanceList
plural: databaseinstances
singular: databaseinstance
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: DatabaseInstance 是 databaseinstances API 的 Schema
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: Spec 定义了 DatabaseInstance 的期望状态
properties:
backupPolicy:
description: BackupPolicy 定义了备份策略配置
properties:
backupImage:
description: BackupImage 定义备份容器使用的镜像
type: string
enabled:
description: Enabled 指示是否启用备份
type: boolean
retention:
description: Retention 定义备份的保留策略
type: string
schedule:
description: Schedule 定义备份的计划
type: string
type: object
databaseType:
description: DatabaseType 表示数据库的类型(目前支持 mysql、postgres、oceanbase-ce
这 3 种)
type: string
image:
description: Image 表示数据库的容器镜像,包括版本/标签
type: string
replicas:
description: Replicas 表示数据库副本的数量
format: int32
type: integer
resources:
description: Resources 定义了数据库的资源请求和限制
properties:
requests:
description: Requests 定义了内存和 CPU 的资源请求
properties:
cpu:
description: CPU 表示 CPU 请求
type: string
memory:
description: Memory 表示内存请求
type: string
type: object
type: object
storage:
description: Storage 表示数据库的存储容量
type: string
version:
description: Version 表示数据库的版本
type: string
type: object
status:
description: Status 定义了 DatabaseInstance 资源的观察到的状态
properties:
conditions:
description: Conditions 记录数据库实例的条件或状态
items:
description: DatabaseInstanceCondition 表示数据库实例的特定方面的状态
properties:
lastTransitionTime:
description: LastTransitionTime 是条件从一个状态过渡到另一个状态的最后时间
format: date-time
type: string
message:
description: Message 表示相关条件的详细信息
type: string
reason:
description: Reason 表示条件最后一次过渡的原因
type: string
status:
description: Status 条件的状态(例如:True、False)
type: string
type:
description: Type 条件的类型(例如:Ready、Available)
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
lastUpdated:
description: LastUpdated 是状态最后一次更新的时间戳
format: date-time
type: string
message:
description: Message 表示相关状态的附加信息或错误消息
type: string
phase:
description: Phase 表示数据库实例当前所处的阶段(例如:Pending、Running、Failed)
type: string
readyReplicas:
description: ReadyReplicas 表示当前已就绪的副本数量
format: int32
type: integer
type: object
type: object
served: true
storage: true
subresources:
status: {}
4 changes: 2 additions & 2 deletions config/crd/bases/apps.zwjk.com_databaseinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
name: databaseinstances.apps.zwjk.com
name: databaseinstances.apps.leqiutong.xyz
spec:
group: apps.zwjk.com
group: apps.leqiutong.xyz
names:
kind: DatabaseInstance
listKind: DatabaseInstanceList
Expand Down
2 changes: 1 addition & 1 deletion config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/apps.zwjk.com_databaseinstances.yaml
- bases/apps.leqiutong.xyz_databaseinstances.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patches:
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/databaseinstance_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
name: databaseinstance-editor-role
rules:
- apiGroups:
- apps.zwjk.com
- apps.leqiutong.xyz
resources:
- databaseinstances
verbs:
Expand All @@ -20,7 +20,7 @@ rules:
- update
- watch
- apiGroups:
- apps.zwjk.com
- apps.leqiutong.xyz
resources:
- databaseinstances/status
verbs:
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/databaseinstance_viewer_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ metadata:
name: databaseinstance-viewer-role
rules:
- apiGroups:
- apps.zwjk.com
- apps.leqiutong.xyz
resources:
- databaseinstances
verbs:
- get
- list
- watch
- apiGroups:
- apps.zwjk.com
- apps.leqiutong.xyz
resources:
- databaseinstances/status
verbs:
Expand Down
6 changes: 3 additions & 3 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: manager-role
rules:
- apiGroups:
- apps.zwjk.com
- apps.leqiutong.xyz
resources:
- databaseinstances
verbs:
Expand All @@ -17,13 +17,13 @@ rules:
- update
- watch
- apiGroups:
- apps.zwjk.com
- apps.leqiutong.xyz
resources:
- databaseinstances/finalizers
verbs:
- update
- apiGroups:
- apps.zwjk.com
- apps.leqiutong.xyz
resources:
- databaseinstances/status
verbs:
Expand Down
2 changes: 1 addition & 1 deletion config/samples/apps_v1_databaseinstance.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: apps.zwjk.com/v1
apiVersion: apps.leqiutong.xyz/v1
kind: DatabaseInstance
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module git.ucmed.cn/pdd/k8s-database-operator
module github.com/cmjzzx/k8s-database-operator

go 1.22.0

Expand Down
10 changes: 5 additions & 5 deletions internal/controller/databaseinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

databasev1 "git.ucmed.cn/pdd/k8s-database-operator/api/v1" // 导入 databasev1
"git.ucmed.cn/pdd/k8s-database-operator/internal/pkg/helpers" // 辅助函数
databasev1 "github.com/cmjzzx/k8s-database-operator/api/v1" // 导入 databasev1
"github.com/cmjzzx/k8s-database-operator/internal/pkg/helpers" // 辅助函数
)

// 定义 DatabaseInstanceReconciler 结构体,负责调节 DatabaseInstance 对象的状态
Expand All @@ -46,9 +46,9 @@ type DatabaseInstanceReconciler struct {
Scheme *runtime.Scheme
}

// +kubebuilder:rbac:groups=apps.zwjk.com,resources=databaseinstances,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps.zwjk.com,resources=databaseinstances/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps.zwjk.com,resources=databaseinstances/finalizers,verbs=update
// +kubebuilder:rbac:groups=apps.leqiutong.xyz,resources=databaseinstances,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps.leqiutong.xyz,resources=databaseinstances/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps.leqiutong.xyz,resources=databaseinstances/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/databaseinstance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

appsv1 "git.ucmed.cn/pdd/k8s-database-operator/api/v1"
appsv1 "github.com/cmjzzx/k8s-database-operator/api/v1"
)

var _ = Describe("DatabaseInstance Controller", func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

appsv1 "git.ucmed.cn/pdd/k8s-database-operator/api/v1"
appsv1 "github.com/cmjzzx/k8s-database-operator/api/v1"
// +kubebuilder:scaffold:imports
)

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/helpers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// GenerateImageName 生成完整的镜像名称
func GenerateImageName(baseImage, databaseType, version string) string {
const imagePrefix = "registry.zwjk.com/middleware/"
const imagePrefix = "registry.leqiutong.xyz/middleware/"
image := baseImage
if image == "" {
image = fmt.Sprintf("%s:%s", databaseType, version)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/helpers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package helpers
import (
"context"

databasev1 "git.ucmed.cn/pdd/k8s-database-operator/api/v1"
databasev1 "github.com/cmjzzx/k8s-database-operator/api/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"git.ucmed.cn/pdd/k8s-database-operator/test/utils"
"github.com/cmjzzx/k8s-database-operator/test/utils"
)

const namespace = "k8s-database-operator-system"
Expand Down

0 comments on commit 281ac9b

Please sign in to comment.