-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Propagate labels from PipelineRun to TaskRun to Pods #488
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ import ( | |
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/kubernetes" | ||
|
||
"github.com/knative/build-pipeline/pkg/credentials" | ||
|
@@ -220,6 +219,14 @@ func MakePod(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po | |
} | ||
annotations["sidecar.istio.io/inject"] = "false" | ||
|
||
labels := map[string]string{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Similar to pipelinerun pattern of adding label this could be similar to |
||
for key, val := range build.ObjectMeta.Labels { | ||
labels[key] = val | ||
} | ||
// TODO: Redundant with TaskRun label set in `taskrun.makeLabels`. Should | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we need to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following up with this is #494. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think there is no value in adding buildName label anymore.
I like this idea
👍 |
||
// probably be removed once we translate from TaskRun to Pod directly. | ||
labels[buildNameLabelKey] = build.Name | ||
|
||
cred, secrets, err := makeCredentialInitializer(build, kubeclient) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -298,18 +305,10 @@ func MakePod(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po | |
// is deleted and re-created with the same name. | ||
// We don't use GenerateName here because k8s fakes don't support it. | ||
Name: fmt.Sprintf("%s-pod-%s", build.Name, gibberish), | ||
// If our parent Build is deleted, then we should be as well. | ||
OwnerReferences: []metav1.OwnerReference{ | ||
*metav1.NewControllerRef(build, schema.GroupVersionKind{ | ||
Group: v1alpha1.SchemeGroupVersion.Group, | ||
Version: v1alpha1.SchemeGroupVersion.Version, | ||
Kind: "Build", | ||
}), | ||
}, | ||
// If our parent TaskRun is deleted, then we should be as well. | ||
OwnerReferences: build.OwnerReferences, | ||
Annotations: annotations, | ||
Labels: map[string]string{ | ||
buildNameLabelKey: build.Name, | ||
}, | ||
Labels: labels, | ||
}, | ||
Spec: corev1.PodSpec{ | ||
// If the build fails, don't restart it. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,14 +430,6 @@ func (c *Reconciler) createBuildPod(ctx context.Context, tr *v1alpha1.TaskRun, t | |
return nil, fmt.Errorf("translating Build to Pod: %v", err) | ||
} | ||
|
||
// Rewrite the pod's OwnerRef to point the TaskRun, instead of a | ||
// non-existent build. | ||
// TODO(jasonhall): Just set this directly when creating a Pod from a | ||
// TaskRun. | ||
pod.OwnerReferences = []metav1.OwnerReference{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the MakePod function is not used at all right now. We still rely on the knative/build API to create a Build instead of using the MakePod above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, maybe I am misunderstanding something. As far as I can tell, we are import the resources package containing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tejal29 : @imjasonh submitted PR to remove dependency on Build API. Currently there is code dependency but TaskRun is not creating Build CRD object anymore. @dwnusbaum : There is no need for maintaining code similarity with Build code base. If it makes sense to pull the logic into separate function then please feel free to do so. |
||
*metav1.NewControllerRef(tr, groupVersionKind), | ||
} | ||
|
||
return c.KubeClientSet.CoreV1().Pods(tr.Namespace).Create(pod) | ||
} | ||
|
||
|
@@ -488,10 +480,10 @@ func createRedirectedBuild(ctx context.Context, bs *buildv1alpha1.BuildSpec, tr | |
// makeLabels constructs the labels we will apply to TaskRun resources. | ||
func makeLabels(s *v1alpha1.TaskRun) map[string]string { | ||
labels := make(map[string]string, len(s.ObjectMeta.Labels)+1) | ||
labels[pipeline.GroupName+pipeline.TaskRunLabelKey] = s.Name | ||
for k, v := range s.ObjectMeta.Labels { | ||
labels[k] = v | ||
} | ||
labels[pipeline.GroupName+pipeline.TaskRunLabelKey] = s.Name | ||
return labels | ||
} | ||
|
||
|
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.
Looks like the keys need to be validated based on my reading of https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/. Will that be handled by Kubernetes itself when the PipelineRun/TaskRun are created, in which case we don't need to do anything since these labels only come from those resources, or do we need to do some validation 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.
yes i am pretty sure, its handled by the kubernetes api and we don't need to do any thing here