Skip to content

[OCTRL-1091] Integrate k8s client into ECS core - #833

Open
justonedev1 wants to merge 8 commits into
masterfrom
OCTRL-1091-merge
Open

[OCTRL-1091] Integrate k8s client into ECS core#833
justonedev1 wants to merge 8 commits into
masterfrom
OCTRL-1091-merge

Conversation

@justonedev1

@justonedev1justonedev1 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

This is actual implementation of the ECS Kubernetes bridge.

Before merging it needs the OCTRL-1090

The goal of this PR was to take existing code that deploys Mesos tasks and adjusts it for the kubernetes client usage, basically linking CRDs defined and managed by managers in control-operator to the existing ECS task infrastructure and classes. The code from managerk8s.go was inspired roughly accroding to this table (generated by llm, but I went through it):

managerk8s.goMesos counterpartLocation
createK8sTaskEntries — InboundChannels loop, IPC endpoint, ::global aliasmakeTaskForMesosResources — same loop, IPC/TCP handling, global aliasscheduler.go:1346
buildK8sNodeTaskRefsO2_ROLE/O2_SYSTEM env var injection loopmakeTaskForMesosResourcesfillEnvDefault loop for the same two varsscheduler.go:1458
buildK8sNodeTaskRefs — ArgsCLI trimming/filteringmakeTaskForMesosResourcescmd.Arguments handlingscheduler.go:1437
newTaskForKubernetesnewTaskForMesosOffermanager.go:169
deployKubernetesTasks — overall flowacquireTasks — Mesos deployment blockmanager.go:550
configureK8sTasksBuildPropertyMap per task, global bind mapconfigureTasks — bind map building + BuildPropertyMapsmanager.go:804
transitionAndWaitK8sEnvState — send transition, block until state reachedtransitionTasks — send Mesos command, block on responsemanager.go:901
killK8sTaskdoKillTaskmanager.go:1238
killK8sEnvironmentreleaseTasksmanager.go:733
process — route watch event to roster task (called from watchK8sTasks)updateTaskState / updateTaskStatusmanager.go:1071
watchK8sTasks — retry loop on watcher failureMesos subscribe retry loopscheduler.go
nodeNameFromDescriptor — scan constraints for machine_idMesos offer attribute matching / Satisfy(targetConstraints)scheduler.go:743
k8sEnvRegistry, createK8sEnvironmentCRD, waitForK8sEnvState, cmdEnvToK8sEnvVars(no direct Mesos equivalent)

It contains multiple changes:

  • upgrading deps after rebasing on master
  • new controlmodes to distinguish between Kubernetes and Mesos tasks
  • k8s manager which translates existing mesos infrastructure to kubernetes (creation, updating, transitioning ,...)
  • small change for environment CRDs
  • control-workflow manifests for readout, stfbuilder-senderoutput and stfsender
  • simple documentation

@justonedev1justonedev1 changed the title [Octrl 1091] Integrate k8s client into ECS core[OCTRL 1091] Integrate k8s client into ECS coreJul 9, 2026
@justonedev1justonedev1 changed the title [OCTRL 1091] Integrate k8s client into ECS core[OCTRL-1091] Integrate k8s client into ECS coreJul 9, 2026
@justonedev1
justonedev1 marked this pull request as ready for review July 9, 2026 15:13

@knopers8knopers8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, i have comments mostly to naming, while the logic and approach seems OK for me.

task/manager.go becomes less clean due to placing kubernetes stuff there, but I wouldn't worry too much with creating a common abstraction for k8s + mesos, since this code is subject to further rewriting or starting it from scratch without mesos in the first place.

Comment threadcore/task/manager.go Outdated
taskman.ackKilledTasks = safeacks.NewAcks()
taskman.k8sEnvs = newK8sEnvRegistry()
if k8sClient, k8sErr := newK8sClientFromViper(); k8sErr != nil {
log.WithError(k8sErr).Warn("K8s client init failed, K8s tasks disabled")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps warn/devel for the time being, so no one panics when using AliECS in a "classic" setup?

Comment threaddocs/kubernetes_ecs.md Outdated
3. Inside the cluster, the **task-manager** and **environment-manager** operators (see `control-operator/cmd/`) watch these CRDs and reconcile the desired state — scheduling Pods, driving OCC gRPC state transitions, and writing status back into the CRD.
4. ECS watches the CRDs via the Kubernetes Watch API and reacts to status changes exactly as it would to Mesos task updates, keeping the rest of the ECS state machine intact.

This design lets ECS reuse its existing environment lifecycle, configuration generation, and monitoring logic while outsourcing Pod scheduling and OCC communication to the in-cluster operators. The relevant code can be found in manager.go and managerk8s.go.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to be more specific, as there is task/manager.go and environment/manager.go

Comment threadcore/task/manager.go Outdated
// Split K8s descriptors out before the Mesos retry loop.
var k8sDescriptors Descriptors
{
mesos := make(Descriptors, 0, len(tasksToRun))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mesos:=make(Descriptors, 0, len(tasksToRun))
mesosDescriptors:=make(Descriptors, 0, len(tasksToRun))

m.roster.append(e.task)
}

envCRDName, err := m.createK8sEnvironmentCRD(ctx, envId, nodeToRefs)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be mistaken, but isn't it a custom object that we are creating, not Custom Resource Definition? My understanding is that a CRD defines what fields our custom objects should have at the new custom resource/endpoint.

Suggested change
envCRDName, err:=m.createK8sEnvironmentCRD(ctx, envId, nodeToRefs)
envCRDName, err:=m.createK8sEnvironmentObject(ctx, envId, nodeToRefs)

So if I am right, any occurence of "CRD" should be replaced here with "Object" or removed.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no this is actual CRD that we are creating and filling in

log.WithField("partition", envCRDName).
WithField("crd", envCRDName).Debug("received some environment update")
if env.Name == envCRDName {
log.WithField("crd", envCRDName).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.WithField("crd", envCRDName).
log.WithField("crd", envCRDName).
WithField("partition", envCRDName).

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@justonedev1@knopers8