diff --git a/pkg/reconciler/brokercell/resources/deployments.go b/pkg/reconciler/brokercell/resources/deployments.go index 547a27335f..4933114a71 100644 --- a/pkg/reconciler/brokercell/resources/deployments.go +++ b/pkg/reconciler/brokercell/resources/deployments.go @@ -26,6 +26,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "knative.dev/pkg/kmeta" + "knative.dev/pkg/ptr" "knative.dev/pkg/system" ) @@ -44,7 +45,7 @@ func MakeIngressDeployment(args IngressArgs) *appsv1.Deployment { }, }, FailureThreshold: 5, - PeriodSeconds: 2, + PeriodSeconds: 15, SuccessThreshold: 1, TimeoutSeconds: 5, } @@ -57,8 +58,8 @@ func MakeIngressDeployment(args IngressArgs) *appsv1.Deployment { }, }, FailureThreshold: 5, - InitialDelaySeconds: 5, - PeriodSeconds: 2, + InitialDelaySeconds: 15, + PeriodSeconds: 15, SuccessThreshold: 1, TimeoutSeconds: 5, } @@ -135,6 +136,13 @@ func deploymentTemplate(args Args, containers []corev1.Container) *appsv1.Deploy }, Spec: appsv1.DeploymentSpec{ Selector: &metav1.LabelSelector{MatchLabels: Labels(args.BrokerCell.Name, args.ComponentName)}, + Strategy: appsv1.DeploymentStrategy{ + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxSurge: &intstr.IntOrString{IntVal: 1}, + MaxUnavailable: &intstr.IntOrString{IntVal: 0}, + }, + }, + MinReadySeconds: 60, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: Labels(args.BrokerCell.Name, args.ComponentName), @@ -154,7 +162,8 @@ func deploymentTemplate(args Args, containers []corev1.Container) *appsv1.Deploy VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{SecretName: "google-broker-key", Optional: &optionalSecretVolume}}, }, }, - Containers: containers, + Containers: containers, + TerminationGracePeriodSeconds: ptr.Int64(60), }, }, }, diff --git a/pkg/reconciler/brokercell/testingdata/fanout_deployment.yaml b/pkg/reconciler/brokercell/testingdata/fanout_deployment.yaml index 04602477cf..d1b0b57f0a 100644 --- a/pkg/reconciler/brokercell/testingdata/fanout_deployment.yaml +++ b/pkg/reconciler/brokercell/testingdata/fanout_deployment.yaml @@ -32,6 +32,11 @@ spec: app: cloud-run-events brokerCell: test-brokercell role: fanout + minReadySeconds: 60 + strategy: + rollingUpdate: + maxUnavailable: 0 + maxSurge: 1 template: metadata: labels: *labels @@ -39,6 +44,7 @@ spec: sidecar.istio.io/inject: "false" spec: serviceAccountName: broker + terminationGracePeriodSeconds: 60 containers: - name: fanout image: fanout diff --git a/pkg/reconciler/brokercell/testingdata/fanout_deployment_with_status.yaml b/pkg/reconciler/brokercell/testingdata/fanout_deployment_with_status.yaml index 250b15bf9a..58661fef71 100644 --- a/pkg/reconciler/brokercell/testingdata/fanout_deployment_with_status.yaml +++ b/pkg/reconciler/brokercell/testingdata/fanout_deployment_with_status.yaml @@ -33,6 +33,11 @@ spec: app: cloud-run-events brokerCell: test-brokercell role: fanout + minReadySeconds: 60 + strategy: + rollingUpdate: + maxUnavailable: 0 + maxSurge: 1 template: metadata: labels: *labels @@ -40,6 +45,7 @@ spec: sidecar.istio.io/inject: "false" spec: serviceAccountName: broker + terminationGracePeriodSeconds: 60 containers: - name: fanout image: fanout diff --git a/pkg/reconciler/brokercell/testingdata/ingress_deployment.yaml b/pkg/reconciler/brokercell/testingdata/ingress_deployment.yaml index 3202ce8814..f75cab5d2c 100644 --- a/pkg/reconciler/brokercell/testingdata/ingress_deployment.yaml +++ b/pkg/reconciler/brokercell/testingdata/ingress_deployment.yaml @@ -32,6 +32,11 @@ spec: app: cloud-run-events brokerCell: test-brokercell role: ingress + minReadySeconds: 60 + strategy: + rollingUpdate: + maxUnavailable: 0 + maxSurge: 1 template: metadata: labels: *labels @@ -39,6 +44,7 @@ spec: sidecar.istio.io/inject: "true" spec: serviceAccountName: broker + terminationGracePeriodSeconds: 60 containers: - name: ingress image: ingress @@ -48,8 +54,8 @@ spec: path: /healthz port: 8080 scheme: HTTP - initialDelaySeconds: 5 - periodSeconds: 2 + initialDelaySeconds: 15 + periodSeconds: 15 successThreshold: 1 timeoutSeconds: 5 readinessProbe: @@ -58,7 +64,7 @@ spec: path: /healthz port: 8080 scheme: HTTP - periodSeconds: 2 + periodSeconds: 15 successThreshold: 1 timeoutSeconds: 5 env: diff --git a/pkg/reconciler/brokercell/testingdata/ingress_deployment_with_status.yaml b/pkg/reconciler/brokercell/testingdata/ingress_deployment_with_status.yaml index 1a6fa201f4..24741e8f1a 100644 --- a/pkg/reconciler/brokercell/testingdata/ingress_deployment_with_status.yaml +++ b/pkg/reconciler/brokercell/testingdata/ingress_deployment_with_status.yaml @@ -33,6 +33,11 @@ spec: app: cloud-run-events brokerCell: test-brokercell role: ingress + minReadySeconds: 60 + strategy: + rollingUpdate: + maxUnavailable: 0 + maxSurge: 1 template: metadata: labels: *labels @@ -40,6 +45,7 @@ spec: sidecar.istio.io/inject: "true" spec: serviceAccountName: broker + terminationGracePeriodSeconds: 60 containers: - name: ingress image: ingress @@ -49,8 +55,8 @@ spec: path: /healthz port: 8080 scheme: HTTP - initialDelaySeconds: 5 - periodSeconds: 2 + initialDelaySeconds: 15 + periodSeconds: 15 successThreshold: 1 timeoutSeconds: 5 readinessProbe: @@ -59,7 +65,7 @@ spec: path: /healthz port: 8080 scheme: HTTP - periodSeconds: 2 + periodSeconds: 15 successThreshold: 1 timeoutSeconds: 5 env: diff --git a/pkg/reconciler/brokercell/testingdata/retry_deployment.yaml b/pkg/reconciler/brokercell/testingdata/retry_deployment.yaml index ca70471805..4456e007d8 100644 --- a/pkg/reconciler/brokercell/testingdata/retry_deployment.yaml +++ b/pkg/reconciler/brokercell/testingdata/retry_deployment.yaml @@ -32,6 +32,11 @@ spec: app: cloud-run-events brokerCell: test-brokercell role: retry + minReadySeconds: 60 + strategy: + rollingUpdate: + maxUnavailable: 0 + maxSurge: 1 template: metadata: labels: *labels @@ -39,6 +44,7 @@ spec: sidecar.istio.io/inject: "false" spec: serviceAccountName: broker + terminationGracePeriodSeconds: 60 containers: - name: retry image: retry diff --git a/pkg/reconciler/brokercell/testingdata/retry_deployment_with_status.yaml b/pkg/reconciler/brokercell/testingdata/retry_deployment_with_status.yaml index 586a0d2e1e..0467979a01 100644 --- a/pkg/reconciler/brokercell/testingdata/retry_deployment_with_status.yaml +++ b/pkg/reconciler/brokercell/testingdata/retry_deployment_with_status.yaml @@ -33,6 +33,11 @@ spec: app: cloud-run-events brokerCell: test-brokercell role: retry + minReadySeconds: 60 + strategy: + rollingUpdate: + maxUnavailable: 0 + maxSurge: 1 template: metadata: labels: *labels @@ -40,6 +45,7 @@ spec: sidecar.istio.io/inject: "false" spec: serviceAccountName: broker + terminationGracePeriodSeconds: 60 containers: - name: retry image: retry diff --git a/pkg/reconciler/utils/deployment.go b/pkg/reconciler/utils/deployment.go index 1f1d8c8935..92adf9c806 100644 --- a/pkg/reconciler/utils/deployment.go +++ b/pkg/reconciler/utils/deployment.go @@ -25,6 +25,7 @@ import ( "k8s.io/client-go/kubernetes" appsv1listers "k8s.io/client-go/listers/apps/v1" "k8s.io/client-go/tools/record" + "knative.dev/pkg/ptr" ) const ( @@ -54,6 +55,10 @@ func (r *DeploymentReconciler) ReconcileDeployment(obj runtime.Object, d *appsv1 if err != nil { return nil, err } + // Don't reconcile on replica difference. + if current.Spec.Replicas != nil { + d.Spec.Replicas = ptr.Int32(*current.Spec.Replicas) + } if !equality.Semantic.DeepDerivative(d.Spec, current.Spec) { // Don't modify the informers copy. desired := current.DeepCopy() diff --git a/pkg/reconciler/utils/deployment_test.go b/pkg/reconciler/utils/deployment_test.go index 7556e2d9db..00e45807b8 100644 --- a/pkg/reconciler/utils/deployment_test.go +++ b/pkg/reconciler/utils/deployment_test.go @@ -24,6 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" clientgotesting "k8s.io/client-go/testing" + "knative.dev/pkg/ptr" pkgreconcilertesting "knative.dev/pkg/reconciler/testing" ) @@ -41,6 +42,10 @@ var ( ObjectMeta: metav1.ObjectMeta{Namespace: "testns", Name: "test"}, Spec: appsv1.DeploymentSpec{MinReadySeconds: 20}, } + deploymentWithReplicas = &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{Namespace: "testns", Name: "test"}, + Spec: appsv1.DeploymentSpec{MinReadySeconds: 10, Replicas: ptr.Int32(3)}, + } deploymentCreateFailure = pkgreconcilertesting.InduceFailure("create", "deployments") deploymentUpdateFailure = pkgreconcilertesting.InduceFailure("update", "deployments") @@ -94,6 +99,14 @@ func TestDeploymentReconciler(t *testing.T) { }, in: deployment, }, + { + commonCase: commonCase{ + name: "deployment exists with different replicas", + existing: []runtime.Object{deploymentWithReplicas}, + }, + in: deployment, + want: deploymentWithReplicas, + }, } for _, test := range tests {