oscerd closed pull request #18: Installation and run works URL: https://github.com/apache/camel-k/pull/18
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/.gitignore b/.gitignore index 0565637..2b30606 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ # Temporary Build Files tmp/_output tmp/_test +tmp/_maven_output # Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode diff --git a/build/Makefile b/build/Makefile index e229a1d..0aad657 100644 --- a/build/Makefile +++ b/build/Makefile @@ -29,7 +29,7 @@ codegen: images: images-build images-build: - operator-sdk build docker.io/apache/camel-k:$(VERSION) + ./build/package_maven_artifacts.sh && operator-sdk build docker.io/apache/camel-k:$(VERSION) images-push: docker push docker.io/apache/camel-k:$(VERSION) diff --git a/build/embed_resources.sh b/build/embed_resources.sh index 3ca6385..7d7fe89 100755 --- a/build/embed_resources.sh +++ b/build/embed_resources.sh @@ -39,7 +39,7 @@ func init() { EOM for f in $(ls $destdir | grep ".yaml"); do - printf "Resources[\"$f\"] =\n\`\n" >> $destfile + printf "\tResources[\"$f\"] =\n\t\t\`\n" >> $destfile cat $destdir/$f >> $destfile printf "\n\`\n" >> $destfile done diff --git a/build/package_maven_artifacts.sh b/build/package_maven_artifacts.sh new file mode 100755 index 0000000..9a89ac7 --- /dev/null +++ b/build/package_maven_artifacts.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +location=$(dirname $0) +cd $location/../ +mvn clean install -DskipTests -f runtime/pom.xml -s tmp/maven/settings.xml diff --git a/deploy/operator-deployment.yaml b/deploy/operator-deployment.yaml new file mode 100644 index 0000000..265b76d --- /dev/null +++ b/deploy/operator-deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: camel-k-operator + labels: + app: "camel-k" +spec: + replicas: 1 + selector: + matchLabels: + name: camel-k-operator + template: + metadata: + labels: + name: camel-k-operator + spec: + serviceAccountName: camel-k-operator + containers: + - name: camel-k-operator + image: docker.io/apache/camel-k:0.0.1-SNAPSHOT + ports: + - containerPort: 60000 + name: metrics + command: + - camel-k-operator + imagePullPolicy: IfNotPresent + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: "camel-k-operator" diff --git a/deploy/operator-role.yaml b/deploy/operator-role-kubernetes.yaml similarity index 100% rename from deploy/operator-role.yaml rename to deploy/operator-role-kubernetes.yaml diff --git a/deploy/operator-role-openshift.yaml b/deploy/operator-role-openshift.yaml new file mode 100644 index 0000000..c6fe09e --- /dev/null +++ b/deploy/operator-role-openshift.yaml @@ -0,0 +1,105 @@ +kind: Role +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: camel-k-operator +rules: +- apiGroups: + - camel.apache.org + resources: + - "*" + verbs: + - "*" +- apiGroups: + - "" + resources: + - pods + - services + - endpoints + - persistentvolumeclaims + - configmaps + - secrets + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + resources: + - events + verbs: + - get + - list + - watch +- apiGroups: + - apps + resources: + - deployments + - replicasets + - statefulsets + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch +- apiGroups: + - apps + attributeRestrictions: null + resources: + - daemonsets + verbs: + - get + - list + - watch +- apiGroups: + - "" + - "build.openshift.io" + resources: + - buildconfigs + - buildconfigs/webhooks + - builds + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + - "image.openshift.io" + resources: + - imagestreamimages + - imagestreammappings + - imagestreams + - imagestreams/secrets + - imagestreamtags + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + - build.openshift.io + attributeRestrictions: null + resources: + - buildconfigs/instantiate + - buildconfigs/instantiatebinary + - builds/clone + verbs: + - create \ No newline at end of file diff --git a/deploy/operator.yaml b/deploy/operator.yaml index 265b76d..863b21c 100644 --- a/deploy/operator.yaml +++ b/deploy/operator.yaml @@ -2,8 +2,6 @@ apiVersion: apps/v1 kind: Deployment metadata: name: camel-k-operator - labels: - app: "camel-k" spec: replicas: 1 selector: @@ -14,7 +12,6 @@ spec: labels: name: camel-k-operator spec: - serviceAccountName: camel-k-operator containers: - name: camel-k-operator image: docker.io/apache/camel-k:0.0.1-SNAPSHOT @@ -23,7 +20,7 @@ spec: name: metrics command: - camel-k-operator - imagePullPolicy: IfNotPresent + imagePullPolicy: Always env: - name: WATCH_NAMESPACE valueFrom: diff --git a/deploy/resources.go b/deploy/resources.go index 4dd9f89..df17de5 100644 --- a/deploy/resources.go +++ b/deploy/resources.go @@ -24,8 +24,8 @@ var Resources map[string]string func init() { Resources = make(map[string]string) -Resources["crd.yaml"] = -` + Resources["crd.yaml"] = + ` apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: @@ -41,8 +41,8 @@ spec: version: v1alpha1 ` -Resources["cr.yaml"] = -` + Resources["cr.yaml"] = + ` apiVersion: "camel.apache.org/v1alpha1" kind: "Integration" metadata: @@ -67,8 +67,45 @@ spec: } ` -Resources["operator-role-binding.yaml"] = + Resources["operator-deployment.yaml"] = + ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: camel-k-operator + labels: + app: "camel-k" +spec: + replicas: 1 + selector: + matchLabels: + name: camel-k-operator + template: + metadata: + labels: + name: camel-k-operator + spec: + serviceAccountName: camel-k-operator + containers: + - name: camel-k-operator + image: docker.io/apache/camel-k:0.0.1-SNAPSHOT + ports: + - containerPort: 60000 + name: metrics + command: + - camel-k-operator + imagePullPolicy: IfNotPresent + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: "camel-k-operator" + ` + Resources["operator-role-binding.yaml"] = + ` kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: @@ -81,8 +118,8 @@ roleRef: name: camel-k-operator apiGroup: rbac.authorization.k8s.io ` -Resources["operator-role.yaml"] = -` + Resources["operator-role-kubernetes.yaml"] = + ` kind: Role apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: @@ -145,21 +182,127 @@ rules: - list - watch ` -Resources["operator-service-account.yaml"] = + Resources["operator-role-openshift.yaml"] = + ` +kind: Role +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: camel-k-operator +rules: +- apiGroups: + - camel.apache.org + resources: + - "*" + verbs: + - "*" +- apiGroups: + - "" + resources: + - pods + - services + - endpoints + - persistentvolumeclaims + - configmaps + - secrets + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + resources: + - events + verbs: + - get + - list + - watch +- apiGroups: + - apps + resources: + - deployments + - replicasets + - statefulsets + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch +- apiGroups: + - apps + attributeRestrictions: null + resources: + - daemonsets + verbs: + - get + - list + - watch +- apiGroups: + - "" + - "build.openshift.io" + resources: + - buildconfigs + - buildconfigs/webhooks + - builds + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + - "image.openshift.io" + resources: + - imagestreamimages + - imagestreammappings + - imagestreams + - imagestreams/secrets + - imagestreamtags + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + - build.openshift.io + attributeRestrictions: null + resources: + - buildconfigs/instantiate + - buildconfigs/instantiatebinary + - builds/clone + verbs: + - create ` + Resources["operator-service-account.yaml"] = + ` apiVersion: v1 kind: ServiceAccount metadata: name: camel-k-operator ` -Resources["operator.yaml"] = -` + Resources["operator.yaml"] = + ` apiVersion: apps/v1 kind: Deployment metadata: name: camel-k-operator - labels: - app: "camel-k" spec: replicas: 1 selector: @@ -170,7 +313,6 @@ spec: labels: name: camel-k-operator spec: - serviceAccountName: camel-k-operator containers: - name: camel-k-operator image: docker.io/apache/camel-k:0.0.1-SNAPSHOT @@ -179,7 +321,7 @@ spec: name: metrics command: - camel-k-operator - imagePullPolicy: IfNotPresent + imagePullPolicy: Always env: - name: WATCH_NAMESPACE valueFrom: @@ -189,8 +331,8 @@ spec: value: "camel-k-operator" ` -Resources["user-cluster-role.yaml"] = -` + Resources["user-cluster-role.yaml"] = + ` kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: diff --git a/pkg/install/operator.go b/pkg/install/operator.go index 5934cc3..a4d98d1 100644 --- a/pkg/install/operator.go +++ b/pkg/install/operator.go @@ -28,9 +28,9 @@ import ( func Operator(namespace string) error { return installResources(namespace, "operator-service-account.yaml", - "operator-role.yaml", + "operator-role-openshift.yaml", // TODO distinguish between Openshift and Kubernetes "operator-role-binding.yaml", - "operator.yaml", + "operator-deployment.yaml", ) } diff --git a/pkg/util/maven/maven.go b/pkg/util/maven/maven.go index 590908f..cb0d8f5 100644 --- a/pkg/util/maven/maven.go +++ b/pkg/util/maven/maven.go @@ -58,17 +58,17 @@ func Build(project Project) (string, error) { } func runMavenBuild(buildDir string) error { - mavenBuild := exec.Command("mvn", "clean", "install", "-DskipTests") + mavenBuild := exec.Command("mvn", mavenExtraOptions(), "clean", "install", "-DskipTests") mavenBuild.Dir = buildDir - logrus.Info("Starting maven build: mvn clean install -DskipTests") + logrus.Info("Starting maven build: mvn " + mavenExtraOptions() + " clean install -DskipTests") err := mavenBuild.Run() if err != nil { return errors.Wrap(err, "failure while executing maven build") } - mavenDep := exec.Command("mvn", "dependency:copy-dependencies") + mavenDep := exec.Command("mvn", mavenExtraOptions(), "dependency:copy-dependencies") mavenDep.Dir = buildDir - logrus.Info("Copying maven dependencies: mvn dependency:copy-dependencies") + logrus.Info("Copying maven dependencies: mvn " + mavenExtraOptions() + " dependency:copy-dependencies") err = mavenDep.Run() if err != nil { return errors.Wrap(err, "failure while extracting maven dependencies") @@ -77,6 +77,13 @@ func runMavenBuild(buildDir string) error { return nil } +func mavenExtraOptions() string { + if _, err := os.Stat("/tmp/artifacts/m2"); err == nil { + return "-Dmaven.repo.local=/tmp/artifacts/m2" + } + return "" +} + func createTar(buildDir string, project Project) (string, error) { artifactDir, err := ioutil.TempDir("", artifactDirPrefix) if err != nil { diff --git a/tmp/build/Dockerfile b/tmp/build/Dockerfile index 519d9b7..df1abde 100644 --- a/tmp/build/Dockerfile +++ b/tmp/build/Dockerfile @@ -1,6 +1,14 @@ -FROM alpine:3.6 +FROM fabric8/s2i-java:2.1 -RUN adduser -D camel-k-operator -USER camel-k-operator +#RUN adduser -D camel-k-operator +#USER camel-k-operator + +ADD tmp/_maven_output /tmp/artifacts/m2 ADD tmp/_output/bin/camel-k-operator /usr/local/bin/camel-k-operator + +USER 0 +RUN chgrp -R 0 /tmp/artifacts/m2 \ + && chmod -R g=u /tmp/artifacts/m2 + +USER 1000 diff --git a/tmp/maven/settings.xml b/tmp/maven/settings.xml new file mode 100644 index 0000000..6d16002 --- /dev/null +++ b/tmp/maven/settings.xml @@ -0,0 +1,6 @@ +<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 + https://maven.apache.org/xsd/settings-1.0.0.xsd"> + <localRepository>tmp/_maven_output</localRepository> +</settings> \ No newline at end of file ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services