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:
parent
f585136505
commit
c2f819c073
3 changed files with 52 additions and 2 deletions
|
@ -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
|
||||||
|
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue