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 6f6f5b4cf5a764edd877dc1fc180571bbed6fe72 Author: Ghoul_Lee <[email protected]> AuthorDate: Wed Jun 29 14:38:18 2022 +0800 feat(code hierarchy): add new hierarchy for operator (#11) * fate(code hierarchy): add new hierarchy for operator,addquickstart fix(webhook): fix return value * fate(code hierarchy): add new hierarchy for operator --- .gitignore | 2 +- doc/quickStart.md | 135 +++++++++++++++++++++ Makefile => shardingsphere-operator/Makefile | 0 PROJECT => shardingsphere-operator/PROJECT | 0 .../api}/v1alpha1/groupversion_info.go | 0 .../api}/v1alpha1/proxy_status.go | 0 .../api}/v1alpha1/proxy_types.go | 0 .../api}/v1alpha1/proxy_webhook.go | 0 .../api}/v1alpha1/proxyconfig_types.go | 0 .../api}/v1alpha1/serverconfig.go | 0 .../api}/v1alpha1/webhook_suite_test.go | 0 .../api}/v1alpha1/zz_generated.deepcopy.go | 29 ++--- .../build}/.dockerignore | 0 .../build}/Dockerfile | 0 .../charts}/shardingsphere-operator/.helmignore | 0 .../charts}/shardingsphere-operator/Chart.yaml | 0 .../crds/shardingsphere.sphere-ex.com_proxies.yaml | 0 .../shardingsphere.sphere-ex.com_proxyconfigs.yaml | 0 .../templates/deployment.yaml | 0 .../shardingsphere-operator/templates/rbac.yaml | 0 .../webhook/admission-webhook-apiservice.yaml | 0 .../webhook/admission-webhook-configuration.yaml | 0 .../webhook/admission-webhook-service.yaml | 0 .../charts}/shardingsphere-operator/values.yaml | 0 .../samples/shardingsphere_v1alpha1_proxy.yaml | 0 .../shardingsphere_v1alpha1_proxyconfig.yaml | 0 go.mod => shardingsphere-operator/go.mod | 0 go.sum => shardingsphere-operator/go.sum | 0 main.go => shardingsphere-operator/main.go | 10 +- .../pkg}/controllers/proxy_controller.go | 8 +- .../pkg}/controllers/proxyconfig_controller.go | 3 +- .../pkg}/controllers/suite_test.go | 3 +- .../pkg}/reconcile/resource.go | 18 +-- .../pkg}/reconcile/status.go | 0 .../pkg}/webhook/webhook.go | 4 +- 35 files changed, 171 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index fb3a7a9..1607d59 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ testbin/* *.swp *.swo *~ -build/certs/ +shardingsphere-operator/build/certs/ diff --git a/doc/quickStart.md b/doc/quickStart.md new file mode 100644 index 0000000..ee60d15 --- /dev/null +++ b/doc/quickStart.md @@ -0,0 +1,135 @@ +# ShardingSphere-Operator 简明使用手册 + +⚠️⚠️⚠️⚠️ 现阶段因为 shardingsphere-proxy 5.1.2 还未发布。proxyConfig 功能还不能使用,请使用前自行挂载现阶段版本支持的 server.yaml ⚠️⚠️⚠️⚠️ +## 配置 +**Proxy.shardingsphere.sphere-ex.com/v1alpha1** + +```yaml +apiVersion: shardingsphere.sphere-ex.com/v1alpha1 +kind: Proxy +metadata: + name: proxy-sample +spec: + version: "5.1.1" + serviceType: + type: ClusterIP + replicas: 1 + proxyConfigName: "sharding-proxy" + port: 3307 + mySQLDriver: + version: "5.1.47" + resources: + limits: + cpu: "2" + memory: "2Gi" + requests: + cpu: "0.2" + memory: "1.6Gi" +``` + +**ProxyConfig.shardingsphere.sphere-ex.com/v1alpha1** + +```yaml +apiVersion: shardingsphere.sphere-ex.com/v1alpha1 +kind: ProxyConfig +metadata: + name: proxyconfig-sample +spec: + authority: + users: + - user: root@% + password: root + - user: sphere + password: sphere + privilege: + type: ALL_PRIVILEGES_PERMITTED + mode: + type: Cluster + repository: + type: ZooKeeper + props: + namespace: "governance_ds" + server-lists: "<your zkAddr>" + retryIntervalMilliseconds: 500 + timeToLiveSeconds: 600 + maxRetries: 3 + operationTimeoutMilliseconds: 5000 + overwrite: true +``` + + +<span id="001">**values.yaml**</span> +```yaml +# Default values for proxy-operator. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 2 + +image: + repository: "shardingsphere-operator" + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "0.0.1" +imagePullSecrets: [] +service: + type: ClusterIP + port: 80 +resources: + requests: + cpu: 100m + memory: 128Mi +webhook: + serviceName: shardingsphere-operator-admission-webhook + port: 9443 +health: + healthProbePort: 8081 +serviceAccount: + name: shardingsphere-operator +``` +<span id=002>**用于 v5.1.1 测试的配置文件**</span> +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: sharding-proxy + namespace: default +data: + server.yaml: |- + mode: + type: Cluster + repository: + type: ZooKeeper + props: + namespace: governance_ds + server-lists: zookeeper.default:2181 + retryIntervalMilliseconds: 500 + timeToLiveSeconds: 600 + maxRetries: 3 + operationTimeoutMilliseconds: 5000 + overwrite: false + rules: + - !AUTHORITY + users: + - root@%:root + provider: + type: ALL_PRIVILEGES_PERMITTED + +``` + +## 安装 ShardingSphere-Operator +按照[values.yaml](#001)中的配置完成对 charts/shardingsphere-operator/values.yaml + +执行 +```shell +kubectl create ns shardingsphere-operator +helm install shardingsphere-operator shardingsphere-operator -n shardingsphere-operator +``` +## 安装 ShardingSphere-Proxy + + +首先新建一个[configmap.yaml](#002) +```shell +kubectl apply -f deploy/samples/shardingsphere_v1alpha1_proxy.yaml +kubectl apply -f configmap.yaml +``` diff --git a/Makefile b/shardingsphere-operator/Makefile similarity index 100% rename from Makefile rename to shardingsphere-operator/Makefile diff --git a/PROJECT b/shardingsphere-operator/PROJECT similarity index 100% rename from PROJECT rename to shardingsphere-operator/PROJECT diff --git a/api/v1alpha1/groupversion_info.go b/shardingsphere-operator/api/v1alpha1/groupversion_info.go similarity index 100% rename from api/v1alpha1/groupversion_info.go rename to shardingsphere-operator/api/v1alpha1/groupversion_info.go diff --git a/api/v1alpha1/proxy_status.go b/shardingsphere-operator/api/v1alpha1/proxy_status.go similarity index 100% rename from api/v1alpha1/proxy_status.go rename to shardingsphere-operator/api/v1alpha1/proxy_status.go diff --git a/api/v1alpha1/proxy_types.go b/shardingsphere-operator/api/v1alpha1/proxy_types.go similarity index 100% rename from api/v1alpha1/proxy_types.go rename to shardingsphere-operator/api/v1alpha1/proxy_types.go diff --git a/api/v1alpha1/proxy_webhook.go b/shardingsphere-operator/api/v1alpha1/proxy_webhook.go similarity index 100% rename from api/v1alpha1/proxy_webhook.go rename to shardingsphere-operator/api/v1alpha1/proxy_webhook.go diff --git a/api/v1alpha1/proxyconfig_types.go b/shardingsphere-operator/api/v1alpha1/proxyconfig_types.go similarity index 100% rename from api/v1alpha1/proxyconfig_types.go rename to shardingsphere-operator/api/v1alpha1/proxyconfig_types.go diff --git a/api/v1alpha1/serverconfig.go b/shardingsphere-operator/api/v1alpha1/serverconfig.go similarity index 100% rename from api/v1alpha1/serverconfig.go rename to shardingsphere-operator/api/v1alpha1/serverconfig.go diff --git a/api/v1alpha1/webhook_suite_test.go b/shardingsphere-operator/api/v1alpha1/webhook_suite_test.go similarity index 100% rename from api/v1alpha1/webhook_suite_test.go rename to shardingsphere-operator/api/v1alpha1/webhook_suite_test.go diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go similarity index 94% rename from api/v1alpha1/zz_generated.deepcopy.go rename to shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go index ba5390b..bb799a0 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/shardingsphere-operator/api/v1alpha1/zz_generated.deepcopy.go @@ -2,20 +2,21 @@ // +build !ignore_autogenerated /* -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. -*/ + * Copyright © 2022,Beijing Sifei Software Technology Co., LTD. + * All Rights Reserved. + * + * 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. + */ // Code generated by controller-gen. DO NOT EDIT. diff --git a/build/.dockerignore b/shardingsphere-operator/build/.dockerignore similarity index 100% rename from build/.dockerignore rename to shardingsphere-operator/build/.dockerignore diff --git a/build/Dockerfile b/shardingsphere-operator/build/Dockerfile similarity index 100% rename from build/Dockerfile rename to shardingsphere-operator/build/Dockerfile diff --git a/charts/shardingsphere-operator/.helmignore b/shardingsphere-operator/charts/shardingsphere-operator/.helmignore similarity index 100% rename from charts/shardingsphere-operator/.helmignore rename to shardingsphere-operator/charts/shardingsphere-operator/.helmignore diff --git a/charts/shardingsphere-operator/Chart.yaml b/shardingsphere-operator/charts/shardingsphere-operator/Chart.yaml similarity index 100% rename from charts/shardingsphere-operator/Chart.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/Chart.yaml diff --git a/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml b/shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml similarity index 100% rename from charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxies.yaml diff --git a/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml b/shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml similarity index 100% rename from charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/crds/shardingsphere.sphere-ex.com_proxyconfigs.yaml diff --git a/charts/shardingsphere-operator/templates/deployment.yaml b/shardingsphere-operator/charts/shardingsphere-operator/templates/deployment.yaml similarity index 100% rename from charts/shardingsphere-operator/templates/deployment.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/templates/deployment.yaml diff --git a/charts/shardingsphere-operator/templates/rbac.yaml b/shardingsphere-operator/charts/shardingsphere-operator/templates/rbac.yaml similarity index 100% rename from charts/shardingsphere-operator/templates/rbac.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/templates/rbac.yaml diff --git a/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml b/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml similarity index 100% rename from charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-apiservice.yaml diff --git a/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml b/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml similarity index 100% rename from charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-configuration.yaml diff --git a/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml b/shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml similarity index 100% rename from charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/templates/webhook/admission-webhook-service.yaml diff --git a/charts/shardingsphere-operator/values.yaml b/shardingsphere-operator/charts/shardingsphere-operator/values.yaml similarity index 100% rename from charts/shardingsphere-operator/values.yaml rename to shardingsphere-operator/charts/shardingsphere-operator/values.yaml diff --git a/deploy/samples/shardingsphere_v1alpha1_proxy.yaml b/shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxy.yaml similarity index 100% rename from deploy/samples/shardingsphere_v1alpha1_proxy.yaml rename to shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxy.yaml diff --git a/deploy/samples/shardingsphere_v1alpha1_proxyconfig.yaml b/shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxyconfig.yaml similarity index 100% rename from deploy/samples/shardingsphere_v1alpha1_proxyconfig.yaml rename to shardingsphere-operator/deploy/samples/shardingsphere_v1alpha1_proxyconfig.yaml diff --git a/go.mod b/shardingsphere-operator/go.mod similarity index 100% rename from go.mod rename to shardingsphere-operator/go.mod diff --git a/go.sum b/shardingsphere-operator/go.sum similarity index 100% rename from go.sum rename to shardingsphere-operator/go.sum diff --git a/main.go b/shardingsphere-operator/main.go similarity index 94% rename from main.go rename to shardingsphere-operator/main.go index cda162e..c468ea6 100644 --- a/main.go +++ b/shardingsphere-operator/main.go @@ -20,11 +20,11 @@ package main import ( "flag" "os" + "sphere-ex.com/shardingsphere-operator/api/v1alpha1" + "sphere-ex.com/shardingsphere-operator/pkg/controllers" "go.uber.org/zap/zapcore" - "sphere-ex.com/shardingsphere-operator/pkg/controllers" - // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -35,8 +35,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" - - shardingspherev1alpha1 "sphere-ex.com/shardingsphere-operator/api/v1alpha1" //+kubebuilder:scaffold:imports ) @@ -48,7 +46,7 @@ var ( func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) - utilruntime.Must(shardingspherev1alpha1.AddToScheme(scheme)) + utilruntime.Must(v1alpha1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme } @@ -100,7 +98,7 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "ProxyConfig") os.Exit(1) } - if err = (&shardingspherev1alpha1.Proxy{}).SetupWebhookWithManager(mgr); err != nil { + if err = (&v1alpha1.Proxy{}).SetupWebhookWithManager(mgr); err != nil { setupLog.Error(err, "unable to create webhook", "webhook", "Proxy") os.Exit(1) } diff --git a/pkg/controllers/proxy_controller.go b/shardingsphere-operator/pkg/controllers/proxy_controller.go similarity index 96% rename from pkg/controllers/proxy_controller.go rename to shardingsphere-operator/pkg/controllers/proxy_controller.go index de09b32..ebf6a23 100644 --- a/pkg/controllers/proxy_controller.go +++ b/shardingsphere-operator/pkg/controllers/proxy_controller.go @@ -26,7 +26,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" logger "sigs.k8s.io/controller-runtime/pkg/log" - shardingspherev1alpha1 "sphere-ex.com/shardingsphere-operator/api/v1alpha1" + "sphere-ex.com/shardingsphere-operator/api/v1alpha1" "sphere-ex.com/shardingsphere-operator/pkg/reconcile" "time" ) @@ -56,7 +56,7 @@ type ProxyReconciler struct { func (r *ProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { log := logger.FromContext(ctx) - run := &shardingspherev1alpha1.Proxy{} + run := &v1alpha1.Proxy{} err := r.Get(ctx, req.NamespacedName, run) if apierrors.IsNotFound(err) { log.Info("Resource in work queue no longer exists!") @@ -132,7 +132,7 @@ func (r *ProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl run.SetPodStarted(readyNodes) } } else { - if run.Status.Phase != shardingspherev1alpha1.StatusReady { + if run.Status.Phase != v1alpha1.StatusReady { log.Info("Status is now ready!") run.SetReady(readyNodes) } @@ -156,7 +156,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(&shardingspherev1alpha1.Proxy{}). + For(&v1alpha1.Proxy{}). Owns(&appsv1.Deployment{}). Owns(&v1.Service{}). Owns(&v1.Pod{}). diff --git a/pkg/controllers/proxyconfig_controller.go b/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go similarity index 99% rename from pkg/controllers/proxyconfig_controller.go rename to shardingsphere-operator/pkg/controllers/proxyconfig_controller.go index c7d13b5..1d5747c 100644 --- a/pkg/controllers/proxyconfig_controller.go +++ b/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go @@ -22,14 +22,13 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" + shardingspherev1alpha1 "sphere-ex.com/shardingsphere-operator/api/v1alpha1" "sphere-ex.com/shardingsphere-operator/pkg/reconcile" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" logger "sigs.k8s.io/controller-runtime/pkg/log" - - shardingspherev1alpha1 "sphere-ex.com/shardingsphere-operator/api/v1alpha1" ) // ProxyConfigReconciler reconciles a ProxyConfig object diff --git a/pkg/controllers/suite_test.go b/shardingsphere-operator/pkg/controllers/suite_test.go similarity index 99% rename from pkg/controllers/suite_test.go rename to shardingsphere-operator/pkg/controllers/suite_test.go index a5389d2..0e63fa5 100644 --- a/pkg/controllers/suite_test.go +++ b/shardingsphere-operator/pkg/controllers/suite_test.go @@ -19,6 +19,7 @@ package controllers import ( "path/filepath" + shardingspherev1alpha1 "sphere-ex.com/shardingsphere-operator/api/v1alpha1" "testing" . "github.com/onsi/ginkgo" @@ -30,8 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest/printer" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - - shardingspherev1alpha1 "sphere-ex.com/shardingsphere-operator/api/v1alpha1" //+kubebuilder:scaffold:imports ) diff --git a/pkg/reconcile/resource.go b/shardingsphere-operator/pkg/reconcile/resource.go similarity index 89% rename from pkg/reconcile/resource.go rename to shardingsphere-operator/pkg/reconcile/resource.go index 77d0d2e..6fef149 100644 --- a/pkg/reconcile/resource.go +++ b/shardingsphere-operator/pkg/reconcile/resource.go @@ -25,14 +25,14 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - shardingspherev1alpha1 "sphere-ex.com/shardingsphere-operator/api/v1alpha1" + "sphere-ex.com/shardingsphere-operator/api/v1alpha1" "strconv" "strings" ) const imageName = "apache/shardingsphere-proxy" -func ConstructCascadingDeployment(proxy *shardingspherev1alpha1.Proxy) *appsv1.Deployment { +func ConstructCascadingDeployment(proxy *v1alpha1.Proxy) *appsv1.Deployment { dp := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: proxy.Name, @@ -105,7 +105,7 @@ func ConstructCascadingDeployment(proxy *shardingspherev1alpha1.Proxy) *appsv1.D return processOptionalParameter(proxy, dp) } -func ConstructCascadingService(proxy *shardingspherev1alpha1.Proxy) *v1.Service { +func ConstructCascadingService(proxy *v1alpha1.Proxy) *v1.Service { svc := v1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -135,7 +135,7 @@ func ConstructCascadingService(proxy *shardingspherev1alpha1.Proxy) *v1.Service return &svc } -func addInitContainer(dp *appsv1.Deployment, mysql *shardingspherev1alpha1.MySQLDriver) { +func addInitContainer(dp *appsv1.Deployment, mysql *v1alpha1.MySQLDriver) { if len(dp.Spec.Template.Spec.InitContainers) == 0 { dp.Spec.Template.Spec.Containers[0].VolumeMounts = append(dp.Spec.Template.Spec.Containers[0].VolumeMounts, v1.VolumeMount{ @@ -175,7 +175,7 @@ else echo failed;exit 1;fi;mv /mysql-connector-java-{{ .Version }}.jar /opt/shar } -func processOptionalParameter(proxy *shardingspherev1alpha1.Proxy, dp *appsv1.Deployment) *appsv1.Deployment { +func processOptionalParameter(proxy *v1alpha1.Proxy, dp *appsv1.Deployment) *appsv1.Deployment { if proxy.Spec.MySQLDriver != nil { addInitContainer(dp, proxy.Spec.MySQLDriver) } @@ -183,7 +183,7 @@ func processOptionalParameter(proxy *shardingspherev1alpha1.Proxy, dp *appsv1.De } // ConstructCascadingConfigmap Construct spec resources to Configmap -func ConstructCascadingConfigmap(proxyConfig *shardingspherev1alpha1.ProxyConfig) *v1.ConfigMap { +func ConstructCascadingConfigmap(proxyConfig *v1alpha1.ProxyConfig) *v1.ConfigMap { y := toYaml(proxyConfig) return &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -201,13 +201,13 @@ func ConstructCascadingConfigmap(proxyConfig *shardingspherev1alpha1.ProxyConfig } // ToYaml Convert ProxyConfig spec content to yaml format -func toYaml(proxyConfig *shardingspherev1alpha1.ProxyConfig) string { +func toYaml(proxyConfig *v1alpha1.ProxyConfig) string { y, _ := yaml.Marshal(proxyConfig.Spec) return string(y) } // UpdateDeployment FIXME:merge UpdateDeployment and ConstructCascadingDeployment -func UpdateDeployment(proxy *shardingspherev1alpha1.Proxy, runtimeDeployment *appsv1.Deployment) { +func UpdateDeployment(proxy *v1alpha1.Proxy, runtimeDeployment *appsv1.Deployment) { runtimeDeployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s", imageName, proxy.Spec.Version) runtimeDeployment.Spec.Replicas = &proxy.Spec.Replicas runtimeDeployment.Spec.Template.Spec.Volumes[0].ConfigMap.Name = proxy.Spec.ProxyConfigName @@ -223,7 +223,7 @@ func UpdateDeployment(proxy *shardingspherev1alpha1.Proxy, runtimeDeployment *ap } -func UpdateService(proxy *shardingspherev1alpha1.Proxy, runtimeService *v1.Service) { +func UpdateService(proxy *v1alpha1.Proxy, 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) diff --git a/pkg/reconcile/status.go b/shardingsphere-operator/pkg/reconcile/status.go similarity index 100% rename from pkg/reconcile/status.go rename to shardingsphere-operator/pkg/reconcile/status.go diff --git a/pkg/webhook/webhook.go b/shardingsphere-operator/pkg/webhook/webhook.go similarity index 99% rename from pkg/webhook/webhook.go rename to shardingsphere-operator/pkg/webhook/webhook.go index dc21e3a..4f93ffb 100644 --- a/pkg/webhook/webhook.go +++ b/shardingsphere-operator/pkg/webhook/webhook.go @@ -19,7 +19,6 @@ package webhook import ( "errors" - "io/ioutil" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/rest" @@ -212,9 +211,8 @@ func (blder *WebhookBuilder) registerApiservice() { func getApiService() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - ar, _ := ioutil.ReadAll(r.Body) + _, _ = w.Write([]byte("{}")) w.WriteHeader(http.StatusOK) - _, _ = w.Write(ar) } }
