Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-delph committed Nov 13, 2023
1 parent 6e61d09 commit 382d737
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 2 deletions.
127 changes: 125 additions & 2 deletions pkg/reconciler/revision/resources/pa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestMakePA(t *testing.T) {
Reachability: autoscalingv1alpha1.ReachabilityUnknown,
}},
}, {
name: "failed deployment",
name: "failed deployment - active route",
rev: &v1.Revision{
ObjectMeta: metav1.ObjectMeta{
Namespace: "blah",
Expand Down Expand Up @@ -272,6 +272,67 @@ func TestMakePA(t *testing.T) {
},
},
},
want: &autoscalingv1alpha1.PodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Namespace: "blah",
Name: "batman",
Annotations: map[string]string{},
Labels: map[string]string{
serving.RevisionLabelKey: "batman",
serving.RevisionUID: "4321",
AppLabelKey: "batman",
},
OwnerReferences: []metav1.OwnerReference{{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: "Revision",
Name: "batman",
UID: "4321",
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: autoscalingv1alpha1.PodAutoscalerSpec{
ContainerConcurrency: 0,
ScaleTargetRef: corev1.ObjectReference{
APIVersion: "apps/v1",
Kind: "Deployment",
Name: "batman-deployment",
},
ProtocolType: networking.ProtocolH2C,
Reachability: autoscalingv1alpha1.ReachabilityReachable,
},
},
}, {
name: "failed deployment - active route",
rev: &v1.Revision{
ObjectMeta: metav1.ObjectMeta{
Namespace: "blah",
Name: "batman",
UID: "4321",
Labels: map[string]string{
serving.RoutingStateLabelKey: string(v1.RoutingStateReserve),
},
},
Spec: v1.RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Ports: []corev1.ContainerPort{{
Name: "h2c",
HostPort: int32(443),
}},
}},
},
},
Status: v1.RevisionStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: v1.RevisionConditionResourcesAvailable,
Status: corev1.ConditionFalse,
}},
},
},
},
want: &autoscalingv1alpha1.PodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Namespace: "blah",
Expand Down Expand Up @@ -304,7 +365,7 @@ func TestMakePA(t *testing.T) {
},
}, {
// Crashlooping container that never starts
name: "failed container",
name: "failed container - active route",
rev: &v1.Revision{
ObjectMeta: metav1.ObjectMeta{
Namespace: "blah",
Expand Down Expand Up @@ -334,6 +395,68 @@ func TestMakePA(t *testing.T) {
},
},
},
want: &autoscalingv1alpha1.PodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Namespace: "blah",
Name: "batman",
Annotations: map[string]string{},
Labels: map[string]string{
serving.RevisionLabelKey: "batman",
serving.RevisionUID: "4321",
AppLabelKey: "batman",
},
OwnerReferences: []metav1.OwnerReference{{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: "Revision",
Name: "batman",
UID: "4321",
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: autoscalingv1alpha1.PodAutoscalerSpec{
ContainerConcurrency: 0,
ScaleTargetRef: corev1.ObjectReference{
APIVersion: "apps/v1",
Kind: "Deployment",
Name: "batman-deployment",
},
ProtocolType: networking.ProtocolH2C,
Reachability: autoscalingv1alpha1.ReachabilityReachable,
},
},
}, {
// Crashlooping container that never starts
name: "failed container - reserve route",
rev: &v1.Revision{
ObjectMeta: metav1.ObjectMeta{
Namespace: "blah",
Name: "batman",
UID: "4321",
Labels: map[string]string{
serving.RoutingStateLabelKey: string(v1.RoutingStateReserve),
},
},
Spec: v1.RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Ports: []corev1.ContainerPort{{
Name: "h2c",
HostPort: int32(443),
}},
}},
},
},
Status: v1.RevisionStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: v1.RevisionConditionContainerHealthy,
Status: corev1.ConditionFalse,
}},
},
},
},
want: &autoscalingv1alpha1.PodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Namespace: "blah",
Expand Down
3 changes: 3 additions & 0 deletions pkg/reconciler/revision/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (

netcfg "knative.dev/networking/pkg/config"
"knative.dev/pkg/apis"
fakepodsinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/pod/fake"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/kmeta"
Expand Down Expand Up @@ -84,6 +85,8 @@ func newTestController(t *testing.T, configs []*corev1.ConfigMap, opts ...reconc
*controller.Impl,
*configmap.ManualWatcher) {

println(fakepodsinformer.Get)

ctx, cancel, informers := SetupFakeContextWithCancel(t)
t.Cleanup(cancel) // cancel is reentrant, so if necessary callers can call it directly, if needed.
configMapWatcher := &configmap.ManualWatcher{Namespace: system.Namespace()}
Expand Down

0 comments on commit 382d737

Please sign in to comment.