Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DomainMapping conformance test #9780

Merged
merged 7 commits into from
Oct 20, 2020
Merged
Changes from 1 commit
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
Next Next commit
Add DomainMapping conformance test
julz committed Oct 20, 2020
commit ab7fefea6810c1df12a1790a24ef84bdad4c6670
5 changes: 5 additions & 0 deletions pkg/apis/serving/v1alpha1/domainmapping_lifecycle.go
Original file line number Diff line number Diff line change
@@ -37,6 +37,11 @@ func (dm *DomainMapping) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("DomainMapping")
}

// IsReady returns true if the DomainMapping is ready.
func (dms *DomainMappingStatus) IsReady() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have moved away from this and are instead providing this method on the type itself, including a Generation check, like:

// IsReady returns true if the Status condition MetricConditionReady
// is true and the latest spec has been observed.
func (m *Metric) IsReady() bool {
	ms := m.Status
	return ms.ObservedGeneration == m.Generation &&
		ms.GetCondition(MetricConditionReady).IsTrue()
}

(this would also make the currently unused ReadyCondition constant used 😂 )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I copied this from Route but sure that makes sense, lemme update

return domainMappingCondSet.Manage(dms).IsHappy()
}

// InitializeConditions sets the initial values to the conditions.
func (dms *DomainMappingStatus) InitializeConditions() {
domainMappingCondSet.Manage(dms).InitializeConditions()
102 changes: 102 additions & 0 deletions pkg/apis/serving/v1alpha1/domainmapping_lifecycle_test.go
Original file line number Diff line number Diff line change
@@ -110,3 +110,105 @@ func TestPropagateIngressStatus(t *testing.T) {
apistest.CheckConditionOngoing(dms, DomainMappingConditionIngressReady, t)
apistest.CheckConditionOngoing(dms, DomainMappingConditionReady, t)
}

func TestDomainMappingIsReady(t *testing.T) {
cases := []struct {
name string
status DomainMappingStatus
isReady bool
}{{
name: "empty status should not be ready",
status: DomainMappingStatus{},
isReady: false,
}, {
name: "Different condition type should not be ready",
status: DomainMappingStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: DomainMappingConditionIngressReady,
Status: corev1.ConditionTrue,
}},
},
},
isReady: false,
}, {
name: "False condition status should not be ready",
status: DomainMappingStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: DomainMappingConditionReady,
Status: corev1.ConditionFalse,
}},
},
},
isReady: false,
}, {
name: "Unknown condition status should not be ready",
status: DomainMappingStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: DomainMappingConditionReady,
Status: corev1.ConditionUnknown,
}},
},
},
isReady: false,
}, {
name: "Missing condition status should not be ready",
status: DomainMappingStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: DomainMappingConditionReady,
}},
},
},
isReady: false,
}, {
name: "True condition status should be ready",
status: DomainMappingStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: DomainMappingConditionReady,
Status: corev1.ConditionTrue,
}},
},
},
isReady: true,
}, {
name: "Multiple conditions with ready status should be ready",
status: DomainMappingStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: DomainMappingConditionIngressReady,
Status: corev1.ConditionTrue,
}, {
Type: DomainMappingConditionReady,
Status: corev1.ConditionTrue,
}},
},
},
isReady: true,
}, {
name: "Multiple conditions with ready status false should not be ready",
status: DomainMappingStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: DomainMappingConditionIngressReady,
Status: corev1.ConditionTrue,
}, {
Type: DomainMappingConditionReady,
Status: corev1.ConditionFalse,
}},
},
},
isReady: false,
}}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if e, a := tc.isReady, tc.status.IsReady(); e != a {
t.Errorf("%q expected: %v got: %v", tc.name, e, a)
}
})
}
}
37 changes: 31 additions & 6 deletions test/clients.go
Original file line number Diff line number Diff line change
@@ -35,20 +35,27 @@ import (
"knative.dev/pkg/test"
"knative.dev/serving/pkg/client/clientset/versioned"
servingv1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1"
servingv1alpha1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1"

// Every E2E test requires this, so add it here.
_ "knative.dev/pkg/metrics/testing"
)

// Clients holds instances of interfaces for making requests to Knative Serving.
type Clients struct {
KubeClient *test.KubeClient
ServingClient *ServingClients
NetworkingClient *NetworkingClients
Dynamic dynamic.Interface
KubeClient *test.KubeClient
ServingAlphaClient *ServingAlphaClients
ServingClient *ServingClients
NetworkingClient *NetworkingClients
Dynamic dynamic.Interface
}

// ServingClients holds instances of interfaces for making requests to knative serving clients
// ServingAlphaClients holds instances of interfaces for making requests to knative serving clients.
type ServingAlphaClients struct {
DomainMappings servingv1alpha1.DomainMappingInterface
}

// ServingClients holds instances of interfaces for making requests to knative serving clients.
type ServingClients struct {
Routes servingv1.RouteInterface
Configs servingv1.ConfigurationInterface
@@ -95,6 +102,11 @@ func NewClientsFromConfig(cfg *rest.Config, namespace string) (*Clients, error)
return nil, err
}

clients.ServingAlphaClient, err = newServingAlphaClients(cfg, namespace)
if err != nil {
return nil, err
}

clients.Dynamic, err = dynamic.NewForConfig(cfg)
if err != nil {
return nil, err
@@ -109,7 +121,7 @@ func NewClientsFromConfig(cfg *rest.Config, namespace string) (*Clients, error)
}

// newNetworkingClients instantiates and returns the networking clientset required to make requests
// to Networking resources on the Knative service cluster
// to Networking resources on the Knative service cluster.
func newNetworkingClients(cfg *rest.Config, namespace string) (*NetworkingClients, error) {
cs, err := netclientset.NewForConfig(cfg)
if err != nil {
@@ -122,6 +134,19 @@ func newNetworkingClients(cfg *rest.Config, namespace string) (*NetworkingClient
}, nil
}

// newServingAlphaClients instantiates and returns the serving clientset required to make requests to the
// knative serving cluster.
func newServingAlphaClients(cfg *rest.Config, namespace string) (*ServingAlphaClients, error) {
cs, err := versioned.NewForConfig(cfg)
if err != nil {
return nil, err
}

return &ServingAlphaClients{
DomainMappings: cs.ServingV1alpha1().DomainMappings(namespace),
}, nil
}

// newServingClients instantiates and returns the serving clientset required to make requests to the
// knative serving cluster.
func newServingClients(cfg *rest.Config, namespace string) (*ServingClients, error) {
100 changes: 100 additions & 0 deletions test/conformance/api/v1alpha1/domain_mapping_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// +build e2e

/*
Copyright 2020 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 v1alpha1

import (
"context"
"net/url"
"testing"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/serving/pkg/apis/serving/v1alpha1"
"knative.dev/serving/test"
"knative.dev/serving/test/conformance/api/shared"
v1test "knative.dev/serving/test/v1"
)

func TestDomainMapping(t *testing.T) {
if !test.ServingFlags.EnableAlphaFeatures {
t.Skip("Alpha features not enabled")
}
Comment on lines +36 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should enable this in .github/workflows/kind-e2e.yaml and ./test/e2e-tests.sh otherwise nothing is running this. I feel like we should be running this at least somewhere.

I'd kinda like to see the istio class annotation moved to be config-based before we start adding e2e tests that will light up folks testgrid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added to kind-e2e in #9837, Im gonna ping on slack to try to get some hand-holding for how to go about trying to iterate on modifications to e2e-tests.sh :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. and added prow e2e in #9851. Think this may be ready to go now.


t.Parallel()
ctx, clients := context.Background(), test.Setup(t)

names := test.ResourceNames{
Service: test.ObjectNameForTest(t),
Image: test.HelloWorld,
}

// Clean up on test failure or interrupt.
test.EnsureTearDown(t, clients, &names)

// Setup initial Service.
svc, err := v1test.CreateServiceReady(t, clients, &names)
if err != nil {
t.Fatalf("Failed to create initial Service %v: %v", names.Service, err)
}

// Using fixed hostnames can lead to conflicts when multiple tests run at
// once, so include the svc name to avoid collisions.
host := svc.Service.Name + ".mapping.com"

// Point DomainMapping at our service.
dm, err := clients.ServingAlphaClient.DomainMappings.Create(ctx, &v1alpha1.DomainMapping{
ObjectMeta: metav1.ObjectMeta{
Name: host,
Namespace: svc.Service.Namespace,
},
Spec: v1alpha1.DomainMappingSpec{
Ref: duckv1.KReference{
Namespace: svc.Service.Namespace,
Name: svc.Service.Name,
},
},
}, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Create(DomainMapping) = %v, expected no error", err)
}

t.Cleanup(func() {
clients.ServingAlphaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{})
})

// Wait for DomainMapping to go Ready.
waitErr := wait.PollImmediate(test.PollInterval, 1*time.Minute, func() (bool, error) {
state, err := clients.ServingAlphaClient.DomainMappings.Get(context.Background(), dm.Name, metav1.GetOptions{})
if err != nil {
return true, err
}

return state.Status.IsReady(), nil
})
if waitErr != nil {
t.Fatalf("The DomainMapping %s was not marked as Ready: %v", dm.Name, waitErr)
}

// Should be able to access the test image text via the mapped domain.
if err := shared.CheckDistribution(ctx, t, clients, &url.URL{Host: host, Scheme: "http"}, test.ConcurrentRequests, test.ConcurrentRequests, []string{test.HelloWorldText}); err != nil {
t.Errorf("CheckDistribution=%v, expected no error", err)
}
}