Skip to content

Commit

Permalink
Remove our use of &boolTrue using new helpers. (#3723)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor authored and knative-prow-robot committed Apr 10, 2019
1 parent 7ce6cfb commit 6ab2ea6
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 57 deletions.
93 changes: 93 additions & 0 deletions pkg/reconciler/v1alpha1/autoscaling/kpa/resources/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright 2019 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package resources

import (
"testing"

"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/knative/pkg/ptr"
pav1a1 "github.com/knative/serving/pkg/apis/autoscaling/v1alpha1"
"github.com/knative/serving/pkg/apis/networking"
"github.com/knative/serving/pkg/apis/serving"
autoscalingv1 "k8s.io/api/autoscaling/v1"
)

func TestMakeService(t *testing.T) {
pa := &pav1a1.PodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Namespace: "here",
Name: "with-you",
UID: "2006",
// Those labels are propagated from the Revision->KPA.
Labels: map[string]string{
serving.RevisionLabelKey: "with-you",
serving.RevisionUID: "2009",
},
Annotations: map[string]string{
"a": "b",
},
},
Spec: pav1a1.PodAutoscalerSpec{
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
APIVersion: "apps/v1",
Kind: "Deployment",
Name: "with-you",
},
ServiceName: "with-you-service",
},
}
selector := map[string]string{"cant": "stop"}
want := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "here",
Name: "with-you-metrics",
Labels: map[string]string{
// Those should be propagated.
serving.RevisionLabelKey: "with-you",
serving.RevisionUID: "2009",
kpaLabelKey: "with-you",
networking.ServiceTypeKey: string(networking.ServiceTypeMetrics),
},
Annotations: map[string]string{
"a": "b",
},
OwnerReferences: []metav1.OwnerReference{{
APIVersion: pav1a1.SchemeGroupVersion.String(),
Kind: "PodAutoscaler",
Name: "with-you",
UID: "2006",
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Name: "metrics",
Protocol: corev1.ProtocolTCP,
Port: 9090,
TargetPort: intstr.FromString("queue-metrics"),
}},
Selector: selector,
},
}
got := MakeMetricsService(pa, selector)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("Metrics K8s Service mismatch (-want, +got) = %v", diff)
}
}
7 changes: 3 additions & 4 deletions pkg/reconciler/v1alpha1/autoscaling/resources/sks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/knative/pkg/ptr"
pav1a1 "github.com/knative/serving/pkg/apis/autoscaling/v1alpha1"
"github.com/knative/serving/pkg/apis/networking"
nv1a1 "github.com/knative/serving/pkg/apis/networking/v1alpha1"
"github.com/knative/serving/pkg/apis/serving"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var boolTrue = true

// MakeSKS makes an SKS resource from the PA, selector and operation mode.
func TestMakeSKS(t *testing.T) {
pa := &pav1a1.PodAutoscaler{
Expand Down Expand Up @@ -70,8 +69,8 @@ func TestMakeSKS(t *testing.T) {
Kind: "PodAutoscaler",
Name: "with-you",
UID: "2006",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: nv1a1.ServerlessServiceSpec{
Expand Down
2 changes: 0 additions & 2 deletions pkg/reconciler/v1alpha1/configuration/resources/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

var boolTrue = true

func TestBuilds(t *testing.T) {
tests := []struct {
name string
Expand Down
17 changes: 9 additions & 8 deletions pkg/reconciler/v1alpha1/configuration/resources/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/knative/pkg/ptr"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -60,8 +61,8 @@ func TestMakeRevisions(t *testing.T) {
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "Configuration",
Name: "build",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
Labels: map[string]string{
serving.ConfigurationLabelKey: "build",
Expand Down Expand Up @@ -113,8 +114,8 @@ func TestMakeRevisions(t *testing.T) {
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "Configuration",
Name: "build",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
Labels: map[string]string{
serving.ConfigurationLabelKey: "build",
Expand Down Expand Up @@ -167,8 +168,8 @@ func TestMakeRevisions(t *testing.T) {
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "Configuration",
Name: "labels",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
Labels: map[string]string{
serving.ConfigurationLabelKey: "labels",
Expand Down Expand Up @@ -217,8 +218,8 @@ func TestMakeRevisions(t *testing.T) {
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "Configuration",
Name: "annotations",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
Labels: map[string]string{
serving.ConfigurationLabelKey: "annotations",
Expand Down
8 changes: 4 additions & 4 deletions pkg/reconciler/v1alpha1/revision/resources/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ var (
Kind: "Revision",
Name: "bar",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: appsv1.DeploymentSpec{
Expand Down Expand Up @@ -349,8 +349,8 @@ func withOwnerReference(name string) revisionOption {
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "Configuration",
Name: name,
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}}
}
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/reconciler/v1alpha1/revision/resources/fluentd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/knative/pkg/ptr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -67,8 +68,8 @@ func TestMakeFluentdConfigMap(t *testing.T) {
Kind: "Revision",
Name: "bar",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Data: map[string]string{
Expand Down Expand Up @@ -102,8 +103,8 @@ func TestMakeFluentdConfigMap(t *testing.T) {
Kind: "Revision",
Name: "bar",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Data: map[string]string{
Expand Down Expand Up @@ -212,8 +213,8 @@ func TestMakeFluentdContainer(t *testing.T) {
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "Configuration",
Name: "the-parent-config-name",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
},
Expand Down
9 changes: 5 additions & 4 deletions pkg/reconciler/v1alpha1/revision/resources/imagecache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/knative/pkg/ptr"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -72,8 +73,8 @@ func TestMakeImageCache(t *testing.T) {
Kind: "Revision",
Name: "bar",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: caching.ImageSpec{
Expand Down Expand Up @@ -111,8 +112,8 @@ func TestMakeImageCache(t *testing.T) {
Kind: "Revision",
Name: "bar",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: caching.ImageSpec{
Expand Down
9 changes: 5 additions & 4 deletions pkg/reconciler/v1alpha1/revision/resources/kpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/knative/pkg/ptr"
autoscalingv1 "k8s.io/api/autoscaling/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -70,8 +71,8 @@ func TestMakeKPA(t *testing.T) {
Kind: "Revision",
Name: "bar",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: kpa.PodAutoscalerSpec{
Expand Down Expand Up @@ -118,8 +119,8 @@ func TestMakeKPA(t *testing.T) {
Kind: "Revision",
Name: "baz",
UID: "4321",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: kpa.PodAutoscalerSpec{
Expand Down
6 changes: 2 additions & 4 deletions pkg/reconciler/v1alpha1/revision/resources/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var boolTrue = true

func TestMakeQueueContainer(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -313,8 +311,8 @@ func TestMakeQueueContainer(t *testing.T) {
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "Configuration",
Name: "the-parent-config-name",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: v1alpha1.RevisionSpec{
Expand Down
13 changes: 7 additions & 6 deletions pkg/reconciler/v1alpha1/revision/resources/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/knative/pkg/ptr"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -61,8 +62,8 @@ func TestMakeK8sService(t *testing.T) {
Kind: "Revision",
Name: "bar",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -115,8 +116,8 @@ func TestMakeK8sService(t *testing.T) {
Kind: "Revision",
Name: "baz",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -161,8 +162,8 @@ func TestMakeK8sService(t *testing.T) {
Kind: "Revision",
Name: "bar",
UID: "1234",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
Spec: corev1.ServiceSpec{
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/v1alpha1/route/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/knative/pkg/configmap"
"github.com/knative/pkg/controller"
"github.com/knative/pkg/ptr"
netv1alpha1 "github.com/knative/serving/pkg/apis/networking/v1alpha1"
"github.com/knative/serving/pkg/apis/serving"
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
Expand Down Expand Up @@ -1596,7 +1597,6 @@ func patchLastPinned(namespace, name string) clientgotesting.PatchActionImpl {
}

func rev(namespace, name string, generation int64, ro ...RevisionOption) *v1alpha1.Revision {
boolTrue := true
r := &v1alpha1.Revision{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Expand All @@ -1608,8 +1608,8 @@ func rev(namespace, name string, generation int64, ro ...RevisionOption) *v1alph
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "Configuration",
Name: name,
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
}},
},
}
Expand Down
Loading

0 comments on commit 6ab2ea6

Please sign in to comment.