You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/07/04 12:19:20 UTC
[camel-k] 09/09: Switch system puller to server or client apply
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit a2562649700943e1a9c0a776fb5bcfe6674498f3
Author: phantomjinx <p....@phantomjinx.co.uk>
AuthorDate: Thu Jun 30 21:15:51 2022 +0100
Switch system puller to server or client apply
* Stop 415 error occurring on Openshift 3.11
---
.github/workflows/openshift.yml | 2 +-
pkg/cmd/promote.go | 39 +++++++++++++++++++++++----------------
2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/.github/workflows/openshift.yml b/.github/workflows/openshift.yml
index bdb86e2bc..a9d2eee10 100644
--- a/.github/workflows/openshift.yml
+++ b/.github/workflows/openshift.yml
@@ -99,7 +99,7 @@ jobs:
- id: change-context
name: Change the Kamel Cluster Context to Admin
run: |
- ./.github/actions/kamel-config-cluster/change-context.sh
+ ./.github/actions/kamel-config-cluster/change-context.sh \
-a "${{ steps.config-cluster.outputs.cluster-kube-admin-user-ctx }}"
- name: Run IT 2
diff --git a/pkg/cmd/promote.go b/pkg/cmd/promote.go
index f487ce0a6..c1fb1f3e4 100644
--- a/pkg/cmd/promote.go
+++ b/pkg/cmd/promote.go
@@ -39,8 +39,6 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
-
- rbacv1ac "k8s.io/client-go/applyconfigurations/rbac/v1"
)
var namedConfRegExp = regexp.MustCompile("([a-z0-9-.]+)/.*")
@@ -464,20 +462,29 @@ func editContainerImage(contTrait v1.TraitSpec, image string) (v1.TraitSpec, err
// image cannot be pulled.
//
func addSystemPullerRoleBinding(ctx context.Context, c client.Client, sourceNS string, destNS string) error {
- rb := rbacv1ac.RoleBinding(fmt.Sprintf("%s-image-puller", destNS), sourceNS).
- WithSubjects(
- rbacv1ac.Subject().
- WithKind("ServiceAccount").
- WithNamespace(destNS).
- WithName("default"),
- ).
- WithRoleRef(rbacv1ac.RoleRef().
- WithAPIGroup(rbacv1.GroupName).
- WithKind("ClusterRole").
- WithName("system:image-puller"))
-
- _, err := c.RbacV1().RoleBindings(sourceNS).
- Apply(ctx, rb, metav1.ApplyOptions{FieldManager: "default", Force: true})
+ rb := &rbacv1.RoleBinding{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "RoleBinding",
+ APIVersion: "rbac.authorization.k8s.io/v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: fmt.Sprintf("%s-image-puller", destNS),
+ Namespace: sourceNS,
+ },
+ Subjects: []rbacv1.Subject{
+ {
+ Kind: "ServiceAccount",
+ Name: "default",
+ Namespace: destNS,
+ },
+ },
+ RoleRef: rbacv1.RoleRef{
+ Kind: "ClusterRole",
+ Name: "system:image-puller",
+ },
+ }
+ applier := c.ServerOrClientSideApplier()
+ err := applier.Apply(ctx, rb)
return err
}