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 serviceUID/configUID labels to pods & deployments, serviceUID label to configs #10539

Merged
merged 1 commit into from
Jan 16, 2021
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
8 changes: 8 additions & 0 deletions pkg/apis/serving/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ const (
// its unique identifier
RevisionUID = GroupName + "/revisionUID"

// ConfigUIDLabelKey is the label key attached to a pod to reference its
// Knative Configuration by its unique UID
ConfigUIDLabelKey = GroupName + "/configUID"

// ServiceUIDLabelKey is the label key attached to a pod to reference its
// Knative Service by its unique UID
ServiceUIDLabelKey = GroupName + "/serviceUID"
dprotaso marked this conversation as resolved.
Show resolved Hide resolved

// ServiceLabelKey is the label key attached to a Route and Configuration indicating by
// which Service they are created.
ServiceLabelKey = GroupName + "/service"
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/serving/v1/configuration_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ func (cs *ConfigurationSpec) Validate(ctx context.Context) *apis.FieldError {
func (c *Configuration) validateLabels() (errs *apis.FieldError) {
for key, val := range c.GetLabels() {
switch key {
case serving.RouteLabelKey:
// Known valid labels.
case serving.RouteLabelKey,
serving.ConfigUIDLabelKey,
serving.ServiceUIDLabelKey:
// Known valid labels - so just skip them
case serving.ServiceLabelKey:
errs = errs.Also(verifyLabelOwnerRef(val, serving.ServiceLabelKey, "Service", c.GetOwnerReferences()))
default:
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/serving/v1/revision_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func (r *Revision) ValidateLabels() (errs *apis.FieldError) {
case serving.RoutingStateLabelKey,
serving.RouteLabelKey,
serving.ServiceLabelKey,
serving.ConfigUIDLabelKey,
serving.ServiceUIDLabelKey,
serving.ConfigurationGenerationLabelKey:
// Known valid labels.
case serving.ConfigurationLabelKey:
Expand Down
6 changes: 6 additions & 0 deletions pkg/reconciler/configuration/resources/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func updateRevisionLabels(rev, config metav1.Object) {
serving.ConfigurationLabelKey,
serving.ServiceLabelKey,
serving.ConfigurationGenerationLabelKey,
serving.ConfigUIDLabelKey,
serving.ServiceUIDLabelKey,
} {
labels[key] = RevisionLabelValueForKey(key, config)
}
Expand Down Expand Up @@ -101,6 +103,10 @@ func RevisionLabelValueForKey(key string, config metav1.Object) string {
return config.GetLabels()[serving.ServiceLabelKey]
case serving.ConfigurationGenerationLabelKey:
return fmt.Sprint(config.GetGeneration())
case serving.ConfigUIDLabelKey:
return string(config.GetUID())
case serving.ServiceUIDLabelKey:
return config.GetLabels()[serving.ServiceUIDLabelKey]
}
return ""
}
45 changes: 40 additions & 5 deletions pkg/reconciler/configuration/resources/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func TestMakeRevisions(t *testing.T) {
Namespace: "no",
Name: "build",
Generation: 10,
Labels: map[string]string{
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
},
Spec: v1.ConfigurationSpec{
Template: v1.RevisionTemplateSpec{
Expand All @@ -72,12 +76,15 @@ func TestMakeRevisions(t *testing.T) {
Name: "build",
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
}},
Labels: map[string]string{
serving.RoutingStateLabelKey: "pending",
serving.ConfigurationLabelKey: "build",
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't seem to have any positive tests here.

Copy link
Author

Choose a reason for hiding this comment

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

yep - on my todo list - wanted to get the core of this out there for review ASAP. Coming soon...

Copy link
Author

Choose a reason for hiding this comment

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

done

serving.ConfigurationGenerationLabelKey: "10",
serving.ConfigUIDLabelKey: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
serving.RoutingStateLabelKey: "pending",
serving.ServiceLabelKey: "",
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
Annotations: map[string]string{
serving.RoutingStateModifiedAnnotationKey: v1.RoutingStateModifiedString(clock),
Expand All @@ -98,6 +105,10 @@ func TestMakeRevisions(t *testing.T) {
Namespace: "with",
Name: "labels",
Generation: 100,
Labels: map[string]string{
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
},
Spec: v1.ConfigurationSpec{
Template: v1.RevisionTemplateSpec{
Expand Down Expand Up @@ -130,12 +141,15 @@ func TestMakeRevisions(t *testing.T) {
Name: "labels",
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
}},
Labels: map[string]string{
serving.ConfigurationLabelKey: "labels",
serving.ConfigurationGenerationLabelKey: "100",
serving.ServiceLabelKey: "",
serving.ConfigUIDLabelKey: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
serving.RoutingStateLabelKey: "pending",
serving.ServiceLabelKey: "",
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"foo": "bar",
"baz": "blah",
},
Expand All @@ -155,6 +169,10 @@ func TestMakeRevisions(t *testing.T) {
Namespace: "with",
Name: "annotations",
Generation: 100,
Labels: map[string]string{
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
},
Spec: v1.ConfigurationSpec{
Template: v1.RevisionTemplateSpec{
Expand Down Expand Up @@ -184,12 +202,15 @@ func TestMakeRevisions(t *testing.T) {
Name: "annotations",
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
}},
Labels: map[string]string{
serving.ConfigurationLabelKey: "annotations",
serving.ConfigurationGenerationLabelKey: "100",
serving.ServiceLabelKey: "",
serving.ConfigUIDLabelKey: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
serving.RoutingStateLabelKey: "pending",
serving.ServiceLabelKey: "",
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
Annotations: map[string]string{
"foo": "bar",
Expand Down Expand Up @@ -217,7 +238,11 @@ func TestMakeRevisions(t *testing.T) {
"serving.knative.dev/lastModifier": "someone",
serving.RoutesAnnotationKey: "route",
},
Labels: map[string]string{
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
Generation: 10,
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
},
Spec: v1.ConfigurationSpec{
Template: v1.RevisionTemplateSpec{
Expand Down Expand Up @@ -246,12 +271,15 @@ func TestMakeRevisions(t *testing.T) {
Name: "config",
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
}},
Labels: map[string]string{
serving.ConfigurationLabelKey: "config",
serving.ConfigurationGenerationLabelKey: "10",
serving.ServiceLabelKey: "",
serving.ConfigUIDLabelKey: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
serving.RoutingStateLabelKey: "active",
serving.ServiceLabelKey: "",
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
},
Spec: v1.RevisionSpec{
Expand All @@ -272,7 +300,11 @@ func TestMakeRevisions(t *testing.T) {
"serving.knative.dev/creator": "admin",
"serving.knative.dev/lastModifier": "someone",
},
Labels: map[string]string{
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
Generation: 10,
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
},
Spec: v1.ConfigurationSpec{
Template: v1.RevisionTemplateSpec{
Expand Down Expand Up @@ -308,12 +340,15 @@ func TestMakeRevisions(t *testing.T) {
Name: "config",
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(true),
UID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
}},
Labels: map[string]string{
serving.ConfigurationLabelKey: "config",
serving.ConfigurationGenerationLabelKey: "10",
serving.ServiceLabelKey: "",
serving.ConfigUIDLabelKey: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
serving.RoutingStateLabelKey: "pending",
serving.ServiceLabelKey: "",
serving.ServiceUIDLabelKey: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
},
},
Spec: v1.RevisionSpec{
Expand Down
5 changes: 4 additions & 1 deletion pkg/reconciler/service/resources/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func MakeConfiguration(service *v1.Service) *v1.Configuration {

// MakeConfigurationFromExisting creates a Configuration from a Service object given an existing Configuration.
func MakeConfigurationFromExisting(service *v1.Service, existing *v1.Configuration) *v1.Configuration {
labels := map[string]string{serving.ServiceLabelKey: service.Name}
labels := map[string]string{
serving.ServiceLabelKey: service.Name,
serving.ServiceUIDLabelKey: string(service.ObjectMeta.UID),
}
anns := kmeta.FilterMap(service.GetAnnotations(), func(key string) bool {
return key == corev1.LastAppliedConfigAnnotation
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/service/resources/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestConfigurationSpec(t *testing.T) {
}
expectOwnerReferencesSetCorrectly(t, c.OwnerReferences)

if got, want := c.Labels, map[string]string{serving.ServiceLabelKey: testServiceName}; !cmp.Equal(got, want) {
if got, want := c.Labels, map[string]string{serving.ServiceLabelKey: testServiceName, serving.ServiceUIDLabelKey: "cccccccc-cccc-cccc-cccc-cccccccccccc"}; !cmp.Equal(got, want) {
t.Errorf("Labels mismatch: diff(-want,+got):\n%s", cmp.Diff(want, got))
}
if got, want := c.Annotations, map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/service/resources/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func expectOwnerReferencesSetCorrectly(t *testing.T, ownerRefs []metav1.OwnerRef
Kind: "Service",
Name: testServiceName,
}}
if diff := cmp.Diff(expectedRefs, ownerRefs, cmpopts.IgnoreFields(expectedRefs[0], "Controller", "BlockOwnerDeletion")); diff != "" {
if diff := cmp.Diff(expectedRefs, ownerRefs, cmpopts.IgnoreFields(expectedRefs[0], "Controller", "BlockOwnerDeletion", "UID")); diff != "" {
t.Error("Unexpected service owner refs diff (-want +got):", diff)
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/testing/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func Service(name, namespace string, so ...ServiceOption) *v1.Service {
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
UID: "cccccccc-cccc-cccc-cccc-cccccccccccc",
},
}
for _, opt := range so {
Expand Down