diff --git a/pkg/registry/apps/daemonset/strategy.go b/pkg/registry/apps/daemonset/strategy.go index c8c5da40542..edcdd0423dc 100644 --- a/pkg/registry/apps/daemonset/strategy.go +++ b/pkg/registry/apps/daemonset/strategy.go @@ -168,7 +168,8 @@ func (daemonSetStrategy) Validate(ctx context.Context, obj runtime.Object) field // WarningsOnCreate returns warnings for the creation of the given object. 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. @@ -210,7 +211,13 @@ func (daemonSetStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Ob // WarningsOnUpdate returns warnings for the given update. 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. diff --git a/pkg/registry/apps/deployment/strategy.go b/pkg/registry/apps/deployment/strategy.go index 98fb66196c9..43ca93f7d8e 100644 --- a/pkg/registry/apps/deployment/strategy.go +++ b/pkg/registry/apps/deployment/strategy.go @@ -98,7 +98,8 @@ func (deploymentStrategy) Validate(ctx context.Context, obj runtime.Object) fiel // WarningsOnCreate returns warnings for the creation of the given object. 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. @@ -156,7 +157,13 @@ func (deploymentStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.O // WarningsOnUpdate returns warnings for the given update. 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 { diff --git a/pkg/registry/apps/replicaset/strategy.go b/pkg/registry/apps/replicaset/strategy.go index 3c3574a60a0..c8729d63cac 100644 --- a/pkg/registry/apps/replicaset/strategy.go +++ b/pkg/registry/apps/replicaset/strategy.go @@ -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. -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. 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. -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 { return true diff --git a/pkg/registry/apps/statefulset/strategy.go b/pkg/registry/apps/statefulset/strategy.go index ed9e2fbfb81..c122b3b30e2 100644 --- a/pkg/registry/apps/statefulset/strategy.go +++ b/pkg/registry/apps/statefulset/strategy.go @@ -115,7 +115,8 @@ func (statefulSetStrategy) Validate(ctx context.Context, obj runtime.Object) fie // WarningsOnCreate returns warnings for the creation of the given object. 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. @@ -140,7 +141,13 @@ func (statefulSetStrategy) ValidateUpdate(ctx context.Context, obj, old runtime. // WarningsOnUpdate returns warnings for the given update. 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. diff --git a/pkg/registry/batch/cronjob/strategy.go b/pkg/registry/batch/cronjob/strategy.go index cda5f13d678..ce77a9ae557 100644 --- a/pkg/registry/batch/cronjob/strategy.go +++ b/pkg/registry/batch/cronjob/strategy.go @@ -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. -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. 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. 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 { diff --git a/pkg/registry/batch/job/strategy.go b/pkg/registry/batch/job/strategy.go index 8942262b0bd..ead85e8ffd1 100644 --- a/pkg/registry/batch/job/strategy.go +++ b/pkg/registry/batch/job/strategy.go @@ -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. -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 // 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. 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 { diff --git a/pkg/registry/core/pod/strategy.go b/pkg/registry/core/pod/strategy.go index 53b9c37189e..89f07712394 100644 --- a/pkg/registry/core/pod/strategy.go +++ b/pkg/registry/core/pod/strategy.go @@ -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. -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. 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. 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 } diff --git a/pkg/registry/core/podtemplate/strategy.go b/pkg/registry/core/podtemplate/strategy.go index fd077a66303..24cdb6438a9 100644 --- a/pkg/registry/core/podtemplate/strategy.go +++ b/pkg/registry/core/podtemplate/strategy.go @@ -60,7 +60,8 @@ func (podTemplateStrategy) Validate(ctx context.Context, obj runtime.Object) fie // WarningsOnCreate returns warnings for the creation of the given object. 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. @@ -99,7 +100,13 @@ func (podTemplateStrategy) ValidateUpdate(ctx context.Context, obj, old runtime. // WarningsOnUpdate returns warnings for the given update. 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 { diff --git a/pkg/registry/core/replicationcontroller/strategy.go b/pkg/registry/core/replicationcontroller/strategy.go index 74dfb0c7e09..be056a32cfe 100644 --- a/pkg/registry/core/replicationcontroller/strategy.go +++ b/pkg/registry/core/replicationcontroller/strategy.go @@ -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. -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. 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. 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 {