-
Notifications
You must be signed in to change notification settings - Fork 113
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
625 user control over pod labels #1069
Changes from all commits
2c4a54d
7bf1778
2f5d613
7104eb4
46dd7c8
89ed08d
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 |
---|---|---|
|
@@ -273,3 +273,8 @@ type BuildRetention struct { | |
func init() { | ||
SchemeBuilder.Register(&Build{}, &BuildList{}) | ||
} | ||
|
||
// GetLabels returns the labels of the Build | ||
func (b Build) GetLabels() map[string]string { | ||
return b.Labels | ||
} | ||
Comment on lines
+278
to
+280
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 don't think this is needed because Kubernetes already provides that function on |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,6 +272,11 @@ func (br *BuildRun) IsCanceled() bool { | |
return br.Spec.State != nil && *br.Spec.State == BuildRunStateCancel | ||
} | ||
|
||
// GetLabels returns the labels of the BuildRun | ||
func (br *BuildRun) GetLabels() map[string]string { | ||
return br.Labels | ||
} | ||
Comment on lines
+275
to
+278
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 don't think this is needed because Kubernetes already provides that function on |
||
|
||
// Conditions defines a list of Condition | ||
type Conditions []Condition | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,11 @@ func (s BuildStrategy) GetVolumes() []BuildStrategyVolume { | |
return s.Spec.Volumes | ||
} | ||
|
||
// GetLabels returns the labels the build strategy | ||
func (s BuildStrategy) GetLabels() map[string]string { | ||
return s.Labels | ||
} | ||
Comment on lines
+87
to
+90
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 don't think this is needed because Kubernetes already provides that function on |
||
|
||
func init() { | ||
SchemeBuilder.Register(&BuildStrategy{}, &BuildStrategyList{}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,11 @@ func (s ClusterBuildStrategy) GetVolumes() []BuildStrategyVolume { | |
return s.Spec.Volumes | ||
} | ||
|
||
// GetLabels returns the labels of the build strategy | ||
func (s ClusterBuildStrategy) GetLabels() map[string]string { | ||
return s.Labels | ||
} | ||
Comment on lines
+88
to
+91
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 don't think this is needed because Kubernetes already provides that function on |
||
|
||
func init() { | ||
SchemeBuilder.Register(&ClusterBuildStrategy{}, &ClusterBuildStrategyList{}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ package resources | |
import ( | ||
"fmt" | ||
"path" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
|
||
|
@@ -35,12 +36,13 @@ const ( | |
inputParamContextDir = "CONTEXT_DIR" | ||
|
||
imageMutateContainerName = "mutate-image" | ||
|
||
reservedLabels = `([a-z0-9]+\.)*(kubernetes.io|k8s.io|tekton.dev|shipwright.io)` | ||
) | ||
|
||
// getStringTransformations gets us MANDATORY replacements using | ||
// a poor man's templating mechanism - TODO: Use golang templating | ||
func getStringTransformations(fullText string) string { | ||
|
||
stringTransformations := map[string]string{ | ||
// this will be removed, build strategy author should use $(params.shp-output-image) directly | ||
"$(build.output.image)": fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramOutputImage), | ||
|
@@ -69,7 +71,6 @@ func GenerateTaskSpec( | |
parameterDefinitions []buildv1alpha1.Parameter, | ||
buildStrategyVolumes []buildv1alpha1.BuildStrategyVolume, | ||
) (*v1beta1.TaskSpec, error) { | ||
|
||
generatedTaskSpec := v1beta1.TaskSpec{ | ||
Params: []v1beta1.ParamSpec{ | ||
{ | ||
|
@@ -255,7 +256,6 @@ func GenerateTaskRun( | |
serviceAccountName string, | ||
strategy buildv1alpha1.BuilderStrategy, | ||
) (*v1beta1.TaskRun, error) { | ||
|
||
// retrieve expected imageURL form build or buildRun | ||
var image string | ||
if buildRun.Spec.Output != nil { | ||
|
@@ -322,6 +322,32 @@ func GenerateTaskRun( | |
expectedTaskRun.Labels[label] = value | ||
} | ||
|
||
reserved, err := regexp.Compile(reservedLabels) | ||
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. The regular expression should be compiled only once. |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// assign labels from the build strategy, filter out those that should not be propagated | ||
for key, value := range strategy.GetLabels() { | ||
if !reserved.MatchString(value) { | ||
expectedTaskRun.Labels[key] = value | ||
} | ||
} | ||
|
||
// assign labels from the build, filter out those that should not be propagated | ||
for key, value := range build.GetLabels() { | ||
if !reserved.MatchString(value) { | ||
expectedTaskRun.Labels[key] = value | ||
} | ||
} | ||
|
||
// assign labels from the buildrun, filter out those that should not be propagated | ||
for key, value := range buildRun.GetLabels() { | ||
if !reserved.MatchString(value) { | ||
expectedTaskRun.Labels[key] = value | ||
} | ||
} | ||
|
||
expectedTaskRun.Spec.Timeout = effectiveTimeout(build, buildRun) | ||
|
||
params := []v1beta1.Param{ | ||
|
@@ -409,7 +435,6 @@ func GenerateTaskRun( | |
func effectiveTimeout(build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) *metav1.Duration { | ||
if buildRun.Spec.Timeout != nil { | ||
return buildRun.Spec.Timeout | ||
|
||
} else if build.Spec.Timeout != nil { | ||
return build.Spec.Timeout | ||
} | ||
|
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.
Please mention here that annotations cannot be overriden.