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
12 changes: 6 additions & 6 deletions docs/spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ metadata:
name: my-service
namespace: default
labels:
knative.dev/type: ... # +optional convention: function|app
knative.dev/service: ... # name of the Service automatically filled in

# system generated meta
uid: ...
Expand Down Expand Up @@ -113,7 +113,9 @@ kind: Configuration
metadata:
name: my-service
namespace: default

labels:
knative.dev/service: ... # name of the Service automatically filled in
knative.dev/route: ... # name of the Route automatically filled in
# system generated meta
uid: ...
resourceVersion: ... # used for optimistic concurrency control
Expand Down Expand Up @@ -222,10 +224,8 @@ metadata:
name: myservice-a1e34 # system generated
namespace: default
labels:
knative.dev/configuration: ... # to list configurations/revisions by service
knative.dev/type: "function" # convention, one of "function" or "app"
knative.dev/revision: ... # generated revision name
knative.dev/revisionUID: ... # generated revision UID
knative.dev/configuration: ... # name of the Configuration automatically filled in
knative.dev/service: ... # name of the Service automatically filled in
annotations:
knative.dev/configurationGeneration: ... # generation of configuration that created this Revision
# system generated meta
Expand Down
100 changes: 100 additions & 0 deletions test/conformance/labels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// +build e2e

/*
Copyright 2018 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 conformance

import (
"testing"

"github.com/knative/pkg/test/logging"
serviceresourcenames "github.com/knative/serving/pkg/reconciler/v1alpha1/service/resources/names"
"github.com/knative/serving/test"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestLabelsPropagation(t *testing.T) {
clients := setup(t)

// Add test case specific name to its own logger.
logger := logging.GetContextLogger("TestLabelsPropagation")

names := test.ResourceNames{Service: test.AppendRandomString("pizzaplanet-service", logger)}
var imagePath = test.ImagePath("helloworld")

defer tearDown(clients, names)
test.CleanupOnInterrupt(func() { tearDown(clients, names) }, logger)

logger.Info("Creating a new Service")
svc, err := test.CreateLatestService(logger, clients, names, imagePath)
if err != nil {
t.Fatalf("Failed to create Service: %v", err)
}
names.Route = serviceresourcenames.Route(svc)
names.Config = serviceresourcenames.Configuration(svc)

logger.Info("The Service will be updated with the name of the Revision once it is created")
names.Revision, err = waitForServiceLatestCreatedRevision(clients, names)
if err != nil {
t.Fatalf("Service %s was not updated with the new revision: %v", names.Service, err)
}

logger.Info("When the Service reports as Ready, everything should be ready.")
if err := test.WaitForServiceState(clients.ServingClient, names.Service, test.IsServiceReady, "ServiceIsReady"); err != nil {
t.Fatalf("The Service %s was not marked as Ready to serve traffic to Revision %s: %v", names.Service, names.Revision, err)
}

// Now that the Serive is ready, we can validate the Labels on the Revision, Configuration
// and Route objects
// see spec here: https://github.com/knative/serving/blob/master/docs/spec/spec.md#revision

logger.Info("Validate Labels on Revision Object")
revision, err := clients.ServingClient.Revisions.Get(names.Revision, metav1.GetOptions{})
if err != nil {
t.Errorf("Error fetching Revision %s: %v", names.Revision, err)
}

if revision.Labels["serving.knative.dev/configuration"] != names.Config {
t.Errorf("Expect Confguration name in Revision label %q but got %q ", names.Config, revision.Labels["serving.knative.dev/configuration"])
}
if revision.Labels["serving.knative.dev/service"] != names.Service {
t.Errorf("Expect Service name in Revision label %q but got %q ", names.Service, revision.Labels["serving.knative.dev/service"])
}

logger.Info("Validate Labels on Configuration Object")
config, err := clients.ServingClient.Configs.Get(names.Config, metav1.GetOptions{})
if err != nil {
t.Errorf("Error fetching Configuration %s: %v", names.Config, err)
}

if config.Labels["serving.knative.dev/service"] != names.Service {
t.Errorf("Expect Service name in Configuration label %q but got %q ", names.Service, config.Labels["serving.knative.dev/service"])
}
if config.Labels["serving.knative.dev/route"] != names.Route {
t.Errorf("Expect Route name in Configuration label %q but got %q ", names.Route, config.Labels["serving.knative.dev/route"])
}

logger.Info("Validate Labels on Route Object")
route, err := clients.ServingClient.Routes.Get(names.Route, metav1.GetOptions{})
if err != nil {
t.Errorf("Error fetching Route %s: %v", names.Route, err)
}

if route.Labels["serving.knative.dev/service"] != names.Service {
t.Errorf("Expect Service name in Route label %q but got %q ", names.Service, route.Labels["serving.knative.dev/service"])
}
}