mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Bugfix] Do not manage ports in managed ExternalAccess mode (#1211)
This commit is contained in:
parent
d130445d17
commit
60adc4e03a
3 changed files with 3 additions and 52 deletions
|
@ -1,6 +1,7 @@
|
|||
# Change Log
|
||||
|
||||
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
||||
- (Bugfix) Do not manage ports in managed ExternalAccess mode
|
||||
|
||||
## [1.2.21](https://github.com/arangodb/kube-arangodb/tree/1.2.21) (2022-12-13)
|
||||
- (Improvement) Bump dependencies
|
||||
|
|
|
@ -248,7 +248,7 @@ func (r *Resources) ensureExternalAccessServices(ctx context.Context, cachedStat
|
|||
|
||||
if spec.GetType().IsManaged() {
|
||||
// Managed services should not be created or removed by the operator.
|
||||
return r.ensureExternalAccessManagedServices(ctx, cachedStatus, eaServiceName, eaPorts, eaSelector, spec)
|
||||
return r.ensureExternalAccessManagedServices(ctx, cachedStatus, eaServiceName, eaSelector, spec)
|
||||
}
|
||||
|
||||
log := r.log.Str("section", "service-ea").Str("role", role).Str("service", eaServiceName)
|
||||
|
@ -368,14 +368,13 @@ func (r *Resources) ensureExternalAccessServices(ctx context.Context, cachedStat
|
|||
// ensureExternalAccessServices ensures if there are correct selectors on a managed services.
|
||||
// If hardcoded external service names are not on the list of managed services then it will be checked additionally.
|
||||
func (r *Resources) ensureExternalAccessManagedServices(ctx context.Context, cachedStatus inspectorInterface.Inspector, eaServiceName string,
|
||||
ports []core.ServicePort, selectors map[string]string, spec api.ExternalAccessSpec) error {
|
||||
selectors map[string]string, spec api.ExternalAccessSpec) error {
|
||||
|
||||
log := r.log.Str("section", "service-ea").Str("service", eaServiceName)
|
||||
managedServiceNames := spec.GetManagedServiceNames()
|
||||
|
||||
apply := func(svc *core.Service) (bool, error) {
|
||||
return patcher.ServicePatcher(ctx, cachedStatus.ServicesModInterface().V1(), svc, meta.PatchOptions{},
|
||||
patcher.PatchServiceOnlyPortsWithoutNodePort(ports...),
|
||||
patcher.PatchServiceSelector(selectors))
|
||||
}
|
||||
|
||||
|
|
|
@ -149,55 +149,6 @@ 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 {
|
||||
return func(in *core.Service) []patch.Item {
|
||||
if in.Spec.Selector != nil && equality.Semantic.DeepEqual(in.Spec.Selector, selector) {
|
||||
|
|
Loading…
Reference in a new issue