From 7e9e23e7879dfeb9544f0260806a3d3b002c8c04 Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Thu, 13 Jan 2022 20:35:51 +0800 Subject: [PATCH] feat(main): fix panic if err is nil --- README.md | 42 +++++++++++++++++++++++++++++++++++---- config/demo/dmz-kube.yaml | 8 +------- controllers/helper.go | 2 +- controllers/sync.go | 2 +- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 4d0020b..a0c9aa4 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,46 @@ # endpoints-operator > 场景对于外部场景使用固定的endpoint维护增加探活功能 -根据service数据生成endpoint数据 - -1. 根据service的port映射对应的endpoints数据 -2. targetPort 不能使用string只能对应int数据 +## 背景 +在很多场景下,用户集群可能需要访问集群外的数据,这时候又想使用service提供的功能,我们一般创建一个空的service,并手动绑定对应的endpoint. +```yaml +apiVersion: v1 +kind: Service +metadata: + name: mysql-kube + namespace: default +spec: + clusterIP: 10.96.0.100 + clusterIPs: + - 10.96.0.100 + internalTrafficPolicy: Cluster + ipFamilies: + - IPv4 + ipFamilyPolicy: SingleStack + ports: + - name: mysql + port: 3306 + protocol: TCP + targetPort: 3306 + sessionAffinity: None + type: ClusterIP +--- +apiVersion: v1 +kind: Endpoints +metadata: + name: mysql-kube + namespace: default +subsets: +- addresses: + - ip: 10.0.99.251 + ports: + - name: mysql + port: 3306 + protocol: TCP +``` +这样手动设置了对应的 ## Usage diff --git a/config/demo/dmz-kube.yaml b/config/demo/dmz-kube.yaml index 1d29585..5d6bfd7 100644 --- a/config/demo/dmz-kube.yaml +++ b/config/demo/dmz-kube.yaml @@ -22,6 +22,7 @@ spec: timeoutSeconds: 1 hosts: - 10.0.112.255 + - 10.0.112.251 ports: - name: https port: 6443 @@ -29,10 +30,3 @@ spec: targetPort: 6443 tcpSocket: enable: true - - name: http - port: 80 - protocol: TCP - targetPort: 80 - httpGet: - path: / - scheme: http diff --git a/controllers/helper.go b/controllers/helper.go index 8455fe9..c01165c 100644 --- a/controllers/helper.go +++ b/controllers/helper.go @@ -173,7 +173,7 @@ func (c *Reconciler) updateCondition(cep *v1beta1.ClusterEndpoint, condition v1b for i, cond := range cep.Status.Conditions { if cond.Type == condition.Type { hasCondition = true - if cond.Reason != condition.Reason || cond.Status != condition.Status { + if cond.Reason != condition.Reason || cond.Status != condition.Status || cond.Message != condition.Message { cep.Status.Conditions[i] = condition } } diff --git a/controllers/sync.go b/controllers/sync.go index c95ab39..e36da11 100644 --- a/controllers/sync.go +++ b/controllers/sync.go @@ -94,7 +94,7 @@ func (c *Reconciler) syncEndpoint(ctx context.Context, cep *v1beta1.ClusterEndpo }) } subErr := ToAggregate(errors) - if len(subErr.Errors()) != 0 { + if subErr != nil && len(subErr.Errors()) != 0 { e = append(e, fmt.Errorf(subErr.Error())) }