Closed gnuletik closed 2 months ago
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle stale
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle rotten
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/reopen
/remove-lifecycle rotten
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
It is a bit sad, that there was no single reply to that issue. I don't face the issue at the moment, but I have concerns to run into that sooner or later.
@gnuletik did you find an answer somewhere else?
@guettli When using ExtractPod
(or similar functions), I manually set the UID
with the following function:
podApply := podApply.WithUID(pod.UID)
I also stopped using ExtractPod
functions (and similar) when I can, and instead I "rebuild" the apply specifications.
@gnuletik just out of curiosity, how do you "rebuild" the apply spec?
I do it like that. But I am unsure if this is good, today is the first time that I use SSA from Go.
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: containerRegistrySecretName,
Namespace: mgtSystemNamespace,
},
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Secret",
},
Type: corev1.SecretTypeDockerConfigJson,
Data: map[string][]byte{
".dockerconfigjson": alm.secret.Data[".dockerconfigjson"],
},
}
data, err := json.Marshal(secret)
if err != nil {
return fmt.Errorf("failed to marshal secret: %w", err)
}
_, err = clientSet.CoreV1().Secrets(secret.Namespace).Patch(
ctx,
secret.Name,
types.ApplyPatchType,
data,
metav1.PatchOptions{
FieldManager: fieldManagerName,
},
)
if err != nil {
return fmt.Errorf("failed to apply secret: %w", err)
}
@guettli your code sample is not using Server Side Apply.
You need to use apply configuration API: https://pkg.go.dev/k8s.io/client-go@v0.31.2/applyconfigurations/core/v1#SecretApplyConfiguration
e.g.
import (
coreac "k8s.io/client-go/applyconfigurations/core/v1"
core "k8s.io/api/core/v1"
)
secret := coreac.Secret().WithType(core.SecretTypeDockerConfigJson).WithName(containerRegistrySecretName).WithNamespace(mgtSystemNamespace)
// etc...
TLDR
When using server side apply with ExtractPod, a controller may recreate a resource that was deleted by attempting to remove a finalizer.
Context
I have a controller that watches pods to remove finalizer using Server-Side Apply (to avoid race condition between controllers as suggested here).
It removes the finalizer in the following way:
The
SharedInformer
sometimes sends the event multiple times, which leads to pod being recreated after deletion, given this scenario:Fix
Kubernetes specs specify that:
See KEPS
We can manually call
podApply := podApply.WithUID(pod.UID)
to workaround this.However, I think that it would be better that
ExtractPod
(and similar method for other resources) sets the UID before returning it.https://github.com/kubernetes/client-go/blob/aa7909e7d7c0661792ba21b9e882f3cd6ad0ce53/applyconfigurations/core/v1/pod.go#L72-L84
WDYT?
I can make a PR if that sounds good to you. However, this part of the codebase seems to be generated, so I'd need a hint on where to edit that.
Thanks!