Skip to content

Commit

Permalink
Fix apache#2834: support OpenShift defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpoth authored and bouskaJ committed Apr 7, 2022
1 parent 38603e9 commit ad4e6c7
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 75 deletions.
17 changes: 16 additions & 1 deletion config/crd/bases/camel.apache.org_builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ spec:
application build phase
properties:
caSecret:
description: The Secret name and key, containing the
description: The Secrets name and key, containing the
CA certificate(s) used to connect to remote Maven
repositories. It can contain X.509 certificates, and
PKCS#7 formatted certificate chains. A JKS formatted
Expand Down Expand Up @@ -281,6 +281,21 @@ spec:
- url
type: object
type: array
servers:
items:
properties:
configuration:
additionalProperties:
type: string
type: object
id:
type: string
password:
type: string
username:
type: string
type: object
type: array
settings:
description: A reference to the ConfigMap or Secret
key that contains the Maven settings.
Expand Down
33 changes: 32 additions & 1 deletion e2e/registry/registry_maven_wagon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ 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/openshift"
)

func TestImageRegistryIsAMavenRepository(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
if ocp {
t.Skip("Avoid running on OpenShift until CA and secret are injected client side")
return
}
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())

// Create integration that should decrypt foobar and log it
Expand Down Expand Up @@ -65,7 +72,13 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) {

func TestLocalFilesAreMountedInContainerInDefaultPath(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
// Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
if ocp {
t.Skip("Avoid running on OpenShift until CA and secret are injected client side")
return
}
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
name := "laughing-route-default-path"

Expect(Kamel("run", "files/LaughingRoute.java",
Expand All @@ -86,6 +99,12 @@ func TestLocalFilesAreMountedInContainerInDefaultPath(t *testing.T) {

func TestLocalFilesAreMountedInContainerInCustomPath(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
if ocp {
t.Skip("Avoid running on OpenShift until CA and secret are injected client side")
return
}
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
name := "laughing-route-custom-path"
customPath := "this/is/a/custom/path/"
Expand All @@ -108,6 +127,12 @@ func TestLocalFilesAreMountedInContainerInCustomPath(t *testing.T) {

func TestLocalDirectoryIsMountedInContainer(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
if ocp {
t.Skip("Avoid running on OpenShift until CA and secret are injected client side")
return
}
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
name := "laughing-route-directory"

Expand All @@ -130,6 +155,12 @@ func TestLocalDirectoryIsMountedInContainer(t *testing.T) {

func TestExtractPomFromJar(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
if ocp {
t.Skip("Avoid running on OpenShift until CA and secret are injected client side")
return
}
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())

// Create integration that should decrypt foobar and log it
Expand Down
17 changes: 16 additions & 1 deletion helm/camel-k/crds/crd-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ spec:
application build phase
properties:
caSecret:
description: The Secret name and key, containing the
description: The Secrets name and key, containing the
CA certificate(s) used to connect to remote Maven
repositories. It can contain X.509 certificates, and
PKCS#7 formatted certificate chains. A JKS formatted
Expand Down Expand Up @@ -281,6 +281,21 @@ spec:
- url
type: object
type: array
servers:
items:
properties:
configuration:
additionalProperties:
type: string
type: object
id:
type: string
password:
type: string
username:
type: string
type: object
type: array
settings:
description: A reference to the ConfigMap or Secret
key that contains the Maven settings.
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/camel/v1/maven_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type MavenArtifact struct {
}

type Server struct {
XMLName xml.Name `xml:"server"`
XMLName xml.Name `xml:"server" json:"-"`
ID string `xml:"id,omitempty" json:"id,omitempty"`
Username string `xml:"username,omitempty" json:"username,omitempty"`
Password string `xml:"password,omitempty" json:"password,omitempty"`
Expand Down
32 changes: 16 additions & 16 deletions pkg/platform/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func ConfigureDefaults(ctx context.Context, c client.Client, p *v1.IntegrationPl
}

if p.Status.Build.BuildStrategy == v1.BuildStrategyPod {
if err := createBuilderServiceAccount(ctx, c, p); err != nil {
if err := CreateBuilderServiceAccount(ctx, c, p); err != nil {
return errors.Wrap(err, "cannot ensure service account is present")
}
}
Expand All @@ -112,6 +112,21 @@ func ConfigureDefaults(ctx context.Context, c client.Client, p *v1.IntegrationPl
return nil
}

func CreateBuilderServiceAccount(ctx context.Context, client client.Client, p *v1.IntegrationPlatform) error {
sa := corev1.ServiceAccount{}
key := ctrl.ObjectKey{
Name: BuilderServiceAccount,
Namespace: p.Namespace,
}

err := client.Get(ctx, key, &sa)
if err != nil && k8serrors.IsNotFound(err) {
return install.BuilderServiceAccountRoles(ctx, client, p.Namespace, p.Status.Cluster)
}

return err
}

func configureRegistry(ctx context.Context, c client.Client, p *v1.IntegrationPlatform) error {
if p.Status.Cluster == v1.IntegrationPlatformClusterOpenShift &&
p.Status.Build.PublishStrategy != v1.IntegrationPlatformBuildPublishStrategyS2I &&
Expand Down Expand Up @@ -253,21 +268,6 @@ func createServiceCaBundleConfigMap(ctx context.Context, client client.Client, p
return cm, nil
}

func createBuilderServiceAccount(ctx context.Context, client client.Client, p *v1.IntegrationPlatform) error {
sa := corev1.ServiceAccount{}
key := ctrl.ObjectKey{
Name: BuilderServiceAccount,
Namespace: p.Namespace,
}

err := client.Get(ctx, key, &sa)
if err != nil && k8serrors.IsNotFound(err) {
return install.BuilderServiceAccountRoles(ctx, client, p.Namespace, p.Status.Cluster)
}

return err
}

func createBuilderRegistryRoleBinding(ctx context.Context, client client.Client, p *v1.IntegrationPlatform) error {
rb := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit ad4e6c7

Please sign in to comment.