Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Do not manage ports in managed ExternalAccess mode #1211

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions pkg/deployment/resources/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}

Expand Down
49 changes: 0 additions & 49 deletions pkg/util/k8sutil/patcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down