Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ string

The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.

|`strategy` +
*xref:#_camel_apache_org_v1_BuildStrategy[BuildStrategy]*
|
Expand Down
74 changes: 44 additions & 30 deletions helm/camel-k/crds/camel-k-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ spec:
for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder Pod (must
be the same of the operator in charge of this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -198,9 +200,10 @@ spec:
Only used for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder
Pod (must be the same of the operator in charge of
this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -308,9 +311,10 @@ spec:
Only used for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder
Pod (must be the same of the operator in charge of
this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -938,9 +942,10 @@ spec:
Only used for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder
Pod (must be the same of the operator in charge of
this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -1019,9 +1024,10 @@ spec:
Only used for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder
Pod (must be the same of the operator in charge of
this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -1130,9 +1136,10 @@ spec:
Only used for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder
Pod (must be the same of the operator in charge of
this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -1239,9 +1246,10 @@ spec:
Only used for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder
Pod (must be the same of the operator in charge of
this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -1863,9 +1871,10 @@ spec:
Only used for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder
Pod (must be the same of the operator in charge of
this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -1967,9 +1976,10 @@ spec:
Only used for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder
Pod (must be the same of the operator in charge of
this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -3425,8 +3435,10 @@ spec:
for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder Pod (must
be the same of the operator in charge of this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down Expand Up @@ -5903,8 +5915,10 @@ spec:
for `pod` strategy
type: object
operatorNamespace:
description: The namespace where to run the builder Pod (must
be the same of the operator in charge of this Build reconciliation).
description: |-
The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).

Deprecated: no longer in use.
type: string
orderStrategy:
description: the build order strategy to adopt
Expand Down
11 changes: 0 additions & 11 deletions pkg/apis/camel/v1/build_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ func NewBuild(namespace string, name string) *Build {
}
}

// BuilderPodNamespace returns the namespace of the operator in charge to reconcile this Build.
func (build *Build) BuilderPodNamespace() string {
for _, t := range build.Spec.Tasks {
if t.Builder != nil {
return t.Builder.Configuration.BuilderPodNamespace
}
}

return ""
}

// BuilderConfiguration returns the builder configuration for this Build.
func (build *Build) BuilderConfiguration() *BuildConfiguration {
return build.TaskConfiguration("builder")
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/camel/v1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ type BuildConfiguration struct {
// The container image to be used to run the build.
ToolImage string `json:"toolImage,omitempty"`
// The namespace where to run the builder Pod (must be the same of the operator in charge of this Build reconciliation).
BuilderPodNamespace string `json:"operatorNamespace,omitempty"`
//
// Deprecated: no longer in use.
DeprecatedBuilderPodNamespace string `json:"operatorNamespace,omitempty"`
// the strategy to adopt
Strategy BuildStrategy `json:"strategy,omitempty" property:"strategy"`
// the build order strategy to adopt
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 0 additions & 60 deletions pkg/controller/build/build_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,63 +82,3 @@ func TestReconcileBuild(t *testing.T) {
assert.NotNil(t, updated.Status, "status should not be nil")
assert.NotEmpty(t, updated.Status.Phase, "phase should be set")
}

func TestReconcileBuildNotifyError(t *testing.T) {
ctx := context.TODO()

build := &v1.Build{
TypeMeta: metav1.TypeMeta{
Kind: string("Build"),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-build",
Namespace: "default",
},
Spec: v1.BuildSpec{
Tasks: []v1.Task{
{
Builder: &v1.BuilderTask{
BaseTask: v1.BaseTask{
Name: "builder",
Configuration: v1.BuildConfiguration{
Strategy: v1.BuildStrategyPod,
},
},
},
},
},
},
Status: v1.BuildStatus{
Phase: v1.BuildPhasePending,
},
}

c, err := internal.NewFakeClient(build)
require.NoError(t, err)
recorder := &internal.FakeRecorder{}
r := &reconcileBuild{
client: c,
reader: c,
recorder: recorder,
}

req := reconcile.Request{
NamespacedName: types.NamespacedName{
Name: "test-build",
Namespace: "default",
},
}

result, err := r.Reconcile(ctx, req)

require.Error(t, err)
assert.Equal(t, reconcile.Result{}, result)

var updated v1.Build
err = c.Get(ctx, req.NamespacedName, &updated)

require.NoError(t, err)
assert.NotNil(t, updated.Status, "status should not be nil")
assert.NotEmpty(t, updated.Status.Phase, "phase should be set")
assert.True(t, recorder.Called)
}
7 changes: 3 additions & 4 deletions pkg/controller/build/build_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,9 @@ func newBuildWithLayoutInPhase(namespace string, name string, layout string, pha
Builder: &v1.BuilderTask{
BaseTask: v1.BaseTask{
Configuration: v1.BuildConfiguration{
Strategy: v1.BuildStrategyRoutine,
OrderStrategy: v1.BuildOrderStrategySequential,
ToolImage: "camel:latest",
BuilderPodNamespace: "ns",
Strategy: v1.BuildStrategyRoutine,
OrderStrategy: v1.BuildOrderStrategySequential,
ToolImage: "camel:latest",
},
},
Dependencies: dependencies,
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/build/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func newBuildPod(ctx context.Context, client client.Client, build *v1.Build) *co
// get pod security context from security context constraint configuration in namespace
//nolint:staticcheck
if task.S2i != nil {
podSecurityContextConstrained, _ := openshift.GetOpenshiftPodSecurityContextRestricted(ctx, client, build.BuilderPodNamespace())
podSecurityContextConstrained, _ := openshift.GetOpenshiftPodSecurityContextRestricted(ctx, client, build.Namespace)
if podSecurityContextConstrained != nil {
podSecurityContext = podSecurityContextConstrained
}
Expand All @@ -62,7 +62,7 @@ func newBuildPod(ctx context.Context, client client.Client, build *v1.Build) *co
Kind: "Pod",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: build.BuilderPodNamespace(),
Namespace: build.Namespace,
Name: buildPodName(build),
Labels: map[string]string{
"camel.apache.org/build": build.Name,
Expand Down Expand Up @@ -151,7 +151,7 @@ func deleteBuilderPod(ctx context.Context, c ctrl.Writer, build *v1.Build) error
Kind: "Pod",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: build.BuilderPodNamespace(),
Namespace: build.Namespace,
Name: buildPodName(build),
},
}
Expand All @@ -166,7 +166,7 @@ func deleteBuilderPod(ctx context.Context, c ctrl.Writer, build *v1.Build) error

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

// get security context from security context constraint configuration in namespace
if taskName == "s2i" {
securityContextConstrained, _ := openshift.GetOpenshiftSecurityContextRestricted(ctx, client, build.BuilderPodNamespace())
securityContextConstrained, _ := openshift.GetOpenshiftSecurityContextRestricted(ctx, client, build.Namespace)
if securityContextConstrained != nil {
container.SecurityContext = securityContextConstrained
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/build/build_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func TestNewBuildPodConfiguration(t *testing.T) {

build := v1.Build{
ObjectMeta: metav1.ObjectMeta{
Name: "theBuildName",
Name: "theBuildName",
Namespace: "theNamespace",
},
Spec: v1.BuildSpec{
Tasks: []v1.Task{
Expand All @@ -44,9 +45,8 @@ func TestNewBuildPodConfiguration(t *testing.T) {
BaseTask: v1.BaseTask{
Name: "builder",
Configuration: v1.BuildConfiguration{
BuilderPodNamespace: "theNamespace",
NodeSelector: map[string]string{"node": "selector"},
Annotations: map[string]string{"annotation": "value"},
NodeSelector: map[string]string{"node": "selector"},
Annotations: map[string]string{"annotation": "value"},
},
},
},
Expand Down
15 changes: 1 addition & 14 deletions pkg/controller/build/monitor_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/platform"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
"github.com/apache/camel-k/v2/pkg/util/kubernetes/log"
)
Expand Down Expand Up @@ -69,25 +68,13 @@ func (action *monitorPodAction) Handle(ctx context.Context, build *v1.Build) (*v
return nil, err
}

//nolint:nestif
if pod == nil {
switch build.Status.Phase {
case v1.BuildPhasePending:
pod = newBuildPod(ctx, action.client, build)
// If the Builder Pod is in the Build namespace, we can set the ownership to it. If not (global operator mode)
// we set the ownership to the Operator Pod instead
var owner metav1.Object
owner = build
if build.Namespace != pod.Namespace {
operatorPod := platform.GetOperatorPod(ctx, action.client, pod.Namespace)
if operatorPod != nil {
owner = operatorPod
}
}
if err = controllerutil.SetControllerReference(owner, pod, action.client.GetScheme()); err != nil {
if err = controllerutil.SetControllerReference(build, pod, action.client.GetScheme()); err != nil {
return nil, err
}

if err = action.client.Create(ctx, pod); err != nil {
return nil, fmt.Errorf("cannot create build pod: %w", err)
}
Expand Down
Loading
Loading