mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
Send pod spec warnings when creating or changing workload objects
This commit is contained in:
parent
ecdecafdc8
commit
f669796dfd
@ -168,7 +168,8 @@ func (daemonSetStrategy) Validate(ctx context.Context, obj runtime.Object) field
|
|||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (daemonSetStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
func (daemonSetStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
return nil
|
newDaemonSet := obj.(*apps.DaemonSet)
|
||||||
|
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newDaemonSet.Spec.Template, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
@ -210,7 +211,13 @@ func (daemonSetStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Ob
|
|||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (daemonSetStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
func (daemonSetStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
return nil
|
var warnings []string
|
||||||
|
newDaemonSet := obj.(*apps.DaemonSet)
|
||||||
|
oldDaemonSet := old.(*apps.DaemonSet)
|
||||||
|
if newDaemonSet.Spec.TemplateGeneration != oldDaemonSet.Spec.TemplateGeneration {
|
||||||
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newDaemonSet.Spec.Template, &oldDaemonSet.Spec.Template)
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllowUnconditionalUpdate is the default update policy for daemon set objects.
|
// AllowUnconditionalUpdate is the default update policy for daemon set objects.
|
||||||
|
@ -98,7 +98,8 @@ func (deploymentStrategy) Validate(ctx context.Context, obj runtime.Object) fiel
|
|||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (deploymentStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
func (deploymentStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
return nil
|
newDeployment := obj.(*apps.Deployment)
|
||||||
|
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newDeployment.Spec.Template, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
@ -156,7 +157,13 @@ func (deploymentStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.O
|
|||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (deploymentStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
func (deploymentStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
return nil
|
var warnings []string
|
||||||
|
newDeployment := obj.(*apps.Deployment)
|
||||||
|
oldDeployment := old.(*apps.Deployment)
|
||||||
|
if newDeployment.Generation != oldDeployment.Generation {
|
||||||
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newDeployment.Spec.Template, &oldDeployment.Spec.Template)
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (deploymentStrategy) AllowUnconditionalUpdate() bool {
|
func (deploymentStrategy) AllowUnconditionalUpdate() bool {
|
||||||
|
@ -126,7 +126,10 @@ func (rsStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (rsStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
|
func (rsStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
|
newRS := obj.(*apps.ReplicaSet)
|
||||||
|
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newRS.Spec.Template, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
func (rsStrategy) Canonicalize(obj runtime.Object) {
|
func (rsStrategy) Canonicalize(obj runtime.Object) {
|
||||||
@ -166,7 +169,15 @@ func (rsStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) f
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (rsStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { return nil }
|
func (rsStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
|
var warnings []string
|
||||||
|
newReplicaSet := obj.(*apps.ReplicaSet)
|
||||||
|
oldReplicaSet := old.(*apps.ReplicaSet)
|
||||||
|
if newReplicaSet.Generation != oldReplicaSet.Generation {
|
||||||
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newReplicaSet.Spec.Template, &oldReplicaSet.Spec.Template)
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
|
}
|
||||||
|
|
||||||
func (rsStrategy) AllowUnconditionalUpdate() bool {
|
func (rsStrategy) AllowUnconditionalUpdate() bool {
|
||||||
return true
|
return true
|
||||||
|
@ -115,7 +115,8 @@ func (statefulSetStrategy) Validate(ctx context.Context, obj runtime.Object) fie
|
|||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (statefulSetStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
func (statefulSetStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
return nil
|
newStatefulSet := obj.(*apps.StatefulSet)
|
||||||
|
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newStatefulSet.Spec.Template, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
@ -140,7 +141,13 @@ func (statefulSetStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.
|
|||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (statefulSetStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
func (statefulSetStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
return nil
|
var warnings []string
|
||||||
|
newStatefulSet := obj.(*apps.StatefulSet)
|
||||||
|
oldStatefulSet := old.(*apps.StatefulSet)
|
||||||
|
if newStatefulSet.Generation != oldStatefulSet.Generation {
|
||||||
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newStatefulSet.Spec.Template, &oldStatefulSet.Spec.Template)
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllowUnconditionalUpdate is the default update policy for StatefulSet objects.
|
// AllowUnconditionalUpdate is the default update policy for StatefulSet objects.
|
||||||
|
@ -112,7 +112,10 @@ func (cronJobStrategy) Validate(ctx context.Context, obj runtime.Object) field.E
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (cronJobStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
|
func (cronJobStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
|
newCronJob := obj.(*batch.CronJob)
|
||||||
|
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "jobTemplate", "spec", "template"), &newCronJob.Spec.JobTemplate.Spec.Template, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
func (cronJobStrategy) Canonicalize(obj runtime.Object) {
|
func (cronJobStrategy) Canonicalize(obj runtime.Object) {
|
||||||
@ -138,7 +141,13 @@ func (cronJobStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Obje
|
|||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (cronJobStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
func (cronJobStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
return nil
|
var warnings []string
|
||||||
|
newCronJob := obj.(*batch.CronJob)
|
||||||
|
oldCronJob := old.(*batch.CronJob)
|
||||||
|
if newCronJob.Generation != oldCronJob.Generation {
|
||||||
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "jobTemplate", "spec", "template"), &newCronJob.Spec.JobTemplate.Spec.Template, &oldCronJob.Spec.JobTemplate.Spec.Template)
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
type cronJobStatusStrategy struct {
|
type cronJobStatusStrategy struct {
|
||||||
|
@ -152,7 +152,10 @@ func (jobStrategy) Validate(ctx context.Context, obj runtime.Object) field.Error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (jobStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
|
func (jobStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
|
newJob := obj.(*batch.Job)
|
||||||
|
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newJob.Spec.Template, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// generateSelector adds a selector to a job and labels to its template
|
// generateSelector adds a selector to a job and labels to its template
|
||||||
// which can be used to uniquely identify the pods created by that job,
|
// which can be used to uniquely identify the pods created by that job,
|
||||||
@ -230,7 +233,13 @@ func (jobStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object)
|
|||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (jobStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
func (jobStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
return nil
|
var warnings []string
|
||||||
|
newJob := obj.(*batch.Job)
|
||||||
|
oldJob := old.(*batch.Job)
|
||||||
|
if newJob.Generation != oldJob.Generation {
|
||||||
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), &newJob.Spec.Template, &oldJob.Spec.Template)
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
type jobStatusStrategy struct {
|
type jobStatusStrategy struct {
|
||||||
|
@ -108,7 +108,9 @@ func (podStrategy) Validate(ctx context.Context, obj runtime.Object) field.Error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (podStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
|
func (podStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
|
return podutil.GetWarningsForPod(ctx, obj.(*api.Pod), nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
func (podStrategy) Canonicalize(obj runtime.Object) {
|
func (podStrategy) Canonicalize(obj runtime.Object) {
|
||||||
@ -130,6 +132,8 @@ func (podStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object)
|
|||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (podStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
func (podStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
|
// skip warnings on pod update, since humans don't typically interact directly with pods,
|
||||||
|
// and we don't want to pay the evaluation cost on what might be a high-frequency update path
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,8 @@ func (podTemplateStrategy) Validate(ctx context.Context, obj runtime.Object) fie
|
|||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (podTemplateStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
func (podTemplateStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
return nil
|
newPodTemplate := obj.(*api.PodTemplate)
|
||||||
|
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("template"), &newPodTemplate.Template, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
@ -99,7 +100,13 @@ func (podTemplateStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.
|
|||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (podTemplateStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
func (podTemplateStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
return nil
|
var warnings []string
|
||||||
|
newTemplate := obj.(*api.PodTemplate)
|
||||||
|
oldTemplate := old.(*api.PodTemplate)
|
||||||
|
if newTemplate.Generation != oldTemplate.Generation {
|
||||||
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("template"), &newTemplate.Template, &oldTemplate.Template)
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (podTemplateStrategy) AllowUnconditionalUpdate() bool {
|
func (podTemplateStrategy) AllowUnconditionalUpdate() bool {
|
||||||
|
@ -126,7 +126,10 @@ func (rcStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (rcStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
|
func (rcStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
|
newRC := obj.(*api.ReplicationController)
|
||||||
|
return pod.GetWarningsForPodTemplate(ctx, field.NewPath("template"), newRC.Spec.Template, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
func (rcStrategy) Canonicalize(obj runtime.Object) {
|
func (rcStrategy) Canonicalize(obj runtime.Object) {
|
||||||
@ -170,7 +173,13 @@ func (rcStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) f
|
|||||||
|
|
||||||
// WarningsOnUpdate returns warnings for the given update.
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
func (rcStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
func (rcStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
return nil
|
var warnings []string
|
||||||
|
oldRc := old.(*api.ReplicationController)
|
||||||
|
newRc := obj.(*api.ReplicationController)
|
||||||
|
if oldRc.Generation != newRc.Generation {
|
||||||
|
warnings = pod.GetWarningsForPodTemplate(ctx, field.NewPath("spec", "template"), oldRc.Spec.Template, newRc.Spec.Template)
|
||||||
|
}
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rcStrategy) AllowUnconditionalUpdate() bool {
|
func (rcStrategy) AllowUnconditionalUpdate() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user