Skip to content

Commit

Permalink
fix(builder): global catalog reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Mar 2, 2023
1 parent 0ccc65a commit 78e13c6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion e2e/commonwithcustominstall/catalog_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestCamelCatalogBuilder(t *testing.T) {

Eventually(CamelCatalog(ns, nonCompatibleCatalogName)).ShouldNot(BeNil())
Eventually(CamelCatalogPhase(ns, nonCompatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseError))
Eventually(CamelCatalogCondition(ns, nonCompatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should(ContainSubstring("Missing base image"))
Eventually(CamelCatalogCondition(ns, nonCompatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should(ContainSubstring("missing base image"))

Eventually(IntegrationKit(ns, name)).ShouldNot(Equal(""))
kitName := IntegrationKit(ns, name)()
Expand Down
12 changes: 12 additions & 0 deletions e2e/commonwithcustominstall/operator_id_filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package commonwithcustominstall
import (
"fmt"
"os"
"strings"
"testing"
"time"

Expand All @@ -35,9 +36,20 @@ import (

. "github.com/apache/camel-k/e2e/support"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util/defaults"
"github.com/apache/camel-k/pkg/util/openshift"
)

func TestOperatorIDCamelCatalogReconciliation(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operator1 := "operator-1"
Expect(KamelInstallWithID(operator1, ns, "--global", "--force").Execute()).To(Succeed())
Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
catalogName := fmt.Sprintf("camel-catalog-%s", strings.ToLower(defaults.DefaultRuntimeVersion))
Eventually(CamelCatalogPhase(ns, catalogName), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady))
})
}

func TestOperatorIDFiltering(t *testing.T) {
RegisterTestingT(t)

Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/integrationkit/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int
buildStrategy = env.BuildStrategy

if buildStrategy == v1.BuildStrategyPod {
// nolint: contextcheck
err = platform.CreateBuilderServiceAccount(env.Ctx, env.Client, env.Platform)
if err != nil {
return nil, errors.Wrap(err, "Error while creating Camel K Builder service account")
Expand All @@ -131,8 +132,9 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int
Annotations: annotations,
},
Spec: v1.BuildSpec{
Strategy: buildStrategy,
ToolImage: env.CamelCatalog.Image,
Strategy: buildStrategy,
ToolImage: env.CamelCatalog.Image,
// TODO try to use platform.GetOperatorNamespace
OperatorNamespace: kubernetes.CurrentPodNamespace(),
Tasks: env.BuildTasks,
Timeout: timeout,
Expand Down
9 changes: 8 additions & 1 deletion pkg/controller/integrationplatform/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"

corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/install"
Expand Down Expand Up @@ -54,7 +55,13 @@ func (action *createAction) Handle(ctx context.Context, platform *v1.Integration

for _, k := range paths {
action.L.Infof("Installing camel catalog: %s", k)
err := install.Resources(ctx, action.client, platform.Namespace, true, install.IdentityResourceCustomizer, k)
err := install.Resources(ctx, action.client, platform.Namespace, true,
func(object ctrl.Object) ctrl.Object {
action.L.Infof("Copying platform annotations to catalog: %s", object.GetName())
object.SetAnnotations(platform.Annotations)
return object
},
k)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/resources/resources.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/util/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ToYAMLNoManagedFields(value runtime.Object) ([]byte, error) {
return util.MapToYAML(mapdata)
}

// CurrentPodNamespace return the Kubernetes namespace on which the caller of this funcion is running
// CurrentPodNamespace return the Kubernetes namespace on which the caller of this funcion is running.
func CurrentPodNamespace() string {
ns, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions resources/builder/builder-role-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ metadata:
labels:
app: "camel-k"
subjects:
# TODO set the camel k builder SA with operator namespace
# - kind: ServiceAccount
# name: camel-k-builder
# TODO set the camel k builder SA with operator namespace
# - kind: ServiceAccount
# name: camel-k-builder
- apiGroup: rbac.authorization.k8s.io
kind: Group
name: system:authenticated
Expand Down

0 comments on commit 78e13c6

Please sign in to comment.