1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-15 17:51:03 +00:00

[Bugfix] Ensure NodePort wont be duplicated (#1209)

This commit is contained in:
Adam Janikowski 2022-12-11 22:19:21 +01:00 committed by GitHub
parent f585136505
commit c2f819c073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 2 deletions

View file

@ -42,6 +42,7 @@
- (Bugfix) Change member port discovery - (Bugfix) Change member port discovery
- (Feature) Do not change external service ports - (Feature) Do not change external service ports
- (Bugfix) Fix Operator Debug mode - (Bugfix) Fix Operator Debug mode
- (Bugfix) Ensure NodePort wont be duplicated
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25) ## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
- (Feature) Add action progress - (Feature) Add action progress

View file

@ -375,7 +375,7 @@ func (r *Resources) ensureExternalAccessManagedServices(ctx context.Context, cac
apply := func(svc *core.Service) (bool, error) { apply := func(svc *core.Service) (bool, error) {
return patcher.ServicePatcher(ctx, cachedStatus.ServicesModInterface().V1(), svc, meta.PatchOptions{}, return patcher.ServicePatcher(ctx, cachedStatus.ServicesModInterface().V1(), svc, meta.PatchOptions{},
patcher.PatchServiceOnlyPorts(ports...), patcher.PatchServiceOnlyPortsWithoutNodePort(ports...),
patcher.PatchServiceSelector(selectors)) patcher.PatchServiceSelector(selectors))
} }

View file

@ -149,9 +149,58 @@ func PatchServiceOnlyPorts(ports ...core.ServicePort) ServicePatch {
} }
} }
func PatchServiceOnlyPortsWithoutNodePort(ports ...core.ServicePort) ServicePatch {
return func(in *core.Service) []patch.Item {
psvc := in.Spec.DeepCopy()
cp := psvc.Ports
changed := false
for pid := range ports {
got := false
for id := range cp {
if ports[pid].Name == cp[id].Name {
got = true
// Set ignored fields
if ports[pid].AppProtocol == nil {
ports[pid].AppProtocol = cp[id].AppProtocol
}
if ports[pid].Protocol == "" {
ports[pid].Protocol = cp[id].Protocol
}
if ports[pid].TargetPort.StrVal == "" && ports[pid].TargetPort.IntVal == 0 {
ports[pid].TargetPort = cp[id].TargetPort
}
if !equality.Semantic.DeepEqual(ports[pid], cp[id]) {
q := ports[pid].DeepCopy()
cp[id] = *q
changed = true
break
}
}
}
if !got {
q := ports[pid].DeepCopy()
cp = append(cp, *q)
changed = true
}
}
if !changed {
return nil
}
return []patch.Item{
patch.ItemReplace(patch.NewPath("spec", "ports"), cp),
}
}
}
func PatchServiceSelector(selector map[string]string) ServicePatch { func PatchServiceSelector(selector map[string]string) ServicePatch {
return func(in *core.Service) []patch.Item { return func(in *core.Service) []patch.Item {
if equality.Semantic.DeepEqual(in.Spec.Selector, selector) { if in.Spec.Selector != nil && equality.Semantic.DeepEqual(in.Spec.Selector, selector) {
return nil return nil
} }