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 6782f9901b174e4f8d2d5c6b670181987f5b1a53 Author: Ghoul_Lee <[email protected]> AuthorDate: Fri May 6 16:49:59 2022 +0800 Update resources based on CRD objects (#7) * ADD: Update proxy CRD cascaded resource logic FIX: Fix some logs format UPDATE: Status logic and update some status logic function * UPDATE: 1. Update LICENSE 2. Update status function 3. Change updateDeployment,add some default value ADD: 1. Update or correct the service and deployment resource according to the CRD object * UPDATE: update license to author Beijing Sifei Software Technology Co --- api/v1alpha1/groupversion_info.go | 21 ++-- api/v1alpha1/proxy_status.go | 24 ++-- api/v1alpha1/proxy_types.go | 21 ++-- api/v1alpha1/proxyconfig_types.go | 21 ++-- api/v1alpha1/serverconfig.go | 21 ++-- config/samples/shardingsphere_v1alpha1_proxy.yaml | 11 +- main.go | 21 ++-- pkg/controllers/proxy_controller.go | 43 ++++--- pkg/controllers/proxyconfig_controller.go | 22 ++-- pkg/controllers/suite_test.go | 21 ++-- pkg/reconcile/resource.go | 134 +++++++++++++++++++--- pkg/reconcile/status.go | 31 ++--- 12 files changed, 260 insertions(+), 131 deletions(-) diff --git a/api/v1alpha1/groupversion_info.go b/api/v1alpha1/groupversion_info.go index 319ac03..2da40bd 100644 --- a/api/v1alpha1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ // Package v1alpha1 contains API Schema definitions for the shardingsphere v1alpha1 API group diff --git a/api/v1alpha1/proxy_status.go b/api/v1alpha1/proxy_status.go index 12adbef..efcb986 100644 --- a/api/v1alpha1/proxy_status.go +++ b/api/v1alpha1/proxy_status.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package v1alpha1 @@ -85,13 +86,14 @@ func (p *Proxy) SetPodStarted(readyNodes int32) { p.Status.ReadyNodes = readyNodes } -func (p *Proxy) SetPodNotStarted() { +func (p *Proxy) SetPodNotStarted(readyNodes int32) { p.Status.Phase = StatusNotReady p.Status.Conditions = append([]Condition{}, Condition{ Type: ConditionStarted, Status: v1.ConditionFalse, LastUpdateTime: metav1.Now(), }) + p.Status.ReadyNodes = readyNodes } func (p *Proxy) SetReady(readyNodes int32) { diff --git a/api/v1alpha1/proxy_types.go b/api/v1alpha1/proxy_types.go index 5b5e569..f6dc11d 100644 --- a/api/v1alpha1/proxy_types.go +++ b/api/v1alpha1/proxy_types.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package v1alpha1 diff --git a/api/v1alpha1/proxyconfig_types.go b/api/v1alpha1/proxyconfig_types.go index 59156e3..6335c26 100644 --- a/api/v1alpha1/proxyconfig_types.go +++ b/api/v1alpha1/proxyconfig_types.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package v1alpha1 diff --git a/api/v1alpha1/serverconfig.go b/api/v1alpha1/serverconfig.go index b4f4518..732997b 100644 --- a/api/v1alpha1/serverconfig.go +++ b/api/v1alpha1/serverconfig.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package v1alpha1 diff --git a/config/samples/shardingsphere_v1alpha1_proxy.yaml b/config/samples/shardingsphere_v1alpha1_proxy.yaml index aaad174..6ab5097 100644 --- a/config/samples/shardingsphere_v1alpha1_proxy.yaml +++ b/config/samples/shardingsphere_v1alpha1_proxy.yaml @@ -5,10 +5,11 @@ metadata: spec: version: "5.1.0" serviceType: - type: ClusterIP + type: NodePort + nodePort: 32001 replicas: 2 proxyConfigName: "sharding-proxy" - port: 3307 + port: 3308 mySQLDriver: version: "5.1.47" resources: @@ -20,14 +21,14 @@ spec: memory: "1.6Gi" livenessProbe: tcpSocket: - port: 3307 + port: 3308 periodSeconds: 10 readinessProbe: tcpSocket: - port: 3307 + port: 3308 periodSeconds: 20 startupProbe: tcpSocket: - port: 3307 + port: 3308 periodSeconds: 5 failureThreshold: 12 diff --git a/main.go b/main.go index 9bba22c..8a5a6d5 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package main diff --git a/pkg/controllers/proxy_controller.go b/pkg/controllers/proxy_controller.go index a32612c..a1984c2 100644 --- a/pkg/controllers/proxy_controller.go +++ b/pkg/controllers/proxy_controller.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package controllers @@ -80,9 +81,16 @@ func (r *ProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl } else if err != nil { log.Error(err, "Error getting cascaded deployment") return ctrl.Result{}, err + } else { + originDeployment := runtimeDeployment.DeepCopy() + reconcile.UpdateDeployment(run, originDeployment) + err = r.Update(ctx, originDeployment) + if err != nil { + log.Error(err, "Error updating cascaded deployment") + return ctrl.Result{Requeue: true}, err + } } - // TODO: Whether the service needs to be corrected runtimeService := &v1.Service{} err = r.Get(ctx, req.NamespacedName, runtimeService) if apierrors.IsNotFound(err) { @@ -99,6 +107,14 @@ func (r *ProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl } else if err != nil { log.Error(err, "Error getting cascaded service") return ctrl.Result{}, err + } else { + originService := runtimeService.DeepCopy() + reconcile.UpdateService(run, originService) + err = r.Update(ctx, originService) + if err != nil { + log.Error(err, "Error updating cascaded service") + return ctrl.Result{}, err + } } podList := &v1.PodList{} @@ -109,8 +125,8 @@ func (r *ProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl } result := ctrl.Result{} + readyNodes := reconcile.CountingReadyPods(podList) if reconcile.IsRunning(podList) { - readyNodes := reconcile.CountingReadyPods(podList) if readyNodes != run.Spec.Replicas { restartTimes := reconcile.CountingPodMaxRestartTimes(podList) if restartTimes > MaxRestartedCount { @@ -130,7 +146,7 @@ func (r *ProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl } } else { // TODO: Waiting for pods to start exceeds the maximum number of retries - run.SetPodNotStarted() + run.SetPodNotStarted(readyNodes) result.RequeueAfter = WaitingForReady } @@ -149,6 +165,7 @@ func (r *ProxyReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&shardingspherev1alpha1.Proxy{}). Owns(&appsv1.Deployment{}). + Owns(&v1.Service{}). Owns(&v1.Pod{}). Complete(r) } diff --git a/pkg/controllers/proxyconfig_controller.go b/pkg/controllers/proxyconfig_controller.go index 184b6b2..c7d13b5 100644 --- a/pkg/controllers/proxyconfig_controller.go +++ b/pkg/controllers/proxyconfig_controller.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package controllers @@ -92,7 +93,6 @@ func (r *ProxyConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) err = r.Update(ctx, configmap) if err != nil { log.Error(err, "Error updating cascaded configmap") - // 重新排队为了处理冲突错误 // TODO: Error handling for conflict errors alone return ctrl.Result{Requeue: true}, err } diff --git a/pkg/controllers/suite_test.go b/pkg/controllers/suite_test.go index abac13c..a5389d2 100644 --- a/pkg/controllers/suite_test.go +++ b/pkg/controllers/suite_test.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package controllers diff --git a/pkg/reconcile/resource.go b/pkg/reconcile/resource.go index 3eec9b8..a7c94a3 100644 --- a/pkg/reconcile/resource.go +++ b/pkg/reconcile/resource.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package reconcile @@ -117,12 +118,9 @@ func ConstructCascadingService(proxy *shardingspherev1alpha1.Proxy) *v1.Service Type: proxy.Spec.ServiceType.Type, Ports: []v1.ServicePort{ { - Name: "proxy-port", - TargetPort: intstr.IntOrString{ - Type: intstr.Int, - IntVal: proxy.Spec.Port, - }, - Port: proxy.Spec.Port, + Name: "proxy-port", + TargetPort: fromInt32(proxy.Spec.Port), + Port: proxy.Spec.Port, }, }, }, @@ -169,6 +167,35 @@ else echo failed;exit 1;fi;mv /mysql-connector-java-{{ .Version }}.jar /opt/shar } +func updateInitContainer(dp *appsv1.Deployment, mysql *shardingspherev1alpha1.MySQLDriver) { + + if len(dp.Spec.Template.Spec.InitContainers) != 0 { + scriptStr := strings.Builder{} + t1, _ := template.New("shell").Parse(`wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/{{ .Version }}/mysql-connector-java-{{ .Version }}.jar; +wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/{{ .Version }}/mysql-connector-java-{{ .Version }}.jar.md5; +if [ $(md5sum /mysql-connector-java-{{ .Version }}.jar | cut -d ' ' -f1) = $(cat /mysql-connector-java-{{ .Version }}.jar.md5) ]; +then echo success; +else echo failed;exit 1;fi;mv /mysql-connector-java-{{ .Version }}.jar /opt/shardingsphere-proxy/ext-lib`) + _ = t1.Execute(&scriptStr, mysql) + dp.Spec.Template.Spec.InitContainers = []v1.Container{ + { + Name: "download-mysql-connect", + Image: "busybox:1.35.0", + Command: []string{"/bin/sh", "-c", scriptStr.String()}, + VolumeMounts: []v1.VolumeMount{ + { + Name: "mysql-connect-jar", + MountPath: "/opt/shardingsphere-proxy/ext-lib", + }, + }, + }, + } + } else { + addInitContainer(dp, mysql) + } + +} + func processOptionalParameter(proxy *shardingspherev1alpha1.Proxy, dp *appsv1.Deployment) *appsv1.Deployment { if proxy.Spec.MySQLDriver != nil { addInitContainer(dp, proxy.Spec.MySQLDriver) @@ -256,3 +283,78 @@ func toYaml(proxyConfig *shardingspherev1alpha1.ProxyConfig) string { y, _ := yaml.Marshal(proxyConfig.Spec) return string(y) } + +// UpdateDeployment FIXME:merge UpdateDeployment and ConstructCascadingDeployment +func UpdateDeployment(proxy *shardingspherev1alpha1.Proxy, runtimeDeployment *appsv1.Deployment) { + runtimeDeployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("apache/shardingsphere-proxy:%s", proxy.Spec.Version) + runtimeDeployment.Spec.Replicas = &proxy.Spec.Replicas + runtimeDeployment.Spec.Template.Spec.Volumes[0].ConfigMap.Name = proxy.Spec.ProxyConfigName + runtimeDeployment.Spec.Template.Spec.Containers[0].Env[0].Value = strconv.FormatInt(int64(proxy.Spec.Port), 10) + runtimeDeployment.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = proxy.Spec.Port + if proxy.Spec.MySQLDriver.Version != "" { + updateInitContainer(runtimeDeployment, proxy.Spec.MySQLDriver) + } + if proxy.Spec.Resources != nil { + runtimeDeployment.Spec.Template.Spec.Containers[0].Resources = *proxy.Spec.Resources + } else { + cpu, _ := resource.ParseQuantity("0.2") + memory, _ := resource.ParseQuantity("1.6Gi") + runtimeDeployment.Spec.Template.Spec.Containers[0].Resources = v1.ResourceRequirements{ + Requests: v1.ResourceList{ + "cpu": cpu, + "memory": memory, + }, + } + } + if proxy.Spec.LivenessProbe != nil { + runtimeDeployment.Spec.Template.Spec.Containers[0].LivenessProbe = proxy.Spec.LivenessProbe + } else { + runtimeDeployment.Spec.Template.Spec.Containers[0].LivenessProbe = &v1.Probe{ + ProbeHandler: v1.ProbeHandler{ + TCPSocket: &v1.TCPSocketAction{ + Port: intstr.FromInt(int(proxy.Spec.Port)), + }, + }, + + PeriodSeconds: 10, + } + } + if proxy.Spec.ReadinessProbe != nil { + runtimeDeployment.Spec.Template.Spec.Containers[0].ReadinessProbe = proxy.Spec.ReadinessProbe + } else { + runtimeDeployment.Spec.Template.Spec.Containers[0].ReadinessProbe = &v1.Probe{ + ProbeHandler: v1.ProbeHandler{ + TCPSocket: &v1.TCPSocketAction{ + Port: intstr.FromInt(int(proxy.Spec.Port)), + }, + }, + PeriodSeconds: 10, + } + } + if proxy.Spec.StartupProbe != nil { + runtimeDeployment.Spec.Template.Spec.Containers[0].StartupProbe = proxy.Spec.StartupProbe + } else { + runtimeDeployment.Spec.Template.Spec.Containers[0].StartupProbe = &v1.Probe{ + ProbeHandler: v1.ProbeHandler{ + TCPSocket: &v1.TCPSocketAction{ + Port: intstr.FromInt(int(proxy.Spec.Port)), + }, + }, + PeriodSeconds: 5, + FailureThreshold: 12, + } + } +} + +func UpdateService(proxy *shardingspherev1alpha1.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) + if proxy.Spec.ServiceType.NodePort != 0 { + runtimeService.Spec.Ports[0].NodePort = proxy.Spec.ServiceType.NodePort + } +} + +func fromInt32(val int32) intstr.IntOrString { + return intstr.IntOrString{Type: intstr.Int, IntVal: val} +} diff --git a/pkg/reconcile/status.go b/pkg/reconcile/status.go index 8d237d7..3833099 100644 --- a/pkg/reconcile/status.go +++ b/pkg/reconcile/status.go @@ -1,17 +1,18 @@ /* - * Copyright (c) 2022. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package reconcile @@ -22,10 +23,10 @@ import ( ) func IsRunning(podList *v1.PodList) bool { - status := true + status := false for _, pod := range podList.Items { - if pod.Status.Phase != v1.PodRunning { - status = false + if pod.Status.Phase == v1.PodRunning && pod.ObjectMeta.DeletionTimestamp == nil { + status = true } } @@ -44,9 +45,9 @@ func CountingReadyPods(podList *v1.PodList) int32 { } func CountingPodMaxRestartTimes(podList *v1.PodList) int32 { - var podRestartCount int32 = math.MinInt32 + var podRestartCount int32 = math.MaxInt32 for _, pod := range podList.Items { - if podRestartCount < pod.Status.ContainerStatuses[0].RestartCount { + if podRestartCount > pod.Status.ContainerStatuses[0].RestartCount { podRestartCount = pod.Status.ContainerStatuses[0].RestartCount } }
