From 5b1179f4f93b10ed89ce97b043358ceaa578ea5d Mon Sep 17 00:00:00 2001 From: EraKin575 Date: Mon, 17 Jun 2024 07:58:18 +0530 Subject: [PATCH 1/2] rename container to main container Signed-off-by: EraKin575 --- DEVELOPMENT.md | 2 +- pkg/apis/config/defaults.go | 20 ++++----- pkg/apis/config/defaults_test.go | 14 +++---- pkg/apis/config/zz_generated.deepcopy.go | 4 +- pkg/apis/serving/k8s_validation.go | 26 ++++++------ pkg/apis/serving/k8s_validation_test.go | 6 +-- .../serving/v1/configuration_defaults_test.go | 6 +-- pkg/apis/serving/v1/revision_defaults.go | 8 ++-- pkg/apis/serving/v1/revision_defaults_test.go | 38 ++++++++--------- pkg/apis/serving/v1/service_defaults_test.go | 8 ++-- pkg/reconciler/revision/resources/deploy.go | 6 +-- pkg/reconciler/revision/resources/queue.go | 42 +++++++++---------- pkg/webhook/podspec_dryrun.go | 2 +- 13 files changed, 91 insertions(+), 91 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index dd4f13347239..c815b68aabd6 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -1,4 +1,4 @@ -# Development + # Development This doc explains how to set up a development environment so you can get started [contributing](https://www.knative.dev/contributing/) to `Knative Serving`. Also diff --git a/pkg/apis/config/defaults.go b/pkg/apis/config/defaults.go index df45e8ee0b8c..0185c62d72b0 100644 --- a/pkg/apis/config/defaults.go +++ b/pkg/apis/config/defaults.go @@ -56,9 +56,9 @@ const ( // specified by the user, if `name:` is omitted. DefaultInitContainerName = "init-container" - // DefaultUserContainerName is the default name we give to the container + // DefaultMainContainerName is the default name we give to the container // specified by the user, if `name:` is omitted. - DefaultUserContainerName = "user-container" + DefaultMainContainerName = "user-container" // DefaultContainerConcurrency is the default container concurrency. It will be set if ContainerConcurrency is not specified. DefaultContainerConcurrency = 0 @@ -74,7 +74,7 @@ const ( var ( DefaultInitContainerNameTemplate = mustParseTemplate(DefaultInitContainerName) - DefaultUserContainerNameTemplate = mustParseTemplate(DefaultUserContainerName) + DefaultMainContainerNameTemplate = mustParseTemplate(DefaultMainContainerName) ) func defaultDefaultsConfig() *Defaults { @@ -84,7 +84,7 @@ func defaultDefaultsConfig() *Defaults { RevisionResponseStartTimeoutSeconds: DefaultRevisionResponseStartTimeoutSeconds, RevisionIdleTimeoutSeconds: DefaultRevisionIdleTimeoutSeconds, InitContainerNameTemplate: DefaultInitContainerNameTemplate, - UserContainerNameTemplate: DefaultUserContainerNameTemplate, + MainContainerNameTemplate: DefaultMainContainerNameTemplate, ContainerConcurrency: DefaultContainerConcurrency, ContainerConcurrencyMaxLimit: DefaultMaxRevisionContainerConcurrency, AllowContainerConcurrencyZero: DefaultAllowContainerConcurrencyZero, @@ -114,7 +114,7 @@ func NewDefaultsConfigFromMap(data map[string]string) (*Defaults, error) { if err := cm.Parse(data, asTemplate("init-container-name-template", &nc.InitContainerNameTemplate), - asTemplate("container-name-template", &nc.UserContainerNameTemplate), + asTemplate("container-name-template", &nc.MainContainerNameTemplate), cm.AsBool("allow-container-concurrency-zero", &nc.AllowContainerConcurrencyZero), asTriState("enable-service-links", &nc.EnableServiceLinks, nil), @@ -163,7 +163,7 @@ func NewDefaultsConfigFromMap(data map[string]string) (*Defaults, error) { nc.ContainerConcurrency, 0, nc.ContainerConcurrencyMaxLimit, "container-concurrency") } // Check that the templates properly apply to ObjectMeta. - if err := nc.UserContainerNameTemplate.Execute(io.Discard, metav1.ObjectMeta{}); err != nil { + if err := nc.MainContainerNameTemplate.Execute(io.Discard, metav1.ObjectMeta{}); err != nil { return nil, fmt.Errorf("error executing template: %w", err) } if err := nc.InitContainerNameTemplate.Execute(io.Discard, metav1.ObjectMeta{}); err != nil { @@ -194,7 +194,7 @@ type Defaults struct { InitContainerNameTemplate *ObjectMetaTemplate - UserContainerNameTemplate *ObjectMetaTemplate + MainContainerNameTemplate *ObjectMetaTemplate ContainerConcurrency int64 @@ -226,9 +226,9 @@ func containerNameFromTemplate(ctx context.Context, tmpl *ObjectMetaTemplate) st return buf.String() } -// UserContainerName returns the name of the user container based on the context. -func (d Defaults) UserContainerName(ctx context.Context) string { - return containerNameFromTemplate(ctx, d.UserContainerNameTemplate) +// MainContainerName returns the name of the user container based on the context. +func (d Defaults) MainContainerName(ctx context.Context) string { + return containerNameFromTemplate(ctx, d.MainContainerNameTemplate) } // InitContainerName returns the name of the init container based on the context. diff --git a/pkg/apis/config/defaults_test.go b/pkg/apis/config/defaults_test.go index 5fb94099a86f..06fb50679f4f 100644 --- a/pkg/apis/config/defaults_test.go +++ b/pkg/apis/config/defaults_test.go @@ -79,7 +79,7 @@ func TestDefaultsConfiguration(t *testing.T) { RevisionIdleTimeoutSeconds: 123, ContainerConcurrencyMaxLimit: 1984, RevisionCPURequest: &oneTwoThree, - UserContainerNameTemplate: mustParseTemplate("{{.Name}}"), + MainContainerNameTemplate: mustParseTemplate("{{.Name}}"), InitContainerNameTemplate: mustParseTemplate("{{.Name}}"), EnableServiceLinks: ptr.Bool(true), }, @@ -103,7 +103,7 @@ func TestDefaultsConfiguration(t *testing.T) { MaxRevisionTimeoutSeconds: DefaultMaxRevisionTimeoutSeconds, RevisionResponseStartTimeoutSeconds: DefaultRevisionResponseStartTimeoutSeconds, InitContainerNameTemplate: DefaultInitContainerNameTemplate, - UserContainerNameTemplate: DefaultUserContainerNameTemplate, + MainContainerNameTemplate: DefaultMainContainerNameTemplate, ContainerConcurrencyMaxLimit: DefaultMaxRevisionContainerConcurrency, AllowContainerConcurrencyZero: true, EnableServiceLinks: ptr.Bool(false), @@ -119,7 +119,7 @@ func TestDefaultsConfiguration(t *testing.T) { MaxRevisionTimeoutSeconds: DefaultMaxRevisionTimeoutSeconds, RevisionResponseStartTimeoutSeconds: DefaultRevisionResponseStartTimeoutSeconds, InitContainerNameTemplate: DefaultInitContainerNameTemplate, - UserContainerNameTemplate: DefaultUserContainerNameTemplate, + MainContainerNameTemplate: DefaultMainContainerNameTemplate, ContainerConcurrencyMaxLimit: DefaultMaxRevisionContainerConcurrency, AllowContainerConcurrencyZero: true, EnableServiceLinks: nil, @@ -214,7 +214,7 @@ func TestDefaultsConfiguration(t *testing.T) { ContainerConcurrencyMaxLimit: DefaultMaxRevisionContainerConcurrency, AllowContainerConcurrencyZero: DefaultAllowContainerConcurrencyZero, EnableServiceLinks: ptr.Bool(false), - UserContainerNameTemplate: mustParseTemplate("{{.Name}}"), + MainContainerNameTemplate: mustParseTemplate("{{.Name}}"), InitContainerNameTemplate: mustParseTemplate("my-template"), }, data: map[string]string{ @@ -235,7 +235,7 @@ func TestDefaultsConfiguration(t *testing.T) { AllowContainerConcurrencyZero: DefaultAllowContainerConcurrencyZero, EnableServiceLinks: ptr.Bool(false), InitContainerNameTemplate: DefaultInitContainerNameTemplate, - UserContainerNameTemplate: DefaultUserContainerNameTemplate, + MainContainerNameTemplate: DefaultMainContainerNameTemplate, }, }} @@ -308,8 +308,8 @@ func TestTemplating(t *testing.T) { Namespace: "guardians", }) - if got, want := def.UserContainerName(ctx), test.want; got != want { - t.Errorf("UserContainerName() = %v, wanted %v", got, want) + if got, want := def.MainContainerName(ctx), test.want; got != want { + t.Errorf("MainContainerName() = %v, wanted %v", got, want) } if got, want := def.InitContainerName(ctx), test.want; got != want { diff --git a/pkg/apis/config/zz_generated.deepcopy.go b/pkg/apis/config/zz_generated.deepcopy.go index dfd36f32e36a..378d6dade49d 100644 --- a/pkg/apis/config/zz_generated.deepcopy.go +++ b/pkg/apis/config/zz_generated.deepcopy.go @@ -64,8 +64,8 @@ func (in *Defaults) DeepCopyInto(out *Defaults) { x := (*in).DeepCopy() *out = &x } - if in.UserContainerNameTemplate != nil { - in, out := &in.UserContainerNameTemplate, &out.UserContainerNameTemplate + if in.MainContainerNameTemplate != nil { + in, out := &in.MainContainerNameTemplate, &out.MainContainerNameTemplate x := (*in).DeepCopy() *out = &x } diff --git a/pkg/apis/serving/k8s_validation.go b/pkg/apis/serving/k8s_validation.go index 42946b80ef99..da6070a0937b 100644 --- a/pkg/apis/serving/k8s_validation.go +++ b/pkg/apis/serving/k8s_validation.go @@ -387,7 +387,7 @@ func ValidatePodSpec(ctx context.Context, ps corev1.PodSpec) *apis.FieldError { case 0: errs = errs.Also(apis.ErrMissingField("containers")) case 1: - errs = errs.Also(ValidateUserContainer(ctx, ps.Containers[0], volumes, port). + errs = errs.Also(ValidateMainContainer(ctx, ps.Containers[0], volumes, port). ViaFieldIndex("containers", 0)) default: errs = errs.Also(validateContainers(ctx, ps.Containers, volumes, port)) @@ -444,7 +444,7 @@ func validateContainers(ctx context.Context, containers []corev1.Container, volu if len(containers[i].Ports) == 0 { errs = errs.Also(validateSidecarContainer(WithinSidecarContainer(ctx), containers[i], volumes).ViaFieldIndex("containers", i)) } else { - errs = errs.Also(ValidateUserContainer(WithinUserContainer(ctx), containers[i], volumes, port).ViaFieldIndex("containers", i)) + errs = errs.Also(ValidateMainContainer(WithinMainContainer(ctx), containers[i], volumes, port).ViaFieldIndex("containers", i)) } } return errs @@ -550,8 +550,8 @@ func validateInitContainer(ctx context.Context, container corev1.Container, volu return errs.Also(validate(WithinInitContainer(ctx), container, volumes)) } -// ValidateUserContainer validate fields for serving containers -func ValidateUserContainer(ctx context.Context, container corev1.Container, volumes map[string]corev1.Volume, port corev1.ContainerPort) (errs *apis.FieldError) { +// ValidateMainContainer validate fields for serving containers +func ValidateMainContainer(ctx context.Context, container corev1.Container, volumes map[string]corev1.Volume, port corev1.ContainerPort) (errs *apis.FieldError) { // Liveness Probes errs = errs.Also(validateProbe(container.LivenessProbe, &port, true).ViaField("livenessProbe")) // Readiness Probes @@ -757,12 +757,12 @@ func validateContainerPortBasic(port corev1.ContainerPort) *apis.FieldError { return errs } -func validateReadinessProbe(p *corev1.Probe, port *corev1.ContainerPort, isUserContainer bool) *apis.FieldError { +func validateReadinessProbe(p *corev1.Probe, port *corev1.ContainerPort, isMainContainer bool) *apis.FieldError { if p == nil { return nil } - errs := validateProbe(p, port, isUserContainer) + errs := validateProbe(p, port, isMainContainer) if p.PeriodSeconds < 0 { errs = errs.Also(apis.ErrOutOfBoundsValue(p.PeriodSeconds, 0, math.MaxInt32, "periodSeconds")) @@ -804,7 +804,7 @@ func validateReadinessProbe(p *corev1.Probe, port *corev1.ContainerPort, isUserC return errs } -func validateProbe(p *corev1.Probe, port *corev1.ContainerPort, isUserContainer bool) *apis.FieldError { +func validateProbe(p *corev1.Probe, port *corev1.ContainerPort, isMainContainer bool) *apis.FieldError { if p == nil { return nil } @@ -819,7 +819,7 @@ func validateProbe(p *corev1.Probe, port *corev1.ContainerPort, isUserContainer handlers = append(handlers, "httpGet") errs = errs.Also(apis.CheckDisallowedFields(*h.HTTPGet, *HTTPGetActionMask(h.HTTPGet))).ViaField("httpGet") getPort := h.HTTPGet.Port - if isUserContainer { + if isMainContainer { if getPort.StrVal != "" && getPort.StrVal != port.Name { errs = errs.Also(apis.ErrInvalidValue(getPort.String(), "httpGet.port", "Probe port must match container port")) } @@ -833,7 +833,7 @@ func validateProbe(p *corev1.Probe, port *corev1.ContainerPort, isUserContainer handlers = append(handlers, "tcpSocket") errs = errs.Also(apis.CheckDisallowedFields(*h.TCPSocket, *TCPSocketActionMask(h.TCPSocket))).ViaField("tcpSocket") tcpPort := h.TCPSocket.Port - if isUserContainer { + if isMainContainer { if tcpPort.StrVal != "" && tcpPort.StrVal != port.Name { errs = errs.Also(apis.ErrInvalidValue(tcpPort.String(), "tcpSocket.port", "Probe port must match container port")) } @@ -983,12 +983,12 @@ func warnDefaultContainerSecurityContext(_ context.Context, psc *corev1.PodSecur // This is attached to contexts as they are passed down through a user container // being validated. -type userContainer struct{} +type mainContainer struct{} -// WithinUserContainer notes on the context that further validation or defaulting +// WithinMainContainer notes on the context that further validation or defaulting // is within the context of a user container in the revision. -func WithinUserContainer(ctx context.Context) context.Context { - return context.WithValue(ctx, userContainer{}, struct{}{}) +func WithinMainContainer(ctx context.Context) context.Context { + return context.WithValue(ctx, mainContainer{}, struct{}{}) } // This is attached to contexts as they are passed down through a sidecar container diff --git a/pkg/apis/serving/k8s_validation_test.go b/pkg/apis/serving/k8s_validation_test.go index a98132feb10f..c33f7c3acd0b 100644 --- a/pkg/apis/serving/k8s_validation_test.go +++ b/pkg/apis/serving/k8s_validation_test.go @@ -1492,7 +1492,7 @@ func TestPodSpecFieldRefValidation(t *testing.T) { } } -func TestUserContainerValidation(t *testing.T) { +func TestMainContainerValidation(t *testing.T) { tests := []containerValidationTestCase{ { name: "has a lifecycle", @@ -1961,10 +1961,10 @@ func TestUserContainerValidation(t *testing.T) { } port, err := validateContainersPorts([]corev1.Container{test.c}) - got := err.Also(ValidateUserContainer(ctx, test.c, test.volumes, port)) + got := err.Also(ValidateMainContainer(ctx, test.c, test.volumes, port)) got = got.Filter(apis.ErrorLevel) if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("ValidateUserContainer (-want, +got): \n%s", diff) + t.Errorf("ValidateMainContainer (-want, +got): \n%s", diff) } }) } diff --git a/pkg/apis/serving/v1/configuration_defaults_test.go b/pkg/apis/serving/v1/configuration_defaults_test.go index ae6e8d9058e3..64cd6c0347cd 100644 --- a/pkg/apis/serving/v1/configuration_defaults_test.go +++ b/pkg/apis/serving/v1/configuration_defaults_test.go @@ -72,7 +72,7 @@ func TestConfigurationDefaulting(t *testing.T) { Spec: RevisionSpec{ PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Image: "busybox", Resources: defaultResources, ReadinessProbe: defaultProbe, @@ -107,7 +107,7 @@ func TestConfigurationDefaulting(t *testing.T) { PodSpec: corev1.PodSpec{ EnableServiceLinks: ptr.Bool(false), Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Image: "busybox", Resources: defaultResources, ReadinessProbe: defaultProbe, @@ -144,7 +144,7 @@ func TestConfigurationDefaulting(t *testing.T) { PodSpec: corev1.PodSpec{ EnableServiceLinks: ptr.Bool(true), Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Image: "busybox", Resources: defaultResources, ReadinessProbe: defaultProbe, diff --git a/pkg/apis/serving/v1/revision_defaults.go b/pkg/apis/serving/v1/revision_defaults.go index 3c40f4f6c7c0..73157914e209 100644 --- a/pkg/apis/serving/v1/revision_defaults.go +++ b/pkg/apis/serving/v1/revision_defaults.go @@ -82,8 +82,8 @@ func (rs *RevisionSpec) SetDefaults(ctx context.Context) { for idx := range rs.PodSpec.InitContainers { containerNames.Insert(rs.PodSpec.InitContainers[idx].Name) } - defaultUserContainerName := cfg.Defaults.UserContainerName(ctx) - applyDefaultContainerNames(rs.PodSpec.Containers, containerNames, defaultUserContainerName) + defaultMainContainerName := cfg.Defaults.MainContainerName(ctx) + applyDefaultContainerNames(rs.PodSpec.Containers, containerNames, defaultMainContainerName) defaultInitContainerName := cfg.Defaults.InitContainerName(ctx) applyDefaultContainerNames(rs.PodSpec.InitContainers, containerNames, defaultInitContainerName) for idx := range rs.PodSpec.Containers { @@ -132,7 +132,7 @@ func (rs *RevisionSpec) applyDefault(ctx context.Context, container *corev1.Cont // If there are multiple containers then default probes will be applied to the container where user specified PORT // default probes will not be applied for non serving containers if len(rs.PodSpec.Containers) == 1 || len(container.Ports) != 0 { - rs.applyUserContainerDefaultReadinessProbe(container) + rs.applyMainContainerDefaultReadinessProbe(container) } rs.applyReadinessProbeDefaults(container) rs.applyGRPCProbeDefaults(container) @@ -155,7 +155,7 @@ func (rs *RevisionSpec) applyDefault(ctx context.Context, container *corev1.Cont } } -func (*RevisionSpec) applyUserContainerDefaultReadinessProbe(container *corev1.Container) { +func (*RevisionSpec) applyMainContainerDefaultReadinessProbe(container *corev1.Container) { if container.ReadinessProbe == nil { container.ReadinessProbe = &corev1.Probe{} } diff --git a/pkg/apis/serving/v1/revision_defaults_test.go b/pkg/apis/serving/v1/revision_defaults_test.go index 4d08fd3f8ccf..007540091d02 100644 --- a/pkg/apis/serving/v1/revision_defaults_test.go +++ b/pkg/apis/serving/v1/revision_defaults_test.go @@ -88,7 +88,7 @@ func TestRevisionDefaulting(t *testing.T) { TimeoutSeconds: ptr.Int64(423), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -122,7 +122,7 @@ func TestRevisionDefaulting(t *testing.T) { IdleTimeoutSeconds: ptr.Int64(100), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -154,7 +154,7 @@ func TestRevisionDefaulting(t *testing.T) { PodSpec: corev1.PodSpec{ EnableServiceLinks: ptr.Bool(false), Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -189,7 +189,7 @@ func TestRevisionDefaulting(t *testing.T) { TimeoutSeconds: ptr.Int64(300), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -220,7 +220,7 @@ func TestRevisionDefaulting(t *testing.T) { TimeoutSeconds: ptr.Int64(300), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -251,7 +251,7 @@ func TestRevisionDefaulting(t *testing.T) { TimeoutSeconds: ptr.Int64(300), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -285,7 +285,7 @@ func TestRevisionDefaulting(t *testing.T) { TimeoutSeconds: ptr.Int64(300), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -315,7 +315,7 @@ func TestRevisionDefaulting(t *testing.T) { PodSpec: corev1.PodSpec{ EnableServiceLinks: ptr.Bool(false), Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Image: "foo", VolumeMounts: []corev1.VolumeMount{{ Name: "bar", @@ -353,7 +353,7 @@ func TestRevisionDefaulting(t *testing.T) { TimeoutSeconds: ptr.Int64(456), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -423,7 +423,7 @@ func TestRevisionDefaulting(t *testing.T) { ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: &corev1.Probe{ SuccessThreshold: 1, @@ -456,7 +456,7 @@ func TestRevisionDefaulting(t *testing.T) { ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, ReadinessProbe: &corev1.Probe{ FailureThreshold: 3, // Added as k8s default ProbeHandler: defaultProbe.ProbeHandler, @@ -483,7 +483,7 @@ func TestRevisionDefaulting(t *testing.T) { ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: defaultResources, ReadinessProbe: defaultProbe, }}, @@ -523,7 +523,7 @@ func TestRevisionDefaulting(t *testing.T) { ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("100m"), @@ -1199,7 +1199,7 @@ func TestRevisionDefaulting(t *testing.T) { ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName + "-0", + Name: config.DefaultMainContainerName + "-0", Resources: defaultResources, ReadinessProbe: &corev1.Probe{ SuccessThreshold: 1, @@ -1210,7 +1210,7 @@ func TestRevisionDefaulting(t *testing.T) { }, }, }, { - Name: config.DefaultUserContainerName + "-1", + Name: config.DefaultMainContainerName + "-1", Resources: defaultResources, ReadinessProbe: &corev1.Probe{ SuccessThreshold: 1, @@ -1251,7 +1251,7 @@ func TestRevisionDefaulting(t *testing.T) { ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName + "-0", + Name: config.DefaultMainContainerName + "-0", Ports: []corev1.ContainerPort{{ ContainerPort: 8080, }}, @@ -1264,7 +1264,7 @@ func TestRevisionDefaulting(t *testing.T) { }, Resources: defaultResources, }, { - Name: config.DefaultUserContainerName + "-1", + Name: config.DefaultMainContainerName + "-1", ReadinessProbe: &corev1.Probe{ FailureThreshold: 3, // Added as k8s default PeriodSeconds: 10, @@ -1294,14 +1294,14 @@ func TestRevisionDefaulting(t *testing.T) { ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency), PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName + "-0", + Name: config.DefaultMainContainerName + "-0", Ports: []corev1.ContainerPort{{ ContainerPort: 8080, }}, Resources: defaultResources, ReadinessProbe: defaultProbe, }, { - Name: config.DefaultUserContainerName + "-1", + Name: config.DefaultMainContainerName + "-1", Resources: defaultResources, ReadinessProbe: nil, }}, diff --git a/pkg/apis/serving/v1/service_defaults_test.go b/pkg/apis/serving/v1/service_defaults_test.go index 01547042ac79..1fb8c62e2b74 100644 --- a/pkg/apis/serving/v1/service_defaults_test.go +++ b/pkg/apis/serving/v1/service_defaults_test.go @@ -83,7 +83,7 @@ func TestServiceDefaulting(t *testing.T) { PodSpec: corev1.PodSpec{ EnableServiceLinks: ptr.Bool(false), Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Image: "busybox", Resources: defaultResources, ReadinessProbe: defaultProbe, @@ -126,7 +126,7 @@ func TestServiceDefaulting(t *testing.T) { Spec: RevisionSpec{ PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Image: "busybox", Resources: defaultResources, ReadinessProbe: defaultProbe, @@ -172,7 +172,7 @@ func TestServiceDefaulting(t *testing.T) { Spec: RevisionSpec{ PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Image: "busybox", Resources: defaultResources, ReadinessProbe: defaultProbe, @@ -229,7 +229,7 @@ func TestServiceDefaulting(t *testing.T) { Spec: RevisionSpec{ PodSpec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: config.DefaultUserContainerName, + Name: config.DefaultMainContainerName, Image: "busybox", Resources: defaultResources, ReadinessProbe: defaultProbe, diff --git a/pkg/reconciler/revision/resources/deploy.go b/pkg/reconciler/revision/resources/deploy.go index d17cfe830b54..4f6308de575a 100644 --- a/pkg/reconciler/revision/resources/deploy.go +++ b/pkg/reconciler/revision/resources/deploy.go @@ -207,7 +207,7 @@ func makePodSpec(rev *v1.Revision, cfg *config.Config) (*corev1.PodSpec, error) extraVolumes = append(extraVolumes, certVolume(networking.ServingCertName)) } - podSpec := BuildPodSpec(rev, append(BuildUserContainers(rev), *queueContainer), cfg) + podSpec := BuildPodSpec(rev, append(BuildMainContainers(rev), *queueContainer), cfg) podSpec.Volumes = append(podSpec.Volumes, extraVolumes...) if cfg.Observability.EnableVarLogCollection { @@ -234,8 +234,8 @@ func makePodSpec(rev *v1.Revision, cfg *config.Config) (*corev1.PodSpec, error) return podSpec, nil } -// BuildUserContainers makes an array of containers from the Revision template. -func BuildUserContainers(rev *v1.Revision) []corev1.Container { +// BuildMainContainers makes an array of containers from the Revision template. +func BuildMainContainers(rev *v1.Revision) []corev1.Container { containers := make([]corev1.Container, 0, len(rev.Spec.PodSpec.Containers)) for i := range rev.Spec.PodSpec.Containers { var container corev1.Container diff --git a/pkg/reconciler/revision/resources/queue.go b/pkg/reconciler/revision/resources/queue.go index 0483111f6517..291cdd6cfa66 100644 --- a/pkg/reconciler/revision/resources/queue.go +++ b/pkg/reconciler/revision/resources/queue.go @@ -93,7 +93,7 @@ var ( } ) -func createQueueResources(cfg *deployment.Config, annotations map[string]string, userContainer *corev1.Container, useDefaults bool) corev1.ResourceRequirements { +func createQueueResources(cfg *deployment.Config, annotations map[string]string, mainContainer *corev1.Container, useDefaults bool) corev1.ResourceRequirements { resourceRequests := corev1.ResourceList{} resourceLimits := corev1.ResourceList{} @@ -135,19 +135,19 @@ func createQueueResources(cfg *deployment.Config, annotations map[string]string, var requestCPU, limitCPU, requestMemory, limitMemory resource.Quantity if resourceFraction, ok := fractionFromPercentage(annotations, serving.QueueSidecarResourcePercentageAnnotation); ok { - if ok, requestCPU = computeResourceRequirements(userContainer.Resources.Requests.Cpu(), resourceFraction, queueContainerRequestCPU); ok { + if ok, requestCPU = computeResourceRequirements(mainContainer.Resources.Requests.Cpu(), resourceFraction, queueContainerRequestCPU); ok { resourceRequests[corev1.ResourceCPU] = requestCPU } - if ok, limitCPU = computeResourceRequirements(userContainer.Resources.Limits.Cpu(), resourceFraction, queueContainerLimitCPU); ok { + if ok, limitCPU = computeResourceRequirements(mainContainer.Resources.Limits.Cpu(), resourceFraction, queueContainerLimitCPU); ok { resourceLimits[corev1.ResourceCPU] = limitCPU } - if ok, requestMemory = computeResourceRequirements(userContainer.Resources.Requests.Memory(), resourceFraction, queueContainerRequestMemory); ok { + if ok, requestMemory = computeResourceRequirements(mainContainer.Resources.Requests.Memory(), resourceFraction, queueContainerRequestMemory); ok { resourceRequests[corev1.ResourceMemory] = requestMemory } - if ok, limitMemory = computeResourceRequirements(userContainer.Resources.Limits.Memory(), resourceFraction, queueContainerLimitMemory); ok { + if ok, limitMemory = computeResourceRequirements(mainContainer.Resources.Limits.Memory(), resourceFraction, queueContainerLimitMemory); ok { resourceLimits[corev1.ResourceMemory] = limitMemory } } @@ -261,32 +261,32 @@ func makeQueueContainer(rev *v1.Revision, cfg *config.Config) (*corev1.Container ports = append(ports, servingPort, queueHTTPSPort) // User container (and queue-proxy) readiness probe - userContainer := rev.Spec.GetContainer() - var queueProxyReadinessProbe, userContainerReadinessProbe *corev1.Probe - if userContainer.ReadinessProbe != nil { + mainContainer := rev.Spec.GetContainer() + var queueProxyReadinessProbe, mainContainerReadinessProbe *corev1.Probe + if mainContainer.ReadinessProbe != nil { probePort := userPort - if userContainer.ReadinessProbe.HTTPGet != nil && userContainer.ReadinessProbe.HTTPGet.Port.IntValue() != 0 { - probePort = userContainer.ReadinessProbe.HTTPGet.Port.IntVal + if mainContainer.ReadinessProbe.HTTPGet != nil && mainContainer.ReadinessProbe.HTTPGet.Port.IntValue() != 0 { + probePort = mainContainer.ReadinessProbe.HTTPGet.Port.IntVal } - if userContainer.ReadinessProbe.TCPSocket != nil && userContainer.ReadinessProbe.TCPSocket.Port.IntValue() != 0 { - probePort = userContainer.ReadinessProbe.TCPSocket.Port.IntVal + if mainContainer.ReadinessProbe.TCPSocket != nil && mainContainer.ReadinessProbe.TCPSocket.Port.IntValue() != 0 { + probePort = mainContainer.ReadinessProbe.TCPSocket.Port.IntVal } - if userContainer.ReadinessProbe.GRPC != nil && userContainer.ReadinessProbe.GRPC.Port > 0 { - probePort = userContainer.ReadinessProbe.GRPC.Port + if mainContainer.ReadinessProbe.GRPC != nil && mainContainer.ReadinessProbe.GRPC.Port > 0 { + probePort = mainContainer.ReadinessProbe.GRPC.Port } // The activator attempts to detect readiness itself by checking the Queue // Proxy's health endpoint rather than waiting for Kubernetes to check and // propagate the Ready state. We encode the original readiness probes as JSON in an // environment variable for this health endpoint to use. - userContainerReadinessProbe = userContainer.ReadinessProbe.DeepCopy() - applyReadinessProbeDefaults(userContainerReadinessProbe, probePort) + mainContainerReadinessProbe = mainContainer.ReadinessProbe.DeepCopy() + applyReadinessProbeDefaults(mainContainerReadinessProbe, probePort) // After startup we'll directly use the same http health check endpoint the // execprobe would have used (which will then check the user container). // Unlike the StartupProbe, we don't need to override any of the other settings // except period here. See below. - queueProxyReadinessProbe = userContainer.ReadinessProbe.DeepCopy() + queueProxyReadinessProbe = mainContainer.ReadinessProbe.DeepCopy() queueProxyReadinessProbe.ProbeHandler = corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ Port: intstr.FromInt32(servingPort.ContainerPort), @@ -300,7 +300,7 @@ func makeQueueContainer(rev *v1.Revision, cfg *config.Config) (*corev1.Container // Sidecar readiness probes multiContainerProbingEnabled := cfg.Features.MultiContainerProbing == apicfg.Enabled - readinessProbes := []*corev1.Probe{userContainerReadinessProbe} + readinessProbes := []*corev1.Probe{mainContainerReadinessProbe} if multiContainerProbingEnabled { for _, sc := range rev.Spec.GetSidecarContainers() { if sc.ReadinessProbe != nil { @@ -331,8 +331,8 @@ func makeQueueContainer(rev *v1.Revision, cfg *config.Config) (*corev1.Container return nil, fmt.Errorf("failed to serialize multiple readiness probes: %w", err) } - } else if userContainerReadinessProbe != nil { - readinessProbeJSON, err = readiness.EncodeSingleProbe(userContainerReadinessProbe) + } else if mainContainerReadinessProbe != nil { + readinessProbeJSON, err = readiness.EncodeSingleProbe(mainContainerReadinessProbe) if err != nil { return nil, fmt.Errorf("failed to serialize single readiness probe: %w", err) } @@ -344,7 +344,7 @@ func makeQueueContainer(rev *v1.Revision, cfg *config.Config) (*corev1.Container c := &corev1.Container{ Name: QueueContainerName, Image: cfg.Deployment.QueueSidecarImage, - Resources: createQueueResources(cfg.Deployment, rev.GetAnnotations(), userContainer, useQPResourceDefaults), + Resources: createQueueResources(cfg.Deployment, rev.GetAnnotations(), mainContainer, useQPResourceDefaults), Ports: ports, StartupProbe: nil, ReadinessProbe: queueProxyReadinessProbe, diff --git a/pkg/webhook/podspec_dryrun.go b/pkg/webhook/podspec_dryrun.go index 0df8b2cfa737..b86e196dfa24 100644 --- a/pkg/webhook/podspec_dryrun.go +++ b/pkg/webhook/podspec_dryrun.go @@ -59,7 +59,7 @@ func validatePodSpec(ctx context.Context, ps v1.RevisionSpec, namespace string, Spec: ps, } rev.SetDefaults(ctx) - podSpec := resources.BuildPodSpec(rev, resources.BuildUserContainers(rev), nil /*configs*/) + podSpec := resources.BuildPodSpec(rev, resources.BuildMainContainers(rev), nil /*configs*/) // Make a sample pod with the template Revisions & PodSpec and dryrun call to API-server pod := &corev1.Pod{ From 3fec7ce7a8b954fcf674a673b8719d3d0a52bfbb Mon Sep 17 00:00:00 2001 From: EraKin575 Date: Sun, 30 Jun 2024 14:16:41 +0530 Subject: [PATCH 2/2] fixed liveness-probe-test Signed-off-by: EraKin575 --- test/conformance/runtime/liveness_probe_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/conformance/runtime/liveness_probe_test.go b/test/conformance/runtime/liveness_probe_test.go index 611b64e9b5a5..78c30028e341 100644 --- a/test/conformance/runtime/liveness_probe_test.go +++ b/test/conformance/runtime/liveness_probe_test.go @@ -173,7 +173,7 @@ func atLeastNumLivenessChecks(t *testing.T, expectedChecks int) spoof.ResponseCh func userContainerRestarted(pod *corev1.Pod) bool { for _, status := range pod.Status.ContainerStatuses { - if status.Name == config.DefaultUserContainerName && status.RestartCount > 0 { + if status.Name == config.DefaultMainContainerName && status.RestartCount > 0 { return true } }