-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 parent BuildConfig to Build OwnerReferences #12961
Add parent BuildConfig to Build OwnerReferences #12961
Conversation
pkg/build/generator/generator.go
Outdated
// deleted when the BuildConfig is deleted | ||
// TODO: is there a utility function for generating an owner reference from an object? | ||
newBuild.OwnerReferences = append(newBuild.OwnerReferences, kapi.OwnerReference{ | ||
APIVersion: "v1", // BuildConfig.APIVersion is not populated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to sort out the right way to resolve this.... we've got an internal buildconfig object, we (apparently?) need to know the api version of the actual buildconfig, or maybe just the api version of the server we're running in, to set this correctly?
@deads2k help
@jim-minter you've got a similar block in your template PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bparees find me on aos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very sorry I missed this, but was there a decision on what to do about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not exactly, but we did learn that "v1" is not the right value :)
i think the net was there isn't a good answer today because the value is supposed to be the name of the api group for builds, but builds aren't in an api group today. I think @deads2k implied that emptystring, or "core" or some other value could be used for things that aren't in an apigroup, but i'm not sure if that's true today, or something that he's hoping to make happen in the GC implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the net was there isn't a good answer today because the value is supposed to be the name of the api group for builds, but builds aren't in an api group today. I think @deads2k implied that emptystring, or "core" or some other value could be used for things that aren't in an apigroup, but i'm not sure if that's true today, or something that he's hoping to make happen in the GC implementation.
No value you put in here will work today. Your best bet is build.openshift.io/v1
(which obviously has migration problems), but that won't work without other API groups enabled. I really wouldn't much worry about it at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deads2k is there any intention to enable GC to work w/ non-apigroup resources in the 3.6 timeframe?
I don't see why we would want to do that. Every API should be group-ified. That should allow us to use the "stock" GC controller instead of doing the surgery required on the dynamic client to make it understand /oapi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I still don't really understand why ObjectRefs don't need apigroup values, but OwnerRefs do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I still don't really understand why ObjectRefs don't need apigroup values, but OwnerRefs do.
ObjectRefs
are going to need them too, but changing it now is likely to break API consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deads2k that's got some interesting migration implications......
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deads2k that's got some interesting migration implications......
- release 1: make new available, tolerate both
- release 2: stop writing old, write only new, migrate old data
- release 3: stop reading old and remove code cruft
We could stretch it out if we really wanted to I guess, but I think that's enough.
test/extended/builds/start.go
Outdated
g.Describe("setting OwnerReferences", func() { | ||
g.It("should set parent BuildConfig as OwnerReference", func() { | ||
g.By("starting the build from buildconfig") | ||
br, err := exutil.StartBuildAndWait(oc, "sample-build") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to wait for the build to finish, it'll be created immediately so you can just grab it and check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that there's no need for the build to run, and factoring in my suggestions above, can't this all be done in existing unit tests in generator_test.go? Search there for references to generateBuildFromConfig and generateBuildFromBuild.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's probably true that this need not be an extended test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved everything to the unit tests, along with other changes.
test/extended/builds/start.go
Outdated
br.AssertSuccess() | ||
if len(br.Build.ObjectMeta.OwnerReferences) == 0 { | ||
o.Expect(fmt.Errorf("Created build has no OwnerReferences")).NotTo(o.HaveOccurred()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should make sure the reference references the right thing (proper type, name of the buildconfig matches what you'd expect)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved everything to unit tests, but this is implemented
test/extended/builds/start.go
Outdated
br.AssertSuccess() | ||
if len(br.Build.ObjectMeta.OwnerReferences) == 0 { | ||
o.Expect(fmt.Errorf("Created build has no OwnerReferences")).NotTo(o.HaveOccurred()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the same comments here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved everything to unit tests, but this is implemented
pkg/build/generator/generator.go
Outdated
// Add the original Build's OwnerReferences to the new Builds. This will | ||
// make sure that the new Build is deleted when the original BuildConfig | ||
// is deleted. | ||
if len(build.OwnerReferences) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be better as a one-liner (I don't think the if statement is necessary) in generateBuildFromBuild, where newBuild is being instantiated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, the logic here is: OpenShift will always add OwnerReferences to builds instantiated from buildconfigs; if I happen to remove the OwnerReference manually and then clone that build, the resulting build will also not have an OwnerReference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure i'd classify it as intentional logic but yes that's the behavior and it's certainly worth noting. I'm inclined to say it's acceptable behavior... us re-attaching the reference by looking up the associated buildconfig, if anything, seems to be contrary to what the user probably intended if they removed the ownerreference.
pkg/build/generator/generator.go
Outdated
// Add the BuildConfig to the Build's OwnerReference, so that it will be | ||
// deleted when the BuildConfig is deleted | ||
// TODO: is there a utility function for generating an owner reference from an object? | ||
newBuild.OwnerReferences = append(newBuild.OwnerReferences, kapi.OwnerReference{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is better going straight into func (g *BuildGenerator) generateBuildFromConfig
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change was so simple, I didn't consider generateBuildFromConfig/Build. Thanks for pointing that out!
@openshift/devex Ready for another go around, ptal? |
pkg/build/generator/generator.go
Outdated
@@ -410,6 +410,14 @@ func (g *BuildGenerator) generateBuildFromConfig(ctx kapi.Context, bc *buildapi. | |||
ObjectMeta: kapi.ObjectMeta{ | |||
Name: buildName, | |||
Labels: bcCopy.Labels, | |||
OwnerReferences: []kapi.OwnerReference{ | |||
kapi.OwnerReference{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to repeat kapi.OwnerReference
- {
should do here.
@@ -1103,6 +1107,14 @@ func TestGenerateBuildFromBuild(t *testing.T) { | |||
buildapi.BuildJenkinsBuildURIAnnotation: "baz", | |||
buildapi.BuildPodNameAnnotation: "ruby-sample-build-1-build", | |||
}, | |||
OwnerReferences: []kapi.OwnerReference{ | |||
kapi.OwnerReference{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to repeat kapi.OwnerReference
- {
should do here.
@@ -1137,6 +1149,9 @@ func TestGenerateBuildFromBuild(t *testing.T) { | |||
if _, ok := newBuild.ObjectMeta.Annotations[buildapi.BuildPodNameAnnotation]; ok { | |||
t.Errorf("%s annotation exists, expected it not to", buildapi.BuildPodNameAnnotation) | |||
} | |||
if len(newBuild.OwnerReferences) == 0 || newBuild.OwnerReferences[0].Name != build.OwnerReferences[0].Name || newBuild.OwnerReferences[0].Kind != build.OwnerReferences[0].Kind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement currently has no effect. How about:
if !reflect.DeepEqual(build.ObjectMeta.OwnerReferences, newBuild.ObjectMeta.OwnerReferences) {
t.Errorf("Build OwnerReferences does not match the original Build OwnerReferences")
}
@@ -841,6 +842,9 @@ func TestGenerateBuildFromConfig(t *testing.T) { | |||
if build.Annotations[buildapi.BuildNumberAnnotation] != "13" { | |||
t.Errorf("Build number annotation value %s does not match expected value 13", build.Annotations[buildapi.BuildNumberAnnotation]) | |||
} | |||
if len(build.OwnerReferences) == 0 { //|| build.OwnerReferences[0].Kind != "BuildConfig" || build.OwnerReferences[0].Name != bc.Name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think testing all the fields is probably a good plan.
@jim-minter Implemented your requests. |
lgtm - squash & then good to go. |
lgtm, will merge after 3.5 branch is created. |
Squashed |
[merge] |
Evaluated for origin merge up to 8c0f0b0 |
[Test]ing while waiting on the merge queue |
Evaluated for origin test up to 8c0f0b0 |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_future/397/) (Base Commit: 2d20080) |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_future/405/) (Base Commit: 20682f2) (Image: devenv-rhel7_5948) |
This is a prelim step to enabling garbage collection instead of reaper code.
@openshift/devex ptal?