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
4 changes: 4 additions & 0 deletions pkg/apis/serving/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ const (
// ConfigurationGenerationLabelKey is the label key attached to a Revision indicating the
// generation of the Configuration that created this revision
ConfigurationGenerationLabelKey = GroupName + "/configurationGeneration"

// BuildHashLabelKey is the label key attached to a Build indicating the
// hash of the spec from which they were created.
BuildHashLabelKey = GroupName + "/buildHash"
)
16 changes: 16 additions & 0 deletions pkg/reconciler/v1alpha1/configuration/resources/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ limitations under the License.
package resources

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

buildv1alpha1 "github.com/knative/build/pkg/apis/build/v1alpha1"
"github.com/knative/pkg/kmeta"
"github.com/knative/serving/pkg/apis/serving"
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
"github.com/knative/serving/pkg/reconciler/v1alpha1/configuration/resources/names"
)
Expand All @@ -48,6 +51,19 @@ func MakeBuild(config *v1alpha1.Configuration) *unstructured.Unstructured {

u = MustToUnstructured(b)
}
// After calling `As()` we can be sure that `.Raw` is populated.

// Compute the hash of the current build's spec.
sum := sha256.Sum256(config.Spec.Build.Raw)
h := hex.EncodeToString(sum[:])

// Put it into a label for later lookups.
l := u.GetLabels()
if l == nil {
l = make(map[string]string)
}
l[serving.BuildHashLabelKey] = h[:63] // Labels can only be 63 characters.
u.SetLabels(l)

u.SetNamespace(config.Namespace)
u.SetName(names.Build(config))
Expand Down
6 changes: 6 additions & 0 deletions pkg/reconciler/v1alpha1/configuration/resources/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func TestBuilds(t *testing.T) {
"controller": true,
"blockOwnerDeletion": true,
}},
"labels": map[string]interface{}{
"serving.knative.dev/buildHash": "2ee4528bee48a78637ec374eb58cb1977b9611b85545f8b91884ff80b8d9472",
},
"creationTimestamp": nil,
},
"spec": map[string]interface{}{
Expand Down Expand Up @@ -146,6 +149,9 @@ func TestBuilds(t *testing.T) {
"controller": true,
"blockOwnerDeletion": true,
}},
"labels": map[string]interface{}{
"serving.knative.dev/buildHash": "934e535117334c700c3a132e5e9dfc4276974cf2c9d6fe8f09c961f8e058933",
},
"creationTimestamp": nil,
},
"spec": map[string]interface{}{
Expand Down