Skip to content

Commit 7228cd9

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 d557953 commit 7228cd9

16 files changed

Lines changed: 115 additions & 203 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
@@ -604,6 +604,8 @@ string
604604
605605
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
606606
607+
Deprecated: no longer in use.
608+
607609
|`strategy` +
608610
*xref:#_camel_apache_org_v1_BuildStrategy[BuildStrategy]*
609611
|

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
@@ -938,9 +942,10 @@ spec:
938942
Only used for `pod` strategy
939943
type: object
940944
operatorNamespace:
941-
description: The namespace where to run the builder
942-
Pod (must be the same of the operator in charge of
943-
this Build reconciliation).
945+
description: |-
946+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
947+
948+
Deprecated: no longer in use.
944949
type: string
945950
orderStrategy:
946951
description: the build order strategy to adopt
@@ -1019,9 +1024,10 @@ spec:
10191024
Only used for `pod` strategy
10201025
type: object
10211026
operatorNamespace:
1022-
description: The namespace where to run the builder
1023-
Pod (must be the same of the operator in charge of
1024-
this Build reconciliation).
1027+
description: |-
1028+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1029+
1030+
Deprecated: no longer in use.
10251031
type: string
10261032
orderStrategy:
10271033
description: the build order strategy to adopt
@@ -1130,9 +1136,10 @@ spec:
11301136
Only used for `pod` strategy
11311137
type: object
11321138
operatorNamespace:
1133-
description: The namespace where to run the builder
1134-
Pod (must be the same of the operator in charge of
1135-
this Build reconciliation).
1139+
description: |-
1140+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1141+
1142+
Deprecated: no longer in use.
11361143
type: string
11371144
orderStrategy:
11381145
description: the build order strategy to adopt
@@ -1239,9 +1246,10 @@ spec:
12391246
Only used for `pod` strategy
12401247
type: object
12411248
operatorNamespace:
1242-
description: The namespace where to run the builder
1243-
Pod (must be the same of the operator in charge of
1244-
this Build reconciliation).
1249+
description: |-
1250+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1251+
1252+
Deprecated: no longer in use.
12451253
type: string
12461254
orderStrategy:
12471255
description: the build order strategy to adopt
@@ -1863,9 +1871,10 @@ spec:
18631871
Only used for `pod` strategy
18641872
type: object
18651873
operatorNamespace:
1866-
description: The namespace where to run the builder
1867-
Pod (must be the same of the operator in charge of
1868-
this Build reconciliation).
1874+
description: |-
1875+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1876+
1877+
Deprecated: no longer in use.
18691878
type: string
18701879
orderStrategy:
18711880
description: the build order strategy to adopt
@@ -1967,9 +1976,10 @@ spec:
19671976
Only used for `pod` strategy
19681977
type: object
19691978
operatorNamespace:
1970-
description: The namespace where to run the builder
1971-
Pod (must be the same of the operator in charge of
1972-
this Build reconciliation).
1979+
description: |-
1980+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
1981+
1982+
Deprecated: no longer in use.
19731983
type: string
19741984
orderStrategy:
19751985
description: the build order strategy to adopt
@@ -3425,8 +3435,10 @@ spec:
34253435
for `pod` strategy
34263436
type: object
34273437
operatorNamespace:
3428-
description: The namespace where to run the builder Pod (must
3429-
be the same of the operator in charge of this Build reconciliation).
3438+
description: |-
3439+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
3440+
3441+
Deprecated: no longer in use.
34303442
type: string
34313443
orderStrategy:
34323444
description: the build order strategy to adopt
@@ -5903,8 +5915,10 @@ spec:
59035915
for `pod` strategy
59045916
type: object
59055917
operatorNamespace:
5906-
description: The namespace where to run the builder Pod (must
5907-
be the same of the operator in charge of this Build reconciliation).
5918+
description: |-
5919+
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
5920+
5921+
Deprecated: no longer in use.
59085922
type: string
59095923
orderStrategy:
59105924
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_controller_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -82,63 +82,3 @@ func TestReconcileBuild(t *testing.T) {
8282
assert.NotNil(t, updated.Status, "status should not be nil")
8383
assert.NotEmpty(t, updated.Status.Phase, "phase should be set")
8484
}
85-
86-
func TestReconcileBuildNotifyError(t *testing.T) {
87-
ctx := context.TODO()
88-
89-
build := &v1.Build{
90-
TypeMeta: metav1.TypeMeta{
91-
Kind: string("Build"),
92-
},
93-
ObjectMeta: metav1.ObjectMeta{
94-
Name: "test-build",
95-
Namespace: "default",
96-
},
97-
Spec: v1.BuildSpec{
98-
Tasks: []v1.Task{
99-
{
100-
Builder: &v1.BuilderTask{
101-
BaseTask: v1.BaseTask{
102-
Name: "builder",
103-
Configuration: v1.BuildConfiguration{
104-
Strategy: v1.BuildStrategyPod,
105-
},
106-
},
107-
},
108-
},
109-
},
110-
},
111-
Status: v1.BuildStatus{
112-
Phase: v1.BuildPhasePending,
113-
},
114-
}
115-
116-
c, err := internal.NewFakeClient(build)
117-
require.NoError(t, err)
118-
recorder := &internal.FakeRecorder{}
119-
r := &reconcileBuild{
120-
client: c,
121-
reader: c,
122-
recorder: recorder,
123-
}
124-
125-
req := reconcile.Request{
126-
NamespacedName: types.NamespacedName{
127-
Name: "test-build",
128-
Namespace: "default",
129-
},
130-
}
131-
132-
result, err := r.Reconcile(ctx, req)
133-
134-
require.Error(t, err)
135-
assert.Equal(t, reconcile.Result{}, result)
136-
137-
var updated v1.Build
138-
err = c.Get(ctx, req.NamespacedName, &updated)
139-
140-
require.NoError(t, err)
141-
assert.NotNil(t, updated.Status, "status should not be nil")
142-
assert.NotEmpty(t, updated.Status.Phase, "phase should be set")
143-
assert.True(t, recorder.Called)
144-
}

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 & 13 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
)
@@ -74,20 +73,9 @@ func (action *monitorPodAction) Handle(ctx context.Context, build *v1.Build) (*v
7473
switch build.Status.Phase {
7574
case v1.BuildPhasePending:
7675
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 {
76+
if err = controllerutil.SetControllerReference(build, pod, action.client.GetScheme()); err != nil {
8877
return nil, err
8978
}
90-
9179
if err = action.client.Create(ctx, pod); err != nil {
9280
return nil, fmt.Errorf("cannot create build pod: %w", err)
9381
}

0 commit comments

Comments
 (0)