Skip to content

Commit e5da154

Browse files
author
Airren
committed
feat: change ep service bind
Signed-off-by: Airren <qiang.ren@intel.com>
1 parent a9011f9 commit e5da154

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ else
1515
GIT_VERSION=$(shell git describe --abbrev=0 --tags --always)
1616
endif
1717

18-
IMAGE_TAG = ${GIT_VERSION}
18+
IMAGE_TAG = svctest
1919
REGISTRY ?= ghcr.io
2020
REGISTRY_NAMESPACE ?= fleetboard-io
2121

@@ -81,10 +81,10 @@ image-crossdns:
8181
docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/crossdns:latest
8282

8383
image-cnf:
84-
docker buildx build --platform linux/amd64,linux/arm64 $(DOCKERARGS) -f ./build/cnf.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:${IMAGE_TAG}
85-
docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:${IMAGE_TAG}
86-
docker tag ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:${IMAGE_TAG} ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:latest
87-
docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:latest
84+
docker buildx build --platform linux/amd64,linux/arm64 $(DOCKERARGS) -f ./build/cnf.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:${IMAGE_TAG} --push
85+
# docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:${IMAGE_TAG}
86+
# docker tag ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:${IMAGE_TAG} ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:latest
87+
# docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/cnf:latest
8888

8989
image-proxy:
9090
docker buildx build --platform linux/amd64,linux/arm64 $(DOCKERARGS) -f ./build/proxy.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/proxy:${IMAGE_TAG}
@@ -93,10 +93,10 @@ image-proxy:
9393
docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/proxy:latest
9494

9595
image-ep-controller:
96-
docker buildx build --platform linux/amd64,linux/arm64 $(DOCKERARGS) -f ./build/ep-controller.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:${IMAGE_TAG}
97-
docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:${IMAGE_TAG}
98-
docker tag ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:${IMAGE_TAG} ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:latest
99-
docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:latest
96+
docker buildx build --platform linux/amd64,linux/arm64 $(DOCKERARGS) -f ./build/ep-controller.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:${IMAGE_TAG} --push
97+
#docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:${IMAGE_TAG}
98+
#docker tag ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:${IMAGE_TAG} ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:latest
99+
#docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/controller:latest
100100

101101

102102
images-push: image-crossdns image-cnf image-proxy image-ep-controller

build/cnf.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ FROM golang:1.21-alpine AS builder
33
WORKDIR /workspace
44
RUN apk update && apk add --no-cache make git
55
COPY ../go.mod ../go.sum ./
6+
# ENV GOPROXY='https://goproxy.io,direct'
7+
ENV GOPROXY=https://goproxy.cn,direct
8+
69
RUN go mod download
710
COPY .. .
811
RUN make cnf

build/ep-controller.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM golang:1.21-alpine AS builder
33
WORKDIR /workspace
44
RUN apk add make
55
COPY ../go.mod ../go.sum ./
6+
ENV GOPROXY=https://goproxy.cn,direct
67
RUN go mod download
78
COPY .. .
89
RUN make ep-controller

pkg/controller/endpointslice/endpointslice.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (c *Controller) syncService(logger klog.Logger, key string) error {
375375
}
376376

377377
esLabelSelector := labels.Set(map[string]string{
378-
discovery.LabelServiceName: service.Name,
378+
discovery.LabelServiceName: GetServiceLabelFromSvcName(service.Name),
379379
discovery.LabelManagedBy: c.reconciler.GetControllerName(),
380380
}).AsSelectorPreValidated()
381381
endpointSlices, err := c.endpointSliceLister.EndpointSlices(service.Namespace).List(esLabelSelector)
@@ -461,8 +461,8 @@ func (c *Controller) onEndpointSliceUpdate(logger klog.Logger, prevObj, obj inte
461461
// EndpointSlice generation does not change when labels change. Although the
462462
// controller will never change LabelServiceName, users might. This check
463463
// ensures that we handle changes to this label.
464-
svcName := endpointSlice.Labels[discovery.LabelServiceName]
465-
prevSvcName := prevEndpointSlice.Labels[discovery.LabelServiceName]
464+
svcName, _ := GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName])
465+
prevSvcName, _ := GetServiceNameFromEpLabel(prevEndpointSlice.Labels[discovery.LabelServiceName])
466466
if svcName != prevSvcName {
467467
logger.Info("label changed", "label", discovery.LabelServiceName, "oldService",
468468
prevSvcName, "newService", svcName, "endpointslice", klog.KObj(endpointSlice))

pkg/controller/endpointslice/util/endpointslice_tracker.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package util
1818

1919
import (
20+
"fmt"
21+
"strings"
2022
"sync"
2123

2224
v1 "k8s.io/api/core/v1"
@@ -187,6 +189,20 @@ func (est *EndpointSliceTracker) GenerationsForSliceUnsafe(endpointSlice *discov
187189
// getServiceNN returns a namespaced name for the Service corresponding to the
188190
// provided EndpointSlice.
189191
func getServiceNN(endpointSlice *discovery.EndpointSlice) types.NamespacedName {
190-
serviceName := endpointSlice.Labels[discovery.LabelServiceName]
192+
serviceName, _ := GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName])
191193
return types.NamespacedName{Name: serviceName, Namespace: endpointSlice.Namespace}
192194
}
195+
196+
func GetServiceLabelFromSvcName(serviceName string) string {
197+
return fmt.Sprintf("%s-----%s", "nauti-service", serviceName)
198+
}
199+
func GetServiceNameFromEpLabel(label string) (string, error) {
200+
parts := strings.Split(label, "-----")
201+
if len(parts) != 2 {
202+
return "", fmt.Errorf("invalid label format")
203+
}
204+
if parts[0] != "nauti-service" {
205+
return "", fmt.Errorf("invalid label prefix")
206+
}
207+
return parts[1], nil
208+
}

pkg/controller/endpointslice/utils.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"errors"
2121
"fmt"
2222
"net"
23+
"strings"
2324
"time"
2425

2526
"github.com/fleetboard-io/fleetboard/pkg/known"
@@ -210,8 +211,8 @@ func ServiceControllerKey(endpointSlice *discovery.EndpointSlice) (string, error
210211
if endpointSlice == nil {
211212
return "", fmt.Errorf("nil EndpointSlice passed to ServiceControllerKey()")
212213
}
213-
serviceName, ok := endpointSlice.Labels[discovery.LabelServiceName]
214-
if !ok || serviceName == "" {
214+
serviceName, err := GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName])
215+
if err != nil || serviceName == "" {
215216
return "", fmt.Errorf("EndpointSlice missing %s label", discovery.LabelServiceName)
216217
}
217218
return fmt.Sprintf("%s/%s", endpointSlice.Namespace, serviceName), nil
@@ -256,7 +257,7 @@ func setEndpointSliceLabels(logger klog.Logger, epSlice *discovery.EndpointSlice
256257
// add or remove headless label depending on the service Type
257258

258259
// override endpoint slices reserved labels
259-
svcLabels[discovery.LabelServiceName] = service.Name
260+
svcLabels[discovery.LabelServiceName] = GetServiceLabelFromSvcName(service.Name)
260261
svcLabels[discovery.LabelManagedBy] = controllerName
261262
svcLabels[v1.IsHeadlessService] = "true"
262263

@@ -404,3 +405,17 @@ func findPort(pod *v1.Pod, svcPort *v1.ServicePort) (int, error) {
404405

405406
return 0, fmt.Errorf("no suitable port for manifest: %s", pod.UID)
406407
}
408+
409+
func GetServiceLabelFromSvcName(serviceName string) string {
410+
return fmt.Sprintf("%s-----%s", "nauti-service", serviceName)
411+
}
412+
func GetServiceNameFromEpLabel(label string) (string, error) {
413+
parts := strings.Split(label, "-----")
414+
if len(parts) != 2 {
415+
return "", fmt.Errorf("invalid label format")
416+
}
417+
if parts[0] != "nauti-service" {
418+
return "", fmt.Errorf("invalid label prefix")
419+
}
420+
return parts[1], nil
421+
}

0 commit comments

Comments
 (0)