This is an automated email from the ASF dual-hosted git repository. duanzhengqiang pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git
commit 2b2675a4221c50dd7b069ff80b7b2ebe854794ce Author: Ghoul_Lee <[email protected]> AuthorDate: Thu Jul 21 11:00:48 2022 +0800 refactor(crd): rename crd (#23) * refactor(crd): rename crd proxy --> shardingsphereproxy ;proxyconfig --> shardingsphereserverconfig Signed-off-by: windghoul <[email protected]> * fix(crd): add license Signed-off-by: windghoul <[email protected]> * fix(helm): set default values Signed-off-by: windghoul <[email protected]> * fix(helm): remove env to download go package Signed-off-by: windghoul <[email protected]> * fix(kubebuilder): add project info Signed-off-by: windghoul <[email protected]> * fix(annotation): fix annotation ShardingSphere-ShardingSphereProxy to ShardingSphere-Proxy Signed-off-by: windghoul <[email protected]> --- ...ardingsphere_v1alpha1_shardingsphereproxy.yaml} | 2 +- ..._v1alpha1_shardingsphereproxyserverconfig.yaml} | 2 +- ...phere.sphere-ex.com_shardingsphereproxies.yaml} | 32 ++++++++------- ...e-ex.com_shardingsphereproxyserverconfigs.yaml} | 29 +++++++------- charts/shardingsphere-operator/templates/rbac.yaml | 12 +++--- .../webhook/admission-webhook-configuration.yaml | 8 ++-- charts/shardingsphere-operator/values.yaml | 2 +- doc/deploy.md | 2 +- doc/images/ss-operatorIA.png | Bin 810035 -> 735662 bytes shardingsphere-operator/PROJECT | 4 +- .../api/v1alpha1/proxy_status.go | 16 ++++---- .../api/v1alpha1/proxy_types.go | 16 ++++---- .../api/v1alpha1/proxy_webhook.go | 33 ++++++++-------- .../api/v1alpha1/proxyconfig_types.go | 18 ++++----- .../api/v1alpha1/serverconfig.go | 4 +- .../api/v1alpha1/webhook_suite_test.go | 2 +- .../api/v1alpha1/zz_generated.deepcopy.go | 44 ++++++++++----------- shardingsphere-operator/main.go | 8 ++-- .../pkg/controllers/proxy_controller.go | 6 +-- .../pkg/controllers/proxyconfig_controller.go | 8 ++-- shardingsphere-operator/pkg/reconcile/resource.go | 20 +++++----- 21 files changed, 135 insertions(+), 133 deletions(-) diff --git a/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxy.yaml b/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_shardingsphereproxy.yaml similarity index 98% rename from charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxy.yaml rename to charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_shardingsphereproxy.yaml index 98fc647..72ec20b 100644 --- a/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxy.yaml +++ b/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_shardingsphereproxy.yaml @@ -15,7 +15,7 @@ ## apiVersion: shardingsphere.sphere-ex.com/v1alpha1 -kind: Proxy +kind: ShardingSphereProxy metadata: name: {{ template "common.names.fullname" . }} spec: diff --git a/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxyconfig.yaml b/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_shardingsphereproxyserverconfig.yaml similarity index 91% rename from charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxyconfig.yaml rename to charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_shardingsphereproxyserverconfig.yaml index 3cbc9be..8e24440 100644 --- a/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_proxyconfig.yaml +++ b/charts/shardingsphere-cluster/templates/shardingsphere_v1alpha1_shardingsphereproxyserverconfig.yaml @@ -15,7 +15,7 @@ ## apiVersion: shardingsphere.sphere-ex.com/v1alpha1 -kind: ProxyConfig +kind: ShardingSphereProxyServerConfig metadata: name: {{ printf "%s-configuration" (include "common.names.fullname" .) }} spec: diff --git a/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml b/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_shardingsphereproxies.yaml similarity index 97% rename from charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml rename to charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_shardingsphereproxies.yaml index f0a3903..29f9f75 100644 --- a/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml +++ b/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_shardingsphereproxies.yaml @@ -21,14 +21,14 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.8.0 creationTimestamp: null - name: proxies.shardingsphere.sphere-ex.com + name: shardingsphereproxies.shardingsphere.sphere-ex.com spec: group: shardingsphere.sphere-ex.com names: - kind: Proxy - listKind: ProxyList - plural: proxies - singular: proxy + kind: ShardingSphereProxy + listKind: ShardingSphereProxyList + plural: shardingsphereproxies + singular: shardingsphereproxy scope: Namespaced versions: - additionalPrinterColumns: @@ -41,7 +41,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: Proxy is the Schema for the proxies API + description: ShardingSphereProxy is the Schema for the proxies API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -56,7 +56,7 @@ spec: metadata: type: object spec: - description: ProxySpec defines the desired state of Proxy + description: ProxySpec defines the desired state of ShardingSphereProxy properties: automaticScaling: description: AutomaticScaling HPA configuration @@ -248,7 +248,8 @@ spec: minimum: 0 type: integer proxyConfigName: - description: ProxyConfigName is the name of the ProxyConfig CRD + description: ProxyConfigName is the name of the ShardingSphereProxyServerConfig + CRD minLength: 0 pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string @@ -605,7 +606,7 @@ spec: - version type: object status: - description: ProxyStatus defines the observed state of Proxy + description: ProxyStatus defines the observed state of ShardingSphereProxy properties: conditions: description: Conditions The conditions array, the reason and message @@ -618,8 +619,8 @@ spec: true | pod started successfully but not ready| | Started | false | pod started failed| | Ready | true | The pod is ready and can provide external services| | Unknown | - true | ShardingSphere-Proxy failed to start correctly due - to some problems | + true | ShardingSphere-Proxy failed to start + correctly due to some problems | properties: lastUpdateTime: format: date-time @@ -634,10 +635,11 @@ spec: type: object type: array phase: - description: 'ShardingSphere-Proxy phase are a brief summary of the - ShardingSphere-Proxy life cycle There are two possible phase values: - Ready: ShardingSphere-Proxy can already provide external services - NotReady: ShardingSphere-Proxy cannot provide external services' + description: 'ShardingSphere-Proxy phase are a brief + summary of the ShardingSphere-Proxy life cycle There + are two possible phase values: Ready: ShardingSphere-Proxy + can already provide external services NotReady: ShardingSphere-Proxy + cannot provide external services' type: string readyNodes: description: ReadyNodes shows the number of replicas that ShardingSphere-Proxy diff --git a/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml b/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_shardingsphereproxyserverconfigs.yaml similarity index 90% rename from charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml rename to charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_shardingsphereproxyserverconfigs.yaml index 6e3cd8e..ba0a8ad 100644 --- a/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml +++ b/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_shardingsphereproxyserverconfigs.yaml @@ -21,14 +21,14 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.8.0 creationTimestamp: null - name: proxyconfigs.shardingsphere.sphere-ex.com + name: shardingsphereproxyserverconfigs.shardingsphere.sphere-ex.com spec: group: shardingsphere.sphere-ex.com names: - kind: ProxyConfig - listKind: ProxyConfigList - plural: proxyconfigs - singular: proxyconfig + kind: ShardingSphereProxyServerConfig + listKind: ShardingSphereProxyServerConfigList + plural: shardingsphereproxyserverconfigs + singular: shardingsphereproxyserverconfig scope: Namespaced versions: - additionalPrinterColumns: @@ -38,7 +38,8 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: ProxyConfig is the Schema for the proxyconfigs API + description: ShardingSphereProxyServerConfig is the Schema for the proxyconfigs + API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -53,7 +54,7 @@ spec: metadata: type: object spec: - description: ProxyConfigSpec defines the desired state of ProxyConfig + description: ProxyConfigSpec defines the desired state of ShardingSphereProxyServerConfig properties: authority: description: Auth is used to set up initial user to login compute @@ -181,16 +182,16 @@ spec: slow SQL.' type: string proxy-backend-query-fetch-size: - description: Proxy backend query fetch size. A larger value may - increase the memory usage of ShardingSphere Proxy. The default - value is -1, which means set the minimum value for different - JDBC drivers. + description: ShardingSphereProxy backend query fetch size. A larger + value may increase the memory usage of ShardingSphere ShardingSphereProxy. + The default value is -1, which means set the minimum value for + different JDBC drivers. type: integer proxy-frontend-database-protocol-type: type: string proxy-frontend-executor-size: - description: Proxy frontend Netty executor size. The default value - is 0, which means let Netty decide. + description: ShardingSphereProxy frontend Netty executor size. + The default value is 0, which means let Netty decide. type: integer type: object required: @@ -198,7 +199,7 @@ spec: - mode type: object status: - description: ProxyConfigStatus defines the observed state of ProxyConfig + description: ProxyConfigStatus defines the observed state of ShardingSphereProxyServerConfig properties: metadataRepository: type: string diff --git a/charts/shardingsphere-operator/templates/rbac.yaml b/charts/shardingsphere-operator/templates/rbac.yaml index bfa3c07..cf85674 100644 --- a/charts/shardingsphere-operator/templates/rbac.yaml +++ b/charts/shardingsphere-operator/templates/rbac.yaml @@ -117,7 +117,7 @@ rules: - apiGroups: - shardingsphere.sphere-ex.com resources: - - proxies + - shardingsphereproxies verbs: - create - delete @@ -129,13 +129,13 @@ rules: - apiGroups: - shardingsphere.sphere-ex.com resources: - - proxies/finalizers + - shardingsphereproxies/finalizers verbs: - update - apiGroups: - shardingsphere.sphere-ex.com resources: - - proxies/status + - shardingsphereproxies/status verbs: - get - patch @@ -143,7 +143,7 @@ rules: - apiGroups: - shardingsphere.sphere-ex.com resources: - - proxyconfigs + - shardingsphereproxyserverconfigs verbs: - create - delete @@ -155,13 +155,13 @@ rules: - apiGroups: - shardingsphere.sphere-ex.com resources: - - proxyconfigs/finalizers + - shardingsphereproxyserverconfigs/finalizers verbs: - update - apiGroups: - shardingsphere.sphere-ex.com resources: - - proxyconfigs/status + - shardingsphereproxyserverconfigs/status verbs: - get - patch diff --git a/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml b/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml index 0988128..fa97cb3 100644 --- a/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml +++ b/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml @@ -26,7 +26,7 @@ webhooks: service: name: kubernetes namespace: default - path: /apis/admission.shardingsphere.sphere-ex.com/v1alpha1/mutate-shardingsphere-sphere-ex-com-v1alpha1-proxy + path: /apis/admission.shardingsphere.sphere-ex.com/v1alpha1/mutate-shardingsphere-sphere-ex-com-v1alpha1-shardingsphereproxy failurePolicy: Fail name: mproxy.shardingsphere.sphere-ex.com rules: @@ -38,7 +38,7 @@ webhooks: - CREATE - UPDATE resources: - - proxies + - shardingsphereproxies sideEffects: None --- apiVersion: admissionregistration.k8s.io/v1 @@ -52,7 +52,7 @@ webhooks: service: name: kubernetes namespace: default - path: /apis/admission.shardingsphere.sphere-ex.com/v1alpha1/validate-shardingsphere-sphere-ex-com-v1alpha1-proxy + path: /apis/admission.shardingsphere.sphere-ex.com/v1alpha1/validate-shardingsphere-sphere-ex-com-v1alpha1-shardingsphereproxy failurePolicy: Fail name: vproxy.shardingsphere.sphere-ex.com rules: @@ -64,5 +64,5 @@ webhooks: - CREATE - UPDATE resources: - - proxies + - shardingsphereproxies sideEffects: None diff --git a/charts/shardingsphere-operator/values.yaml b/charts/shardingsphere-operator/values.yaml index ae6f1cb..83c7b43 100644 --- a/charts/shardingsphere-operator/values.yaml +++ b/charts/shardingsphere-operator/values.yaml @@ -27,7 +27,7 @@ image: pullPolicy: IfNotPresent ## @param image.tag image tag ## - tag: "0.1.0" + tag: "v0.1.0" ## @param imagePullSecrets image pull secret of private repository ## e.g: ## imagePullSecrets: diff --git a/doc/deploy.md b/doc/deploy.md index 16909ac..b50199b 100644 --- a/doc/deploy.md +++ b/doc/deploy.md @@ -262,5 +262,5 @@ zookeeper: ```shell helm uninstall shardingsphere-cluster -n shardingsphere helm uninstall shardingsphere-operator -n shardingsphere-operator -kubectl delete crd proxies.shardingsphere.sphere-ex.com proxyconfigs.shardingsphere.sphere-ex.com +kubectl delete crd shardingsphereproxies.shardingsphere.sphere-ex.com shardingsphereproxyserverconfigs.shardingsphere.sphere-ex.com ``` diff --git a/doc/images/ss-operatorIA.png b/doc/images/ss-operatorIA.png index 4484ca4..1ff5317 100644 Binary files a/doc/images/ss-operatorIA.png and b/doc/images/ss-operatorIA.png differ diff --git a/shardingsphere-operator/PROJECT b/shardingsphere-operator/PROJECT index d43dd68..24e7805 100644 --- a/shardingsphere-operator/PROJECT +++ b/shardingsphere-operator/PROJECT @@ -10,7 +10,7 @@ resources: controller: true domain: sphere-ex.com group: shardingsphere - kind: Proxy + kind: ShardingSphereProxy path: sphere-ex.com/shardingsphere-operator/api/v1alpha1 version: v1alpha1 webhooks: @@ -23,7 +23,7 @@ resources: controller: true domain: sphere-ex.com group: shardingsphere - kind: ProxyConfig + kind: ShardingSphereProxyServerConfig path: sphere-ex.com/shardingsphere-operator/api/v1alpha1 version: v1alpha1 version: "3" diff --git a/shardingsphere-operator/api/v1alpha1/proxy_status.go b/shardingsphere-operator/api/v1alpha1/proxy_status.go index 8f3ae69..fcbf696 100644 --- a/shardingsphere-operator/api/v1alpha1/proxy_status.go +++ b/shardingsphere-operator/api/v1alpha1/proxy_status.go @@ -39,7 +39,7 @@ const ( ConditionUnknown ConditionType = "Unknown" ) -// ProxyStatus defines the observed state of Proxy +// ProxyStatus defines the observed state of ShardingSphereProxy type ProxyStatus struct { //ShardingSphere-Proxy phase are a brief summary of the ShardingSphere-Proxy life cycle //There are two possible phase values: @@ -70,7 +70,7 @@ type Condition struct { LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"` } -func (p *Proxy) SetInitialized() { +func (p *ShardingSphereProxy) SetInitialized() { p.Status.Phase = StatusNotReady p.Status.Conditions = append([]Condition{}, Condition{ Type: ConditionInitialized, @@ -79,7 +79,7 @@ func (p *Proxy) SetInitialized() { }) } -func (p *Proxy) SetInitializationFailed() { +func (p *ShardingSphereProxy) SetInitializationFailed() { p.Status.Phase = StatusNotReady p.Status.Conditions = append([]Condition{}, Condition{ Type: ConditionInitialized, @@ -88,7 +88,7 @@ func (p *Proxy) SetInitializationFailed() { }) } -func (p *Proxy) SetPodStarted(readyNodes int32) { +func (p *ShardingSphereProxy) SetPodStarted(readyNodes int32) { p.Status.Phase = StatusNotReady p.Status.Conditions = append([]Condition{}, Condition{ Type: ConditionStarted, @@ -98,7 +98,7 @@ func (p *Proxy) SetPodStarted(readyNodes int32) { p.Status.ReadyNodes = readyNodes } -func (p *Proxy) SetPodNotStarted(readyNodes int32) { +func (p *ShardingSphereProxy) SetPodNotStarted(readyNodes int32) { p.Status.Phase = StatusNotReady p.Status.Conditions = append([]Condition{}, Condition{ Type: ConditionStarted, @@ -108,7 +108,7 @@ func (p *Proxy) SetPodNotStarted(readyNodes int32) { p.Status.ReadyNodes = readyNodes } -func (p *Proxy) SetReady(readyNodes int32) { +func (p *ShardingSphereProxy) SetReady(readyNodes int32) { p.Status.Phase = StatusReady p.Status.Conditions = append([]Condition{}, Condition{ Type: ConditionReady, @@ -119,7 +119,7 @@ func (p *Proxy) SetReady(readyNodes int32) { } -func (p *Proxy) SetFailed() { +func (p *ShardingSphereProxy) SetFailed() { p.Status.Phase = StatusNotReady p.Status.Conditions = append([]Condition{}, Condition{ Type: ConditionUnknown, @@ -127,6 +127,6 @@ func (p *Proxy) SetFailed() { LastUpdateTime: metav1.Now(), }) } -func (p *Proxy) UpdateReadyNodes(readyNodes int32) { +func (p *ShardingSphereProxy) UpdateReadyNodes(readyNodes int32) { p.Status.ReadyNodes = readyNodes } diff --git a/shardingsphere-operator/api/v1alpha1/proxy_types.go b/shardingsphere-operator/api/v1alpha1/proxy_types.go index 8e1ba42..28928db 100644 --- a/shardingsphere-operator/api/v1alpha1/proxy_types.go +++ b/shardingsphere-operator/api/v1alpha1/proxy_types.go @@ -68,7 +68,7 @@ type AutomaticScaling struct { MinInstance int32 `json:"minInstance,omitempty"` } -// ProxySpec defines the desired state of Proxy +// ProxySpec defines the desired state of ShardingSphereProxy type ProxySpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file @@ -85,7 +85,7 @@ type ProxySpec struct { // +kubebuilder:validation:MinLength=0 // +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` - //ProxyConfigName is the name of the ProxyConfig CRD + //ProxyConfigName is the name of the ShardingSphereProxyServerConfig CRD ProxyConfigName string `json:"proxyConfigName"` // +kubebuilder:validation:Minimum=0 @@ -111,8 +111,8 @@ type ProxySpec struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status -// Proxy is the Schema for the proxies API -type Proxy struct { +// ShardingSphereProxy is the Schema for the proxies API +type ShardingSphereProxy struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -122,13 +122,13 @@ type Proxy struct { //+kubebuilder:object:root=true -// ProxyList contains a list of Proxy -type ProxyList struct { +// ShardingSphereProxyList contains a list of ShardingSphereProxy +type ShardingSphereProxyList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []Proxy `json:"items"` + Items []ShardingSphereProxy `json:"items"` } func init() { - SchemeBuilder.Register(&Proxy{}, &ProxyList{}) + SchemeBuilder.Register(&ShardingSphereProxy{}, &ShardingSphereProxyList{}) } diff --git a/shardingsphere-operator/api/v1alpha1/proxy_webhook.go b/shardingsphere-operator/api/v1alpha1/proxy_webhook.go index b216a20..aa441d9 100644 --- a/shardingsphere-operator/api/v1alpha1/proxy_webhook.go +++ b/shardingsphere-operator/api/v1alpha1/proxy_webhook.go @@ -32,22 +32,21 @@ import ( shardingwebhook "sphere-ex.com/shardingsphere-operator/pkg/webhook" ) -// log is for logging in this package. -var proxylog = logf.Log.WithName("proxy-resource") +var shardingsphereproxylog = logf.Log.WithName("shardingsphereproxy-resource") -func (r *Proxy) SetupWebhookWithManager(mgr ctrl.Manager) error { +func (r *ShardingSphereProxy) SetupWebhookWithManager(mgr ctrl.Manager) error { return shardingwebhook.NewWebhookManagedBy(mgr). For(r). Complete() } -//+kubebuilder:webhook:path=/apis/admission.shardingsphere.sphere-ex.com/v1alpha1/mutate-shardingsphere-sphere-ex-com-v1alpha1-proxy,mutating=true,failurePolicy=fail,sideEffects=None,groups=shardingsphere.sphere-ex.com,resources=proxies,verbs=create;update,versions=v1alpha1,name=mproxy.kb.io,admissionReviewVersions=v1 +//+kubebuilder:webhook:path=/apis/admission.shardingsphere.sphere-ex.com/v1alpha1/mutate-shardingsphere-sphere-ex-com-v1alpha1-proxy,mutating=true,failurePolicy=fail,sideEffects=None,groups=shardingsphere.sphere-ex.com,resources=shardingsphereproxies,verbs=create;update,versions=v1alpha1,name=mproxy.kb.io,admissionReviewVersions=v1 -var _ webhook.Defaulter = &Proxy{} +var _ webhook.Defaulter = &ShardingSphereProxy{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *Proxy) Default() { - proxylog.Info("default", "name", r.Name) +func (r *ShardingSphereProxy) Default() { + shardingsphereproxylog.Info("default", "name", r.Name) if r.Spec.StartupProbe == nil { r.Spec.StartupProbe = &v1.Probe{ ProbeHandler: v1.ProbeHandler{ @@ -102,11 +101,11 @@ func (r *Proxy) Default() { // +kubebuilder:webhook:path=/apis/admission.shardingsphere.sphere-ex.com/v1alpha1/validate-shardingsphere-sphere-ex-com-v1alpha1-proxy,mutating=false,failurePolicy=fail,sideEffects=None,groups=shardingsphere.sphere-ex.com,resources=proxies,verbs=create;update,versions=v1alpha1,name=vproxy.kb.io,admissionReviewVersions=v1 -var _ webhook.Validator = &Proxy{} +var _ webhook.Validator = &ShardingSphereProxy{} // ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *Proxy) ValidateCreate() error { - proxylog.Info("validate create", "name", r.Name) +func (r *ShardingSphereProxy) ValidateCreate() error { + shardingsphereproxylog.Info("validate create", "name", r.Name) err := r.validateService() if err != nil { return err @@ -119,8 +118,8 @@ func (r *Proxy) ValidateCreate() error { } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *Proxy) ValidateUpdate(old runtime.Object) error { - proxylog.Info("validate update", "name", r.Name) +func (r *ShardingSphereProxy) ValidateUpdate(old runtime.Object) error { + shardingsphereproxylog.Info("validate update", "name", r.Name) err := r.validateService() if err != nil { return err @@ -133,29 +132,29 @@ func (r *Proxy) ValidateUpdate(old runtime.Object) error { } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *Proxy) ValidateDelete() error { +func (r *ShardingSphereProxy) ValidateDelete() error { return nil } -func (r *Proxy) validateService() error { +func (r *ShardingSphereProxy) validateService() error { var allErrs field.ErrorList field.NewPath("spec").Child("serviceType") if r.Spec.ServiceType.NodePort != 0 && r.Spec.ServiceType.Type != v1.ServiceTypeNodePort { allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("serviceType"), r.Spec.ServiceType, errors.New("nodePort: Forbidden: may not be used when `type` is 'ClusterIP'").Error())) return apierrors.NewInvalid(schema.GroupKind{ Group: "shardingsphere.sphere-ex.com", - Kind: "Proxy", + Kind: "ShardingSphereProxy", }, r.Name, allErrs) } return nil } -func (r *Proxy) validateInstance() error { +func (r *ShardingSphereProxy) validateInstance() error { var allErrs field.ErrorList if r.Spec.AutomaticScaling != nil && r.Spec.AutomaticScaling.MaxInstance < 1 { allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("MaxInstance"), r.Spec.ServiceType, errors.New("If automatic scaling is enabled, the number of instances must be filled in.").Error())) return apierrors.NewInvalid(schema.GroupKind{ Group: "shardingsphere.sphere-ex.com", - Kind: "Proxy", + Kind: "ShardingSphereProxy", }, r.Name, allErrs) } return nil diff --git a/shardingsphere-operator/api/v1alpha1/proxyconfig_types.go b/shardingsphere-operator/api/v1alpha1/proxyconfig_types.go index a184ba0..3179f86 100644 --- a/shardingsphere-operator/api/v1alpha1/proxyconfig_types.go +++ b/shardingsphere-operator/api/v1alpha1/proxyconfig_types.go @@ -21,7 +21,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// ProxyConfigSpec defines the desired state of ProxyConfig +// ProxyConfigSpec defines the desired state of ShardingSphereProxyServerConfig type ProxyConfigSpec struct { ClusterConfig ClusterConfig `json:"mode" yaml:"mode"` Authority Auth `json:"authority" yaml:"authority"` @@ -29,7 +29,7 @@ type ProxyConfigSpec struct { Props *Props `json:"props,omitempty" yaml:"props,omitempty"` } -// ProxyConfigStatus defines the observed state of ProxyConfig +// ProxyConfigStatus defines the observed state of ShardingSphereProxyServerConfig type ProxyConfigStatus struct { MetadataRepository string `json:"metadataRepository"` } @@ -38,8 +38,8 @@ type ProxyConfigStatus struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status -// ProxyConfig is the Schema for the proxyconfigs API -type ProxyConfig struct { +// ShardingSphereProxyServerConfig is the Schema for the proxyconfigs API +type ShardingSphereProxyServerConfig struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -49,17 +49,17 @@ type ProxyConfig struct { //+kubebuilder:object:root=true -// ProxyConfigList contains a list of ProxyConfig -type ProxyConfigList struct { +// ShardingSphereProxyServerConfigList contains a list of ShardingSphereProxyServerConfig +type ShardingSphereProxyServerConfigList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []ProxyConfig `json:"items"` + Items []ShardingSphereProxyServerConfig `json:"items"` } func init() { - SchemeBuilder.Register(&ProxyConfig{}, &ProxyConfigList{}) + SchemeBuilder.Register(&ShardingSphereProxyServerConfig{}, &ShardingSphereProxyServerConfigList{}) } -func (in *ProxyConfig) SetMetadataRepository(metadataType string) { +func (in *ShardingSphereProxyServerConfig) SetMetadataRepository(metadataType string) { in.Status.MetadataRepository = metadataType } diff --git a/shardingsphere-operator/api/v1alpha1/serverconfig.go b/shardingsphere-operator/api/v1alpha1/serverconfig.go index 4267c0c..57c257f 100644 --- a/shardingsphere-operator/api/v1alpha1/serverconfig.go +++ b/shardingsphere-operator/api/v1alpha1/serverconfig.go @@ -46,13 +46,13 @@ type Props struct { // Whether validate table meta data consistency when application startup or updated. // +optional CheckTableMetadataEnabled bool `json:"check-table-metadata-enabled,omitempty" yaml:"check-table-metadata-enabled,omitempty"` - // Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy. The default value is -1, which means set the minimum value for different JDBC drivers. + // ShardingSphereProxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere ShardingSphereProxy. The default value is -1, which means set the minimum value for different JDBC drivers. // +optional ProxyBackendQueryFetchSize int `json:"proxy-backend-query-fetch-size,omitempty" yaml:"proxy-backend-query-fetch-size,omitempty"` // Whether validate duplicate table when application startup or updated. // +optional CheckDuplicateTableEnabled bool `json:"check-duplicate-table-enabled,omitempty" yaml:"check-duplicate-table-enabled,omitempty"` - // Proxy frontend Netty executor size. The default value is 0, which means let Netty decide. + // ShardingSphereProxy frontend Netty executor size. The default value is 0, which means let Netty decide. // +optional ProxyFrontendExecutorSize int `json:"proxy-frontend-executor-size,omitempty" yaml:"proxy-frontend-executor-size,omitempty"` // Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution and block other clients if client connections are more than proxy-frontend-executor-size, especially executing slow SQL. diff --git a/shardingsphere-operator/api/v1alpha1/webhook_suite_test.go b/shardingsphere-operator/api/v1alpha1/webhook_suite_test.go index 6a1f9ff..9707169 100644 --- a/shardingsphere-operator/api/v1alpha1/webhook_suite_test.go +++ b/shardingsphere-operator/api/v1alpha1/webhook_suite_test.go @@ -101,7 +101,7 @@ var _ = BeforeSuite(func() { }) Expect(err).NotTo(HaveOccurred()) - err = (&Proxy{}).SetupWebhookWithManager(mgr) + err = (&ShardingSphereProxy{}).SetupWebhookWithManager(mgr) Expect(err).NotTo(HaveOccurred()) //+kubebuilder:scaffold:webhook diff --git a/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go b/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go index bb799a0..39b98ae 100644 --- a/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go +++ b/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go @@ -162,7 +162,7 @@ func (in *Props) DeepCopy() *Props { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Proxy) DeepCopyInto(out *Proxy) { +func (in *ShardingSphereProxy) DeepCopyInto(out *ShardingSphereProxy) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -170,18 +170,18 @@ func (in *Proxy) DeepCopyInto(out *Proxy) { in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Proxy. -func (in *Proxy) DeepCopy() *Proxy { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShardingSphereProxy. +func (in *ShardingSphereProxy) DeepCopy() *ShardingSphereProxy { if in == nil { return nil } - out := new(Proxy) + out := new(ShardingSphereProxy) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Proxy) DeepCopyObject() runtime.Object { +func (in *ShardingSphereProxy) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -189,7 +189,7 @@ func (in *Proxy) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ProxyConfig) DeepCopyInto(out *ProxyConfig) { +func (in *ShardingSphereProxyServerConfig) DeepCopyInto(out *ShardingSphereProxyServerConfig) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -197,18 +197,18 @@ func (in *ProxyConfig) DeepCopyInto(out *ProxyConfig) { out.Status = in.Status } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProxyConfig. -func (in *ProxyConfig) DeepCopy() *ProxyConfig { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShardingSphereProxyServerConfig. +func (in *ShardingSphereProxyServerConfig) DeepCopy() *ShardingSphereProxyServerConfig { if in == nil { return nil } - out := new(ProxyConfig) + out := new(ShardingSphereProxyServerConfig) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ProxyConfig) DeepCopyObject() runtime.Object { +func (in *ShardingSphereProxyServerConfig) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -216,31 +216,31 @@ func (in *ProxyConfig) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ProxyConfigList) DeepCopyInto(out *ProxyConfigList) { +func (in *ShardingSphereProxyServerConfigList) DeepCopyInto(out *ShardingSphereProxyServerConfigList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]ProxyConfig, len(*in)) + *out = make([]ShardingSphereProxyServerConfig, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProxyConfigList. -func (in *ProxyConfigList) DeepCopy() *ProxyConfigList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShardingSphereProxyServerConfigList. +func (in *ShardingSphereProxyServerConfigList) DeepCopy() *ShardingSphereProxyServerConfigList { if in == nil { return nil } - out := new(ProxyConfigList) + out := new(ShardingSphereProxyServerConfigList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ProxyConfigList) DeepCopyObject() runtime.Object { +func (in *ShardingSphereProxyServerConfigList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -281,31 +281,31 @@ func (in *ProxyConfigStatus) DeepCopy() *ProxyConfigStatus { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ProxyList) DeepCopyInto(out *ProxyList) { +func (in *ShardingSphereProxyList) DeepCopyInto(out *ShardingSphereProxyList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]Proxy, len(*in)) + *out = make([]ShardingSphereProxy, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProxyList. -func (in *ProxyList) DeepCopy() *ProxyList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShardingSphereProxyList. +func (in *ShardingSphereProxyList) DeepCopy() *ShardingSphereProxyList { if in == nil { return nil } - out := new(ProxyList) + out := new(ShardingSphereProxyList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ProxyList) DeepCopyObject() runtime.Object { +func (in *ShardingSphereProxyList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } diff --git a/shardingsphere-operator/main.go b/shardingsphere-operator/main.go index e522fd4..da35ba2 100644 --- a/shardingsphere-operator/main.go +++ b/shardingsphere-operator/main.go @@ -88,18 +88,18 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "Proxy") + setupLog.Error(err, "unable to create controller", "controller", "ShardingSphereProxy") os.Exit(1) } if err = (&controllers.ProxyConfigReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "ProxyConfig") + setupLog.Error(err, "unable to create controller", "controller", "ShardingSphereProxyServerConfig") os.Exit(1) } - if err = (&v1alpha1.Proxy{}).SetupWebhookWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create webhook", "webhook", "Proxy") + if err = (&v1alpha1.ShardingSphereProxy{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "ShardingSphereProxy") os.Exit(1) } //+kubebuilder:scaffold:builder diff --git a/shardingsphere-operator/pkg/controllers/proxy_controller.go b/shardingsphere-operator/pkg/controllers/proxy_controller.go index 5e69311..77b61a2 100644 --- a/shardingsphere-operator/pkg/controllers/proxy_controller.go +++ b/shardingsphere-operator/pkg/controllers/proxy_controller.go @@ -39,7 +39,7 @@ const ( miniReadyCount = 1 ) -// ProxyReconciler reconciles a Proxy object +// ProxyReconciler reconciles a ShardingSphereProxy object type ProxyReconciler struct { client.Client Scheme *runtime.Scheme @@ -60,7 +60,7 @@ type ProxyReconciler struct { func (r *ProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { log := logger.FromContext(ctx) - run := &v1alpha1.Proxy{} + run := &v1alpha1.ShardingSphereProxy{} err := r.Get(ctx, req.NamespacedName, run) if apierrors.IsNotFound(err) { log.Info("Resource in work queue no longer exists!") @@ -195,7 +195,7 @@ func (r *ProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl // SetupWithManager sets up the controller with the Manager. func (r *ProxyReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&v1alpha1.Proxy{}). + For(&v1alpha1.ShardingSphereProxy{}). Owns(&appsv1.Deployment{}). Owns(&v1.Service{}). Owns(&v1.Pod{}). diff --git a/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go b/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go index 8910fb9..1d3fcd3 100644 --- a/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go +++ b/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go @@ -31,7 +31,7 @@ import ( logger "sigs.k8s.io/controller-runtime/pkg/log" ) -// ProxyConfigReconciler reconciles a ProxyConfig object +// ProxyConfigReconciler reconciles a ShardingSphereProxyServerConfig object type ProxyConfigReconciler struct { client.Client Scheme *runtime.Scheme @@ -45,7 +45,7 @@ type ProxyConfigReconciler struct { // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. // TODO(user): Modify the Reconcile function to compare the state specified by -// the ProxyConfig object against the actual cluster state, and then +// the ShardingSphereProxyServerConfig object against the actual cluster state, and then // perform operations to make the cluster state reflect the state specified by // the user. // @@ -54,7 +54,7 @@ type ProxyConfigReconciler struct { func (r *ProxyConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { log := logger.FromContext(ctx) - run := &shardingspherev1alpha1.ProxyConfig{} + run := &shardingspherev1alpha1.ShardingSphereProxyServerConfig{} err := r.Get(ctx, req.NamespacedName, run) if apierrors.IsNotFound(err) { log.Info("Resource in work queue no longer exists!") @@ -110,7 +110,7 @@ func (r *ProxyConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) // SetupWithManager sets up the controller with the Manager. func (r *ProxyConfigReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&shardingspherev1alpha1.ProxyConfig{}). + For(&shardingspherev1alpha1.ShardingSphereProxyServerConfig{}). Owns(&v1.ConfigMap{}). Complete(r) } diff --git a/shardingsphere-operator/pkg/reconcile/resource.go b/shardingsphere-operator/pkg/reconcile/resource.go index 6829e94..2d0d735 100644 --- a/shardingsphere-operator/pkg/reconcile/resource.go +++ b/shardingsphere-operator/pkg/reconcile/resource.go @@ -66,7 +66,7 @@ var logback = `<?xml version="1.0"?> </configuration> ` -func ConstructCascadingDeployment(proxy *v1alpha1.Proxy) *appsv1.Deployment { +func ConstructCascadingDeployment(proxy *v1alpha1.ShardingSphereProxy) *appsv1.Deployment { dp := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: proxy.Name, @@ -144,7 +144,7 @@ func ConstructCascadingDeployment(proxy *v1alpha1.Proxy) *appsv1.Deployment { return processOptionalParameter(proxy, dp) } -func ConstructCascadingService(proxy *v1alpha1.Proxy) *v1.Service { +func ConstructCascadingService(proxy *v1alpha1.ShardingSphereProxy) *v1.Service { svc := v1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -214,7 +214,7 @@ else echo failed;exit 1;fi;mv /mysql-connector-java-{{ .Version }}.jar /opt/shar } -func processOptionalParameter(proxy *v1alpha1.Proxy, dp *appsv1.Deployment) *appsv1.Deployment { +func processOptionalParameter(proxy *v1alpha1.ShardingSphereProxy, dp *appsv1.Deployment) *appsv1.Deployment { if proxy.Spec.MySQLDriver != nil { addInitContainer(dp, proxy.Spec.MySQLDriver) } @@ -222,7 +222,7 @@ func processOptionalParameter(proxy *v1alpha1.Proxy, dp *appsv1.Deployment) *app } // ConstructCascadingConfigmap Construct spec resources to Configmap -func ConstructCascadingConfigmap(proxyConfig *v1alpha1.ProxyConfig) *v1.ConfigMap { +func ConstructCascadingConfigmap(proxyConfig *v1alpha1.ShardingSphereProxyServerConfig) *v1.ConfigMap { y := toYaml(proxyConfig) return &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -241,7 +241,7 @@ func ConstructCascadingConfigmap(proxyConfig *v1alpha1.ProxyConfig) *v1.ConfigMa } // ConstructHPA Create HPA if you need -func ConstructHPA(proxy *v1alpha1.Proxy) *autoscalingv2beta2.HorizontalPodAutoscaler { +func ConstructHPA(proxy *v1alpha1.ShardingSphereProxy) *autoscalingv2beta2.HorizontalPodAutoscaler { return &autoscalingv2beta2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: proxy.Name, @@ -290,14 +290,14 @@ func ConstructHPA(proxy *v1alpha1.Proxy) *autoscalingv2beta2.HorizontalPodAutosc } -// ToYaml Convert ProxyConfig spec content to yaml format -func toYaml(proxyConfig *v1alpha1.ProxyConfig) string { +// ToYaml Convert ShardingSphereProxyServerConfig spec content to yaml format +func toYaml(proxyConfig *v1alpha1.ShardingSphereProxyServerConfig) string { y, _ := yaml.Marshal(proxyConfig.Spec) return string(y) } // UpdateDeployment FIXME:merge UpdateDeployment and ConstructCascadingDeployment -func UpdateDeployment(proxy *v1alpha1.Proxy, runtimeDeployment *appsv1.Deployment) { +func UpdateDeployment(proxy *v1alpha1.ShardingSphereProxy, runtimeDeployment *appsv1.Deployment) { runtimeDeployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s", imageName, proxy.Spec.Version) if proxy.Spec.AutomaticScaling == nil { runtimeDeployment.Spec.Replicas = &proxy.Spec.Replicas @@ -315,7 +315,7 @@ func UpdateDeployment(proxy *v1alpha1.Proxy, runtimeDeployment *appsv1.Deploymen } -func UpdateService(proxy *v1alpha1.Proxy, runtimeService *v1.Service) { +func UpdateService(proxy *v1alpha1.ShardingSphereProxy, runtimeService *v1.Service) { runtimeService.Spec.Type = proxy.Spec.ServiceType.Type runtimeService.Spec.Ports[0].Port = proxy.Spec.Port runtimeService.Spec.Ports[0].TargetPort = fromInt32(proxy.Spec.Port) @@ -324,7 +324,7 @@ func UpdateService(proxy *v1alpha1.Proxy, runtimeService *v1.Service) { } } -func UpdateHPA(proxy *v1alpha1.Proxy, runtimeHPA *autoscalingv2beta2.HorizontalPodAutoscaler) { +func UpdateHPA(proxy *v1alpha1.ShardingSphereProxy, runtimeHPA *autoscalingv2beta2.HorizontalPodAutoscaler) { runtimeHPA.Spec.Metrics[0].Resource.Target.AverageUtilization = &proxy.Spec.AutomaticScaling.Target runtimeHPA.Spec.Behavior.ScaleDown.StabilizationWindowSeconds = &proxy.Spec.AutomaticScaling.ScaleDownWindows runtimeHPA.Spec.Behavior.ScaleUp.StabilizationWindowSeconds = &proxy.Spec.AutomaticScaling.ScaleUpWindows
