From 0d15d0674eee672229389d4d0bb3452a9f0fbf64 Mon Sep 17 00:00:00 2001 From: whg517 Date: Thu, 11 Jan 2024 19:31:17 +0800 Subject: [PATCH 1/2] feat: update apis version and typos --- CHANGELOG.md | 11 +++ .../authentication_types.go | 2 +- .../{v1alhpa1 => v1alpha1}/database_types.go | 4 +- .../commons/{v1alhpa1 => v1alpha1}/doc.go | 2 +- .../{v1alhpa1 => v1alpha1}/s3_types.go | 5 +- .../zz_generated.deepcopy.go | 2 +- pkg/image/image_spec.go | 29 ------- pkg/ingress/ingress_spec.go | 44 ---------- pkg/persistence/persistence_spec.go | 87 ------------------- pkg/service/service_spec.go | 36 -------- ...reconcilier_util.go => reconciler_util.go} | 0 11 files changed, 20 insertions(+), 202 deletions(-) rename pkg/apis/commons/{v1alhpa1 => v1alpha1}/authentication_types.go (98%) rename pkg/apis/commons/{v1alhpa1 => v1alpha1}/database_types.go (98%) rename pkg/apis/commons/{v1alhpa1 => v1alpha1}/doc.go (90%) rename pkg/apis/commons/{v1alhpa1 => v1alpha1}/s3_types.go (96%) rename pkg/apis/commons/{v1alhpa1 => v1alpha1}/zz_generated.deepcopy.go (99%) delete mode 100644 pkg/image/image_spec.go delete mode 100644 pkg/ingress/ingress_spec.go delete mode 100644 pkg/persistence/persistence_spec.go delete mode 100644 pkg/service/service_spec.go rename pkg/util/{reconcilier_util.go => reconciler_util.go} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..7536471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# CHANGELOG + +## v0.0.1 2021-01-11 + +### features + +- Add `DatabaseConnection` and `Database` struct, and implement mysql, postgres, redis. +- Add `S3Conection` and `S3Bucket` struct. +- Add `AuthenticationClass` struct, and implement oidc. +- Add errors and conditions constants +- Add `CreateOrUpdate` for k8s object create or update. diff --git a/pkg/apis/commons/v1alhpa1/authentication_types.go b/pkg/apis/commons/v1alpha1/authentication_types.go similarity index 98% rename from pkg/apis/commons/v1alhpa1/authentication_types.go rename to pkg/apis/commons/v1alpha1/authentication_types.go index df97138..4c5d997 100644 --- a/pkg/apis/commons/v1alhpa1/authentication_types.go +++ b/pkg/apis/commons/v1alpha1/authentication_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alhpa1 +package v1alpha1 type ResponseType string diff --git a/pkg/apis/commons/v1alhpa1/database_types.go b/pkg/apis/commons/v1alpha1/database_types.go similarity index 98% rename from pkg/apis/commons/v1alhpa1/database_types.go rename to pkg/apis/commons/v1alpha1/database_types.go index f3113a2..7d2f8e7 100644 --- a/pkg/apis/commons/v1alhpa1/database_types.go +++ b/pkg/apis/commons/v1alpha1/database_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alhpa1 +package v1alpha1 import ( "github.com/zncdata-labs/operator-go/pkg/status" @@ -140,5 +140,5 @@ type RedisProvider struct { // +kubebuilder:validation:Required Port string `json:"port,omitempty"` // +kubebuilder:validation:Optional - Password string `json:"password,omitempty"` + Credential *DatabaseConnectionCredentialSpec `json:"credential,omitempty"` } diff --git a/pkg/apis/commons/v1alhpa1/doc.go b/pkg/apis/commons/v1alpha1/doc.go similarity index 90% rename from pkg/apis/commons/v1alhpa1/doc.go rename to pkg/apis/commons/v1alpha1/doc.go index 3f26057..01f238d 100644 --- a/pkg/apis/commons/v1alhpa1/doc.go +++ b/pkg/apis/commons/v1alpha1/doc.go @@ -2,4 +2,4 @@ // +kubebuilder:object:generate=true // +groupName=stack.zncdata.net -package v1alhpa1 +package v1alpha1 diff --git a/pkg/apis/commons/v1alhpa1/s3_types.go b/pkg/apis/commons/v1alpha1/s3_types.go similarity index 96% rename from pkg/apis/commons/v1alhpa1/s3_types.go rename to pkg/apis/commons/v1alpha1/s3_types.go index e2222a0..bbfa255 100644 --- a/pkg/apis/commons/v1alhpa1/s3_types.go +++ b/pkg/apis/commons/v1alpha1/s3_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alhpa1 +package v1alpha1 import ( "github.com/zncdata-labs/operator-go/pkg/status" @@ -33,6 +33,9 @@ type S3ConnectionSpec struct { Region string `json:"region,omitempty"` // +kubebuilder:validation:Optional SSL bool `json:"ssl,omitempty"` + // +kubebuilder:validation:Optional + // +kubebuilder:default:=false + PathStyle bool `json:"pathStyle,omitempty"` } // S3Credential include AccessKey and SecretKey or ExistingSecret. diff --git a/pkg/apis/commons/v1alhpa1/zz_generated.deepcopy.go b/pkg/apis/commons/v1alpha1/zz_generated.deepcopy.go similarity index 99% rename from pkg/apis/commons/v1alhpa1/zz_generated.deepcopy.go rename to pkg/apis/commons/v1alpha1/zz_generated.deepcopy.go index 612e908..c03ccc4 100644 --- a/pkg/apis/commons/v1alhpa1/zz_generated.deepcopy.go +++ b/pkg/apis/commons/v1alpha1/zz_generated.deepcopy.go @@ -2,7 +2,7 @@ // Code generated by controller-gen. DO NOT EDIT. -package v1alhpa1 +package v1alpha1 import ( runtime "k8s.io/apimachinery/pkg/runtime" diff --git a/pkg/image/image_spec.go b/pkg/image/image_spec.go deleted file mode 100644 index 72c1769..0000000 --- a/pkg/image/image_spec.go +++ /dev/null @@ -1,29 +0,0 @@ -package image - -import corev1 "k8s.io/api/core/v1" - -type ImageSpec struct { - // +kubebuilder:validation:Optional - Repository string `json:"repository,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:="3.4.1" - Tag string `json:"tag,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:=IfNotPresent - PullPolicy corev1.PullPolicy `json:"pullPolicy,omitempty"` -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ImageSpec) DeepCopyInto(out *ImageSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageSpec. -func (in *ImageSpec) DeepCopy() *ImageSpec { - if in == nil { - return nil - } - out := new(ImageSpec) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/ingress/ingress_spec.go b/pkg/ingress/ingress_spec.go deleted file mode 100644 index cc13888..0000000 --- a/pkg/ingress/ingress_spec.go +++ /dev/null @@ -1,44 +0,0 @@ -package ingress - -import ( - networkingv1 "k8s.io/api/networking/v1" -) - -type IngressSpec struct { - // +kubebuilder:validation:Optional - // +kubebuilder:default:=true - Enabled bool `json:"enabled,omitempty"` - // +kubebuilder:validation:Optional - TLS *networkingv1.IngressTLS `json:"tls,omitempty"` - // +kubebuilder:validation:Optional - Annotations map[string]string `json:"annotations,omitempty"` - // +kubebuilder:validation:Optional - Host string `json:"host,omitempty"` -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *IngressSpec) DeepCopyInto(out *IngressSpec) { - *out = *in - if in.TLS != nil { - in, out := &in.TLS, &out.TLS - *out = new(networkingv1.IngressTLS) - (*in).DeepCopyInto(*out) - } - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressSpec. -func (in *IngressSpec) DeepCopy() *IngressSpec { - if in == nil { - return nil - } - out := new(IngressSpec) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/persistence/persistence_spec.go b/pkg/persistence/persistence_spec.go deleted file mode 100644 index 19fc13b..0000000 --- a/pkg/persistence/persistence_spec.go +++ /dev/null @@ -1,87 +0,0 @@ -package persistence - -import corev1 "k8s.io/api/core/v1" - -type PersistenceSpec struct { - // +kubebuilder:validation:Optional - // +kubebuilder:default:=true - Enable bool `json:"enable,omitempty"` - // +kubebuilder:validation:Optional - ExistingClaim *string `json:"existingClaim,omitempty"` - // +kubebuilder:validation:Optional - Annotations map[string]string `json:"annotations,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:="10Gi" - StorageSize string `json:"storageSize,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:="ReadWriteOnce" - AccessMode string `json:"accessMode,omitempty"` - // +kubebuilder:validation:Optional - StorageClassName *string `json:"storageClassName,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default=Filesystem - VolumeMode *corev1.PersistentVolumeMode `json:"volumeMode,omitempty"` - // +kubebuilder:validation:Optional - StorageClass *string `json:"storageClass,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default={ReadWriteOnce} - AccessModes []corev1.PersistentVolumeAccessMode `json:"accessModes,omitempty"` - // +kubebuilder:default="10Gi" - Size string `json:"size,omitempty"` - - // +kubebuilder:validation:Optional - Labels map[string]string `json:"labels,omitempty"` -} - -func (p *PersistenceSpec) Existing() bool { - return p.ExistingClaim != nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PersistenceSpec) DeepCopyInto(out *PersistenceSpec) { - *out = *in - if in.StorageClass != nil { - in, out := &in.StorageClass, &out.StorageClass - *out = new(string) - **out = **in - } - if in.AccessModes != nil { - in, out := &in.AccessModes, &out.AccessModes - *out = make([]corev1.PersistentVolumeAccessMode, len(*in)) - copy(*out, *in) - } - if in.ExistingClaim != nil { - in, out := &in.ExistingClaim, &out.ExistingClaim - *out = new(string) - **out = **in - } - if in.VolumeMode != nil { - in, out := &in.VolumeMode, &out.VolumeMode - *out = new(corev1.PersistentVolumeMode) - **out = **in - } - if in.Labels != nil { - in, out := &in.Labels, &out.Labels - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PersistenceSpec. -func (in *PersistenceSpec) DeepCopy() *PersistenceSpec { - if in == nil { - return nil - } - out := new(PersistenceSpec) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/service/service_spec.go b/pkg/service/service_spec.go deleted file mode 100644 index 6b8ec65..0000000 --- a/pkg/service/service_spec.go +++ /dev/null @@ -1,36 +0,0 @@ -package service - -import corev1 "k8s.io/api/core/v1" - -type ServiceSpec struct { - // +kubebuilder:validation:Optional - Annotations map[string]string `json:"annotations,omitempty"` - // +kubebuilder:validation:enum=ClusterIP;NodePort;LoadBalancer;ExternalName - // +kubebuilder:default=ClusterIP - Type corev1.ServiceType `json:"type,omitempty"` - // +kubebuilder:validation:Minimum=1 - // +kubebuilder:validation:Maximum=65535 - Port int32 `json:"port"` -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { - *out = *in - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceSpec. -func (in *ServiceSpec) DeepCopy() *ServiceSpec { - if in == nil { - return nil - } - out := new(ServiceSpec) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/util/reconcilier_util.go b/pkg/util/reconciler_util.go similarity index 100% rename from pkg/util/reconcilier_util.go rename to pkg/util/reconciler_util.go From 63acd163dcb8bf817877c37cdbf6e93b2f8e79ad Mon Sep 17 00:00:00 2001 From: whg517 Date: Thu, 11 Jan 2024 20:23:42 +0800 Subject: [PATCH 2/2] chron: update README and add gadge --- README.md | 26 +++++++++++--------------- READNE_zh-CN.md | 28 +++++++++++++--------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 2d7a461..e7a662a 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,16 @@ # Operator-go -## 1. Introduction to Operator-go +[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/zncdata-labs/operator-go) +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/zncdata-labs/operator-go) +![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/zncdata-labs/operator-go/ci.yml) +![GitHub License](https://img.shields.io/github/license/zncdata-labs/commons-operator) +![GitHub release (latest by date)](https://img.shields.io/github/v/release/zncdata-labs/operator-go) -Operator-go is the public class library of operator under zncdata, which is mainly used to handle operator-related logic. -## 2. Directory introduction +## Features -Since they are all public class libraries, the main codes are placed in the pkg directory. - -### pkg/spec directory - - This directory extracts the public parts of the operator developed by zncdata for easy application, and content will be added in the future. - Among them, commons-spec is special. Commons-spec is the spec part of commons-operator. - commons-operator will be referenced by many operators in the planning of zncdata, so it is extracted separately to facilitate the use of other projects. - -### pkg/status directory - - This directory defines the status of the operator. Currently, the status of the operator in zncdata is relatively unified. - It is currently separated and content will be added in the future. +- Database Connection CRD, which provides database connection and database configuration for applications, has implemented Mysql, Postgres, Redis +- S3 Connection CRD: Provides S3 connection and S3 bucket configuration for applications +- Authentication CRD provides flexible authentication for applications and has been configured with oidc +- Error and condition constants +- k8s object creation or update optimization diff --git a/READNE_zh-CN.md b/READNE_zh-CN.md index 7878239..d3b93b4 100644 --- a/READNE_zh-CN.md +++ b/READNE_zh-CN.md @@ -1,19 +1,17 @@ -# Operator-go +# operator-go -## 1. Operator-go简介 +Operator-go 是 zncdata-stack 中 operator 开发需要用公共类库,主要用于处理 operator 的相关逻辑。 -Operator-go 是 zncdata 下的 operator 的公共类库,主要用于处理 operator 的相关逻辑。 +[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/zncdata-labs/operator-go) +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/zncdata-labs/operator-go) +![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/zncdata-labs/operator-go/ci.yml) +![GitHub License](https://img.shields.io/github/license/zncdata-labs/commons-operator) +![GitHub release (latest by date)](https://img.shields.io/github/v/release/zncdata-labs/operator-go) -## 2. 目录介绍 +## 特性 -由于都是公共类库,所以主要代码都放在了pkg目录下。 - -### pkg/spec 目录 - - 该目录把zncdata 开发的 operator 的公共部分提取出来,方便应用,后续会陆续增加内容 - 其中 commons-spec比较特殊,Commons-spec 是commons-operator 的 spec 部分,commons-operator 在 zncdata 的规划中会被许多 - operator 引用,所以把它单独提取出来,方便其他项目使用。 - -### pkg/status 目录 - - 该目录是对 operator 的状态进行定义,目前 zncdata 的 operator 的 status 比较统一,目前抽离了出来,后续会陆续增加内容 +- 数据库连接 CRD ,为应用提供数据库连接和数据库配置,目前已经实现 Mysql , Postgres , Redis +- S3连接 CRD ,为应用提供 S3 连接和 S3 桶配置 +- 认证 CRD,为应用提供灵活的认证方式,已经实现 oidc 配置 +- 错误和条件常量 +- k8s 对象创建或更新的优化