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

RFC: Handle affinity assistant deadlock for node maintenance #6584

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/reconciler/customrun"
"github.com/tektoncd/pipeline/pkg/reconciler/node"
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun"
"github.com/tektoncd/pipeline/pkg/reconciler/resolutionrequest"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun"
Expand Down Expand Up @@ -132,6 +133,7 @@ func main() {
pipelinerun.NewController(opts, clock.RealClock{}, tpPipelineRun),
resolutionrequest.NewController(clock.RealClock{}),
customrun.NewController(),
node.NewController(),
)

// Cleanly shutdown and flush telemetry when the application exits.
Expand Down
3 changes: 3 additions & 0 deletions config/200-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ rules:
# Controller needs to watch Pods created by TaskRuns to see them progress.
resources: ["pods"]
verbs: ["list", "watch"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["list", "watch"]
# Controller needs cluster access to all of the CRDs that it is responsible for
# managing.
- apiGroups: ["tekton.dev"]
Expand Down
41 changes: 41 additions & 0 deletions pkg/reconciler/node/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package node

import (
"context"

"github.com/tektoncd/pipeline/pkg/apis/config"

"github.com/tektoncd/pipeline/pkg/pipelinerunmetrics"
kubeclient "knative.dev/pkg/client/injection/kube/client"
nodeinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/node"
nodereconciler "knative.dev/pkg/client/injection/kube/reconciler/core/v1/node"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/logging"
)

// NewController instantiates a new controller.Impl from knative.dev/pkg/controller
func NewController() func(context.Context, configmap.Watcher) *controller.Impl {
return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
logger := logging.FromContext(ctx)
kubeclientset := kubeclient.Get(ctx)
nodeInformer := nodeinformer.Get(ctx)
configStore := config.NewStore(logger.Named("config-store"), pipelinerunmetrics.MetricsOnStore(logger))
configStore.WatchConfigs(cmw)

c := &Reconciler{
KubeClientSet: kubeclientset,
}

impl := nodereconciler.NewImpl(ctx, c, func(impl *controller.Impl) controller.Options {
return controller.Options{
AgentName: "pod",
SkipStatusUpdates: true,
ConfigStore: configStore,
}
})

nodeInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))
return impl
}
}
53 changes: 53 additions & 0 deletions pkg/reconciler/node/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package node

import (
"context"
"fmt"

"github.com/tektoncd/pipeline/pkg/workspace"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
nodereconciler "knative.dev/pkg/client/injection/kube/reconciler/core/v1/node"
"knative.dev/pkg/logging"
pkgreconciler "knative.dev/pkg/reconciler"
)

// Reconciler implements controller.Reconciler for Configuration resources.
type Reconciler struct {
KubeClientSet kubernetes.Interface
}

// Check that our Reconciler implements noderunreconciler.Interface
var (
_ nodereconciler.Interface = (*Reconciler)(nil)
)

// ReconcileKind deletes any affinity assistant pods on unschedulable nodes
func (c *Reconciler) ReconcileKind(ctx context.Context, n *corev1.Node) pkgreconciler.Event {
if !n.Spec.Unschedulable {
return nil
}
logger := logging.FromContext(ctx)
logger.Debugf("found unschedulable node %s", n.Name)

// Find all affinity assistant pods on the node
pods, err := c.KubeClientSet.CoreV1().Pods("").List(ctx, metav1.ListOptions{
LabelSelector: workspace.LabelComponent + "=" + workspace.ComponentNameAffinityAssistant,
FieldSelector: "spec.nodeName=" + n.Name,
})
if err != nil {
return fmt.Errorf("couldn't list affinity assistant pods on node %s: %s", n.Name, err)
}

// Delete affinity assistant pods, allowing their statefulset controllers to recreate them.
lbernick marked this conversation as resolved.
Show resolved Hide resolved
// Pods are deleted individually since API server rejects DeleteCollection
for _, pod := range pods.Items {
err = c.KubeClientSet.CoreV1().Pods(pod.Namespace).Delete(ctx, pod.Name, metav1.DeleteOptions{})
if err != nil {
return fmt.Errorf("error deleting affinity assistant pod %s in ns %s: %s", pod.Name, pod.Namespace, err)
}
}

return nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading