-
Notifications
You must be signed in to change notification settings - Fork 946
fix(operator): Scope MPI ConfigMap and Secret watches to owned objects #3377
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ import ( | |
|
|
||
| "golang.org/x/crypto/ssh" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| apiruntime "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/util/validation/field" | ||
| corev1ac "k8s.io/client-go/applyconfigurations/core/v1" | ||
|
|
@@ -38,6 +39,7 @@ import ( | |
| "sigs.k8s.io/controller-runtime/pkg/cache" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/handler" | ||
| "sigs.k8s.io/controller-runtime/pkg/predicate" | ||
| "sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
|
|
||
| configapi "github.com/kubeflow/trainer/v2/pkg/apis/config/v1alpha1" | ||
|
|
@@ -218,19 +220,27 @@ func (m *MPI) EnforceMLPolicy(info *runtime.Info, trainJob *trainer.TrainJob) er | |
| func (m *MPI) ReconcilerBuilders() []runtime.ReconcilerBuilder { | ||
| return []runtime.ReconcilerBuilder{ | ||
| func(b *builder.Builder, cl client.Client, cache cache.Cache) *builder.Builder { | ||
| return b.Watches( | ||
| return b.WatchesMetadata( | ||
| &corev1.ConfigMap{}, | ||
| handler.EnqueueRequestForOwner( | ||
| m.client.Scheme(), m.client.RESTMapper(), &trainer.TrainJob{}, handler.OnlyControllerOwner(), | ||
| ), | ||
| builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool { | ||
| _, ok := obj.GetLabels()[constants.LabelJobName] | ||
| return ok | ||
| })), | ||
| ) | ||
|
Comment on lines
+223
to
232
|
||
| }, | ||
| func(b *builder.Builder, cl client.Client, cache cache.Cache) *builder.Builder { | ||
| return b.Watches( | ||
| return b.WatchesMetadata( | ||
| &corev1.Secret{}, | ||
| handler.EnqueueRequestForOwner( | ||
| m.client.Scheme(), m.client.RESTMapper(), &trainer.TrainJob{}, handler.OnlyControllerOwner(), | ||
| ), | ||
| builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool { | ||
| _, ok := obj.GetLabels()[constants.LabelJobName] | ||
| return ok | ||
| })), | ||
| ) | ||
| }, | ||
| } | ||
|
|
@@ -244,7 +254,9 @@ func (m *MPI) Build(ctx context.Context, info *runtime.Info, trainJob *trainer.T | |
| var objects []apiruntime.ApplyConfiguration | ||
|
|
||
| // SSHAuthSecret is immutable. | ||
| if err := m.client.Get(ctx, client.ObjectKey{Name: sshAuthSecretName(trainJob.Name), Namespace: trainJob.Namespace}, &corev1.Secret{}); err != nil { | ||
| partialSecret := &metav1.PartialObjectMetadata{} | ||
| partialSecret.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Secret")) | ||
| if err := m.client.Get(ctx, client.ObjectKey{Name: sshAuthSecretName(trainJob.Name), Namespace: trainJob.Namespace}, partialSecret); err != nil { | ||
| if client.IgnoreNotFound(err) != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -275,6 +287,9 @@ func (m *MPI) buildSSHAuthSecret(trainJob *trainer.TrainJob) (*corev1ac.SecretAp | |
| return nil, err | ||
| } | ||
| return corev1ac.Secret(sshAuthSecretName(trainJob.Name), trainJob.Namespace). | ||
| WithLabels(map[string]string{ | ||
| constants.LabelJobName: trainJob.Name, | ||
| }). | ||
| WithType(corev1.SecretTypeSSHAuth). | ||
| WithData(map[string][]byte{ | ||
| corev1.SSHAuthPrivateKey: privatePEM, | ||
|
|
@@ -310,6 +325,9 @@ func (m *MPI) buildHostFileConfigMap(info *runtime.Info, trainJob *trainer.Train | |
| } | ||
| } | ||
| return corev1ac.ConfigMap(fmt.Sprintf("%s%s", trainJob.Name, constants.MPIHostfileConfigMapSuffix), trainJob.Namespace). | ||
| WithLabels(map[string]string{ | ||
| constants.LabelJobName: trainJob.Name, | ||
| }). | ||
| WithData(map[string]string{ | ||
| constants.MPIHostfileName: hostFile.String(), | ||
| }). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new label-based predicate will drop events for existing MPI-owned Secrets/ConfigMaps created before this change (they have owner refs but won’t have the new label), so deletions/updates of those objects may no longer trigger TrainJob reconciliation after an upgrade.