Skip to content

Commit 222cdbd

Browse files
committed
feat(api): deprecate builder pod namespace
It is no longer needed as we can infer it from the Build custom resource
1 parent c715d99 commit 222cdbd

15 files changed

Lines changed: 115 additions & 144 deletions

File tree

docs/modules/ROOT/partials/apis/camel-k-crds.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ string
602602
603603
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
604604
605+
Deprecated: no longer in use.
606+
605607
|`strategy` +
606608
*xref:#_camel_apache_org_v1_BuildStrategy[BuildStrategy]*
607609
|

helm/camel-k/crds/camel-k-crds.yaml

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ spec:
111111
for `pod` strategy
112112
type: object
113113
operatorNamespace:
114-
description: The namespace where to run the builder Pod (must
115-
be the same of the operator in charge of this Build reconciliation).
114+
description: |-
115+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
116+
117+
Deprecated: no longer in use.
116118
type: string
117119
orderStrategy:
118120
description: the build order strategy to adopt
@@ -198,9 +200,10 @@ spec:
198200
Only used for `pod` strategy
199201
type: object
200202
operatorNamespace:
201-
description: The namespace where to run the builder
202-
Pod (must be the same of the operator in charge of
203-
this Build reconciliation).
203+
description: |-
204+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
205+
206+
Deprecated: no longer in use.
204207
type: string
205208
orderStrategy:
206209
description: the build order strategy to adopt
@@ -308,9 +311,10 @@ spec:
308311
Only used for `pod` strategy
309312
type: object
310313
operatorNamespace:
311-
description: The namespace where to run the builder
312-
Pod (must be the same of the operator in charge of
313-
this Build reconciliation).
314+
description: |-
315+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
316+
317+
Deprecated: no longer in use.
314318
type: string
315319
orderStrategy:
316320
description: the build order strategy to adopt
@@ -937,9 +941,10 @@ spec:
937941
Only used for `pod` strategy
938942
type: object
939943
operatorNamespace:
940-
description: The namespace where to run the builder
941-
Pod (must be the same of the operator in charge of
942-
this Build reconciliation).
944+
description: |-
945+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
946+
947+
Deprecated: no longer in use.
943948
type: string
944949
orderStrategy:
945950
description: the build order strategy to adopt
@@ -1018,9 +1023,10 @@ spec:
10181023
Only used for `pod` strategy
10191024
type: object
10201025
operatorNamespace:
1021-
description: The namespace where to run the builder
1022-
Pod (must be the same of the operator in charge of
1023-
this Build reconciliation).
1026+
description: |-
1027+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1028+
1029+
Deprecated: no longer in use.
10241030
type: string
10251031
orderStrategy:
10261032
description: the build order strategy to adopt
@@ -1129,9 +1135,10 @@ spec:
11291135
Only used for `pod` strategy
11301136
type: object
11311137
operatorNamespace:
1132-
description: The namespace where to run the builder
1133-
Pod (must be the same of the operator in charge of
1134-
this Build reconciliation).
1138+
description: |-
1139+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1140+
1141+
Deprecated: no longer in use.
11351142
type: string
11361143
orderStrategy:
11371144
description: the build order strategy to adopt
@@ -1238,9 +1245,10 @@ spec:
12381245
Only used for `pod` strategy
12391246
type: object
12401247
operatorNamespace:
1241-
description: The namespace where to run the builder
1242-
Pod (must be the same of the operator in charge of
1243-
this Build reconciliation).
1248+
description: |-
1249+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1250+
1251+
Deprecated: no longer in use.
12441252
type: string
12451253
orderStrategy:
12461254
description: the build order strategy to adopt
@@ -1861,9 +1869,10 @@ spec:
18611869
Only used for `pod` strategy
18621870
type: object
18631871
operatorNamespace:
1864-
description: The namespace where to run the builder
1865-
Pod (must be the same of the operator in charge of
1866-
this Build reconciliation).
1872+
description: |-
1873+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1874+
1875+
Deprecated: no longer in use.
18671876
type: string
18681877
orderStrategy:
18691878
description: the build order strategy to adopt
@@ -1965,9 +1974,10 @@ spec:
19651974
Only used for `pod` strategy
19661975
type: object
19671976
operatorNamespace:
1968-
description: The namespace where to run the builder
1969-
Pod (must be the same of the operator in charge of
1970-
this Build reconciliation).
1977+
description: |-
1978+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1979+
1980+
Deprecated: no longer in use.
19711981
type: string
19721982
orderStrategy:
19731983
description: the build order strategy to adopt
@@ -3418,8 +3428,10 @@ spec:
34183428
for `pod` strategy
34193429
type: object
34203430
operatorNamespace:
3421-
description: The namespace where to run the builder Pod (must
3422-
be the same of the operator in charge of this Build reconciliation).
3431+
description: |-
3432+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
3433+
3434+
Deprecated: no longer in use.
34233435
type: string
34243436
orderStrategy:
34253437
description: the build order strategy to adopt
@@ -5895,8 +5907,10 @@ spec:
58955907
for `pod` strategy
58965908
type: object
58975909
operatorNamespace:
5898-
description: The namespace where to run the builder Pod (must
5899-
be the same of the operator in charge of this Build reconciliation).
5910+
description: |-
5911+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
5912+
5913+
Deprecated: no longer in use.
59005914
type: string
59015915
orderStrategy:
59025916
description: the build order strategy to adopt

pkg/apis/camel/v1/build_types_support.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ func NewBuild(namespace string, name string) *Build {
3838
}
3939
}
4040

41-
// BuilderPodNamespace returns the namespace of the operator in charge to reconcile this Build.
42-
func (build *Build) BuilderPodNamespace() string {
43-
for _, t := range build.Spec.Tasks {
44-
if t.Builder != nil {
45-
return t.Builder.Configuration.BuilderPodNamespace
46-
}
47-
}
48-
49-
return ""
50-
}
51-
5241
// BuilderConfiguration returns the builder configuration for this Build.
5342
func (build *Build) BuilderConfiguration() *BuildConfiguration {
5443
return build.TaskConfiguration("builder")

pkg/apis/camel/v1/common_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ type BuildConfiguration struct {
4949
// The container image to be used to run the build.
5050
ToolImage string `json:"toolImage,omitempty"`
5151
// The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
52-
BuilderPodNamespace string `json:"operatorNamespace,omitempty"`
52+
//
53+
// Deprecated: no longer in use.
54+
DeprecatedBuilderPodNamespace string `json:"operatorNamespace,omitempty"`
5355
// the strategy to adopt
5456
Strategy BuildStrategy `json:"strategy,omitempty" property:"strategy"`
5557
// the build order strategy to adopt

pkg/client/camel/applyconfiguration/camel/v1/buildconfiguration.go

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/build/build_monitor_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,9 @@ func newBuildWithLayoutInPhase(namespace string, name string, layout string, pha
685685
Builder: &v1.BuilderTask{
686686
BaseTask: v1.BaseTask{
687687
Configuration: v1.BuildConfiguration{
688-
Strategy: v1.BuildStrategyRoutine,
689-
OrderStrategy: v1.BuildOrderStrategySequential,
690-
ToolImage: "camel:latest",
691-
BuilderPodNamespace: "ns",
688+
Strategy: v1.BuildStrategyRoutine,
689+
OrderStrategy: v1.BuildOrderStrategySequential,
690+
ToolImage: "camel:latest",
692691
},
693692
},
694693
Dependencies: dependencies,

pkg/controller/build/build_pod.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func newBuildPod(ctx context.Context, client client.Client, build *v1.Build) *co
5050
// get pod security context from security context constraint configuration in namespace
5151
//nolint:staticcheck
5252
if task.S2i != nil {
53-
podSecurityContextConstrained, _ := openshift.GetOpenshiftPodSecurityContextRestricted(ctx, client, build.BuilderPodNamespace())
53+
podSecurityContextConstrained, _ := openshift.GetOpenshiftPodSecurityContextRestricted(ctx, client, build.Namespace)
5454
if podSecurityContextConstrained != nil {
5555
podSecurityContext = podSecurityContextConstrained
5656
}
@@ -62,7 +62,7 @@ func newBuildPod(ctx context.Context, client client.Client, build *v1.Build) *co
6262
Kind: "Pod",
6363
},
6464
ObjectMeta: metav1.ObjectMeta{
65-
Namespace: build.BuilderPodNamespace(),
65+
Namespace: build.Namespace,
6666
Name: buildPodName(build),
6767
Labels: map[string]string{
6868
"camel.apache.org/build": build.Name,
@@ -151,7 +151,7 @@ func deleteBuilderPod(ctx context.Context, c ctrl.Writer, build *v1.Build) error
151151
Kind: "Pod",
152152
},
153153
ObjectMeta: metav1.ObjectMeta{
154-
Namespace: build.BuilderPodNamespace(),
154+
Namespace: build.Namespace,
155155
Name: buildPodName(build),
156156
},
157157
}
@@ -166,7 +166,7 @@ func deleteBuilderPod(ctx context.Context, c ctrl.Writer, build *v1.Build) error
166166

167167
func getBuilderPod(ctx context.Context, c ctrl.Reader, build *v1.Build) (*corev1.Pod, error) {
168168
pod := corev1.Pod{}
169-
err := c.Get(ctx, ctrl.ObjectKey{Namespace: build.BuilderPodNamespace(), Name: buildPodName(build)}, &pod)
169+
err := c.Get(ctx, ctrl.ObjectKey{Namespace: build.Namespace, Name: buildPodName(build)}, &pod)
170170
if err != nil && k8serrors.IsNotFound(err) {
171171
return nil, nil
172172
}
@@ -222,7 +222,7 @@ func addBuildTaskToPod(ctx context.Context, client client.Client, build *v1.Buil
222222

223223
// get security context from security context constraint configuration in namespace
224224
if taskName == "s2i" {
225-
securityContextConstrained, _ := openshift.GetOpenshiftSecurityContextRestricted(ctx, client, build.BuilderPodNamespace())
225+
securityContextConstrained, _ := openshift.GetOpenshiftSecurityContextRestricted(ctx, client, build.Namespace)
226226
if securityContextConstrained != nil {
227227
container.SecurityContext = securityContextConstrained
228228
}

pkg/controller/build/build_pod_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ func TestNewBuildPodConfiguration(t *testing.T) {
3535

3636
build := v1.Build{
3737
ObjectMeta: metav1.ObjectMeta{
38-
Name: "theBuildName",
38+
Name: "theBuildName",
39+
Namespace: "theNamespace",
3940
},
4041
Spec: v1.BuildSpec{
4142
Tasks: []v1.Task{
@@ -44,9 +45,8 @@ func TestNewBuildPodConfiguration(t *testing.T) {
4445
BaseTask: v1.BaseTask{
4546
Name: "builder",
4647
Configuration: v1.BuildConfiguration{
47-
BuilderPodNamespace: "theNamespace",
48-
NodeSelector: map[string]string{"node": "selector"},
49-
Annotations: map[string]string{"annotation": "value"},
48+
NodeSelector: map[string]string{"node": "selector"},
49+
Annotations: map[string]string{"annotation": "value"},
5050
},
5151
},
5252
},

pkg/controller/build/monitor_pod.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3434

3535
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
36-
"github.com/apache/camel-k/v2/pkg/platform"
3736
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
3837
"github.com/apache/camel-k/v2/pkg/util/kubernetes/log"
3938
)
@@ -69,25 +68,13 @@ func (action *monitorPodAction) Handle(ctx context.Context, build *v1.Build) (*v
6968
return nil, err
7069
}
7170

72-
//nolint:nestif
7371
if pod == nil {
7472
switch build.Status.Phase {
7573
case v1.BuildPhasePending:
7674
pod = newBuildPod(ctx, action.client, build)
77-
// If the Builder Pod is in the Build namespace, we can set the ownership to it. If not (global operator mode)
78-
// we set the ownership to the Operator Pod instead
79-
var owner metav1.Object
80-
owner = build
81-
if build.Namespace != pod.Namespace {
82-
operatorPod := platform.GetOperatorPod(ctx, action.client, pod.Namespace)
83-
if operatorPod != nil {
84-
owner = operatorPod
85-
}
86-
}
87-
if err = controllerutil.SetControllerReference(owner, pod, action.client.GetScheme()); err != nil {
75+
if err = controllerutil.SetControllerReference(build, pod, action.client.GetScheme()); err != nil {
8876
return nil, err
8977
}
90-
9178
if err = action.client.Create(ctx, pod); err != nil {
9279
return nil, fmt.Errorf("cannot create build pod: %w", err)
9380
}

pkg/controller/build/monitor_pod_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ func TestHandle_PodSucceeded(t *testing.T) {
4747
Tasks: []v1.Task{
4848
{
4949
Custom: &v1.UserTask{
50-
BaseTask: v1.BaseTask{
51-
Configuration: v1.BuildConfiguration{
52-
BuilderPodNamespace: "default",
53-
},
54-
},
5550
PublishingImage: "my-camel-k-container-image",
5651
},
5752
},
@@ -66,7 +61,7 @@ func TestHandle_PodSucceeded(t *testing.T) {
6661
pod := &corev1.Pod{
6762
ObjectMeta: metav1.ObjectMeta{
6863
Name: buildPodName(build),
69-
Namespace: build.BuilderPodNamespace(),
64+
Namespace: build.Namespace,
7065
Annotations: map[string]string{},
7166
},
7267
Status: corev1.PodStatus{
@@ -118,11 +113,6 @@ func TestHandle_PodFailed(t *testing.T) {
118113
Tasks: []v1.Task{
119114
{
120115
Custom: &v1.UserTask{
121-
BaseTask: v1.BaseTask{
122-
Configuration: v1.BuildConfiguration{
123-
BuilderPodNamespace: "default",
124-
},
125-
},
126116
PublishingImage: "my-camel-k-container-image",
127117
},
128118
},
@@ -137,7 +127,7 @@ func TestHandle_PodFailed(t *testing.T) {
137127
pod := &corev1.Pod{
138128
ObjectMeta: metav1.ObjectMeta{
139129
Name: buildPodName(build),
140-
Namespace: build.BuilderPodNamespace(),
130+
Namespace: build.Namespace,
141131
Annotations: map[string]string{},
142132
},
143133
Status: corev1.PodStatus{

0 commit comments

Comments
 (0)