fix(imagebuild): derive build Job name from all build inputs - #58
Merged
Conversation
BuildJobName hashed only the source revision, so two ImageBuilds that differed solely in dockerfilePath or contextPath mapped to the same Job name. PR #54 gave those builds distinct ImageBuild CR names, but the second build's reconcile did a plain Get by Job name, found the first build's completed Job, and reported BuildComplete without ever running a build. The image tag is revision-derived, so the status ImageUrl then pointed at the image built from the old Dockerfile. Make BuildJobName a method on *ImageBuild that hashes the whole spec: source revision, Dockerfile path, context path, repository and build args. Cancelled is zeroed before hashing since cancelling deletes the Job rather than changing the image. The 63-character ceiling still holds structurally: the resource-name segment is capped at 63 - 8 (hash) - 6 ("-build") - 1. Tests assert both the length limit and DNS-1123 label validity across long, empty and non-ASCII inputs, plus the regression case where only the Dockerfile path changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BuildJobNamehashed only the source revision. Two ImageBuilds that differ solely indockerfilePathorcontextPathmapped to the same Job name in the same namespace.#54 fixed the ImageBuild CR name (whole-spec hash), but not the Job name. Failure path when a user changes only
dockerFilePath:reconcileBuildJobdoes a plainGetby name — no ownership check — and finds fix: skip synchronous replication config when NumSynchronousReplicas is 0 #1's completed Job.BuildCompleteand setsStatus.ImageUrl. No build ever runs. The tag is revision-derived, so the URL resolves to the image built from the old Dockerfile. Silent stale deploy.Same class of bug for
contextPath,repositoryandbuildArgs— none were in the Job name.Change
BuildJobNamebecomes a method on*ImageBuildthat hashes the whole spec: source revision, Dockerfile path, context path, repository, build args. Mirrors whatImageBuildNamealready does.Cancelledis zeroed before hashing — cancelling deletes the Job, it does not change the image.buildInputsHashgeneralized toanyso both name helpers share it. Both controller call sites now usebuildConfig.BuildJobName().k8s name limits
The Job name is copied verbatim into the
batch.kubernetes.io/job-namelabel on every pod the Job creates, and label values cap at 63. Enforced structurally:maxResourceNameInJob = 63 - 8 (hash) - 6 ("-build") - 1 = 48.TestBuildJobName_HonorsK8sNameLimitsasserts length <= 63 and DNS-1123 label validity across 11 cases: 200-char resource name, truncation landing on a dash, non-ASCII revision, empty resource name, empty revision, separators-only name.Not in scope
reconcileBuildJob. With an input-derived name, a Job under that name is by construction this build's Job.Test plan
go build ./...go vet ./api/... ./internal/...go test ./api/builds/v1alpha1/... ./internal/...— all greendockerfilePath(andcontextPath, build args, repository) produce different Job namesNot run:
make test-integration(~11 min, needs Docker).