Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkg/reconciler/revision/cruds.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package revision
import (
"context"

"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/equality"
caching "knative.dev/caching/pkg/apis/caching/v1alpha1"
Expand All @@ -34,7 +35,7 @@ import (
func (c *Reconciler) createDeployment(ctx context.Context, rev *v1alpha1.Revision) (*appsv1.Deployment, error) {
cfgs := config.FromContext(ctx)

deployment := resources.MakeDeployment(
deployment, err := resources.MakeDeployment(
rev,
cfgs.Logging,
cfgs.Tracing,
Expand All @@ -44,14 +45,18 @@ func (c *Reconciler) createDeployment(ctx context.Context, rev *v1alpha1.Revisio
cfgs.Deployment,
)

if err != nil {
return nil, errors.Wrap(err, "failed to make deployment")
}

return c.KubeClientSet.AppsV1().Deployments(deployment.Namespace).Create(deployment)
}

func (c *Reconciler) checkAndUpdateDeployment(ctx context.Context, rev *v1alpha1.Revision, have *appsv1.Deployment) (*appsv1.Deployment, error) {
logger := logging.FromContext(ctx)
cfgs := config.FromContext(ctx)

deployment := resources.MakeDeployment(
deployment, err := resources.MakeDeployment(
rev,
cfgs.Logging,
cfgs.Tracing,
Expand All @@ -61,6 +66,10 @@ func (c *Reconciler) checkAndUpdateDeployment(ctx context.Context, rev *v1alpha1
cfgs.Deployment,
)

if err != nil {
return nil, errors.Wrap(err, "failed to update deployment")
}

// Preserve the current scale of the Deployment.
deployment.Spec.Replicas = have.Spec.Replicas

Expand Down
23 changes: 17 additions & 6 deletions pkg/reconciler/revision/resources/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package resources
import (
"strconv"

"github.com/pkg/errors"
"knative.dev/pkg/kmeta"
"knative.dev/pkg/logging"
"knative.dev/pkg/ptr"
Expand Down Expand Up @@ -108,7 +109,13 @@ func rewriteUserProbe(p *corev1.Probe, userPort int) {
}
}

func makePodSpec(rev *v1alpha1.Revision, loggingConfig *logging.Config, tracingConfig *tracingconfig.Config, observabilityConfig *metrics.ObservabilityConfig, autoscalerConfig *autoscaler.Config, deploymentConfig *deployment.Config) *corev1.PodSpec {
func makePodSpec(rev *v1alpha1.Revision, loggingConfig *logging.Config, tracingConfig *tracingconfig.Config, observabilityConfig *metrics.ObservabilityConfig, autoscalerConfig *autoscaler.Config, deploymentConfig *deployment.Config) (*corev1.PodSpec, error) {
queueContainer, err := makeQueueContainer(rev, loggingConfig, tracingConfig, observabilityConfig, autoscalerConfig, deploymentConfig)

if err != nil {
return nil, errors.Wrap(err, "failed to create queue-proxy container")
}

userContainer := rev.Spec.GetContainer().DeepCopy()
// Adding or removing an overwritten corev1.Container field here? Don't forget to
// update the fieldmasks / validations in pkg/apis/serving
Expand Down Expand Up @@ -149,7 +156,7 @@ func makePodSpec(rev *v1alpha1.Revision, loggingConfig *logging.Config, tracingC
podSpec := &corev1.PodSpec{
Containers: []corev1.Container{
*userContainer,
*makeQueueContainer(rev, loggingConfig, tracingConfig, observabilityConfig, autoscalerConfig, deploymentConfig),
*queueContainer,
},
Volumes: append([]corev1.Volume{varLogVolume}, rev.Spec.Volumes...),
ServiceAccountName: rev.Spec.ServiceAccountName,
Expand All @@ -161,7 +168,7 @@ func makePodSpec(rev *v1alpha1.Revision, loggingConfig *logging.Config, tracingC
podSpec.Volumes = append(podSpec.Volumes, internalVolume)
}

return podSpec
return podSpec, nil
}

func getUserPort(rev *v1alpha1.Revision) int32 {
Expand Down Expand Up @@ -193,7 +200,7 @@ func buildUserPortEnv(userPort string) corev1.EnvVar {
// MakeDeployment constructs a K8s Deployment resource from a revision.
func MakeDeployment(rev *v1alpha1.Revision,
loggingConfig *logging.Config, tracingConfig *tracingconfig.Config, networkConfig *network.Config, observabilityConfig *metrics.ObservabilityConfig,
autoscalerConfig *autoscaler.Config, deploymentConfig *deployment.Config) *appsv1.Deployment {
autoscalerConfig *autoscaler.Config, deploymentConfig *deployment.Config) (*appsv1.Deployment, error) {

podTemplateAnnotations := resources.FilterMap(rev.GetAnnotations(), func(k string) bool {
return k == serving.RevisionLastPinnedAnnotationKey
Expand Down Expand Up @@ -221,6 +228,10 @@ func MakeDeployment(rev *v1alpha1.Revision,
podTemplateAnnotations[IstioOutboundIPRangeAnnotation] = networkConfig.IstioOutboundIPRanges
}
}
podSpec, err := makePodSpec(rev, loggingConfig, tracingConfig, observabilityConfig, autoscalerConfig, deploymentConfig)
if err != nil {
return nil, errors.Wrap(err, "failed to create PodSpec")
}

return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -242,8 +253,8 @@ func MakeDeployment(rev *v1alpha1.Revision,
Labels: makeLabels(rev),
Annotations: podTemplateAnnotations,
},
Spec: *makePodSpec(rev, loggingConfig, tracingConfig, observabilityConfig, autoscalerConfig, deploymentConfig),
Spec: *podSpec,
},
},
}
}, nil
}
Loading