q-shift / qshift-templates Goto Github PK
View Code? Open in Web Editor NEWBackstage templates for the Qshift demo
License: Apache License 2.0
Backstage templates for the Qshift demo
License: Apache License 2.0
Enable to build a quarkus native image
Changes:
native-image
Set a default value for the backstage owner
owner:
title: Owner
type: string
ui:field: EntityPicker
ui:options:
catalogFilter:
kind:
- Group
- User
default: user:guest
Update the ClusterRoleBinding of the sa:pipeline
to give it access to kubevirt.io API within the namespace of the application AND NOT as this is the case under qshift-test
namespace.
Example
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubevirt.io:view
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubevirt.io:view
subjects:
- kind: ServiceAccount
name: pipeline
namespace: qshift-test
Add a new value to the list of the database within the template - field enum database
: NoSQL
Add condition to install postgresql helm chart and its argocd app
Question:
What should be the parameters ?
Then helm chart could be installed as such
See: https://github.com/halkyonio/primaza-poc/blob/main/scripts/atomic-fruits.sh#L54-L59
helm install $DB_RELEASE_NAME bitnami/postgresql \
--version $DB_VERSION \
--set auth.username=$DB_USERNAME \
--set auth.password=$DB_PASSWORD \
--set auth.database=$DB_DATABASE \
--create-namespace \
-n ${DB_NAMESPACE}"
For the demo, we could define within the template the default values (using template parameters) that we pass to the argocd: create
action.
It is also needed to update the application.properties to use the parameters OR that we pass instead ENV vars to the Quarkus App Deployment manifest instead.
WDYT ? @iocanel @aureamunoz
Deploy the Argocd Applications CR within the user's namespace as we have configured argocd to support such a feature. See: q-shift/backstage-playground#39 (comment)
Remark: Warn the user that the ArgoCD project - field sourceNamespaces
should include its namespace within the list
Add a new annotation to specify the quarkus version to the cataloginfo.yaml
app.quarkus.io/quarkus-version: ${{values.quarkusVersion}}
The value should be passed as a new backstage template parameter using a new UI field
When we replay the scaffolding using the template of the PR #5 then process fails
792024-02-09T11:37:40.000Z Finished step Generating GitOps Resources
802024-02-09T11:37:40.000Z Beginning step Publishing to Code Source Repository - Github
812024-02-09T11:37:41.000Z info: Init git repository {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38}
822024-02-09T11:37:41.000Z info: Adding file {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38,filepath=.}
832024-02-09T11:37:41.000Z info: Committing file to repo {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38,message=initial commit}
842024-02-09T11:37:41.000Z info: Creating new remote {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38,remote=origin,url=https://github.com/ch007m/my-quarkus-app.git}
852024-02-09T11:37:41.000Z info: Pushing directory to remote {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38,remote=origin}
862024-02-09T11:37:42.000Z Finished step Publishing to Code Source Repository - Github
...
882024-02-09T11:29:00.000Z Error: Duplicate project detected. Cannot overwrite existing.89 at
ArgoService.createArgoProject (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@roadiehq/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts:264:13)90 at
process.processTicksAndRejections (node:internal/process/task_queues:95:5)91 at
ArgoService.createArgoResources (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@roadiehq/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts:686:5)92 at
Object.handler (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@roadiehq/scaffolder-backend-argocd/src/actions/run/argocd.ts:59:7)93 at
NunjucksWorkflowRunner.executeStep (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@backstage/plugin-scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts:343:9)94 at
NunjucksWorkflowRunner.execute (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@backstage/plugin-scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts:431:9)95 at
TaskWorker.runOneTask (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@backstage/plugin-scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts:145:26)96 at
async run (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/p-queue/dist/index.js:163:29)
Error occurs when the argocd plugin checks if the project
already exists
https://github.com/RoadieHQ/roadie-backstage-plugins/blob/f96282c5430fa57f2a1953cf6cc7c66815cdf5ee/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts#L330-L361
}: CreateArgoProjectProps): Promise<object> {
const data = {
project: this.buildArgoProjectPayload({
projectName,
namespace,
sourceRepo,
destinationServer,
}),
};
const options: RequestInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${argoToken}`,
},
body: JSON.stringify(data),
};
const resp = await fetch(`${baseUrl}/api/v1/projects`, options);
const responseData = await resp.json();
if (resp.status === 403) {
throw new Error(responseData.message);
} else if (resp.status === 404) {
return resp.json();
} else if (
JSON.stringify(responseData).includes(
'existing project spec is different',
)
) {
throw new Error('Duplicate project detected. Cannot overwrite existing.');
}
return responseData;
}
The following project https://github.com/ch007m/ch007m-quarkus-app generated via backstage Quarkus plugin contains duplicated entities and resources. It comes from the recently generator code added for hibernate-orm-rest-data extension in Quarkus.
Duplicated code can be found in
src/main/java/io/quarkus/MyEntity.java
and src/main/java/io/quarkus/demo/MyEntity.java
src/main/java/io/quarkus/MyEntityResource.java
and src/main/java/io/quarkus/demo/MyEntityResource.java
The following error is launched when the application is started with mvn quarkus:dev
command:
io.quarkus.demo.MyEntityResourceJaxRs_6379958a2e660cd15fde7de382353a8d80f383ae#delete consumes *, produces *
io.quarkus.MyEntityResourceJaxRs_95036a537c257516229b105d011e9f48bae2e7cc#delete consumes *, produces *
POST /my-entity is declared by :
io.quarkus.demo.MyEntityResourceJaxRs_6379958a2e660cd15fde7de382353a8d80f383ae#add consumes application/json, produces application/json
io.quarkus.MyEntityResourceJaxRs_95036a537c257516229b105d011e9f48bae2e7cc#add consumes application/json, produces application/json
GET /my-entity is declared by :
io.quarkus.demo.MyEntityResourceJaxRs_6379958a2e660cd15fde7de382353a8d80f383ae#list consumes *, produces application/json
io.quarkus.MyEntityResourceJaxRs_95036a537c257516229b105d011e9f48bae2e7cc#list consumes *, produces application/json
GET /my-entity is declared by :
io.quarkus.demo.MyEntityResourceJaxRs_6379958a2e660cd15fde7de382353a8d80f383ae#get consumes *, produces application/json
io.quarkus.MyEntityResourceJaxRs_95036a537c257516229b105d011e9f48bae2e7cc#get consumes *, produces application/json
PUT /my-entity is declared by :
io.quarkus.demo.MyEntityResourceJaxRs_6379958a2e660cd15fde7de382353a8d80f383ae#update consumes application/json, produces application/json
io.quarkus.MyEntityResourceJaxRs_95036a537c257516229b105d011e9f48bae2e7cc#update consumes application/json, produces application/json
GET /my-entity is declared by :
io.quarkus.demo.MyEntityResourceJaxRs_6379958a2e660cd15fde7de382353a8d80f383ae#count consumes *, produces application/json
io.quarkus.MyEntityResourceJaxRs_95036a537c257516229b105d011e9f48bae2e7cc#count consumes *, produces application/json
at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor.checkForDuplicateEndpoint(ResteasyReactiveProcessor.java:1379)
at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor.setupEndpoints(ResteasyReactiveProcessor.java:671)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:849)
at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
at java.base/java.lang.Thread.run(Thread.java:1583)
at org.jboss.threads.JBossThread.run(JBossThread.java:483)
Merge the 2 pipelines into one as the step to build the image should only take place if the task: mvn test
=> accessing remote container succeeded.
When we generate a project using the option starter=true
with code.quarkus.io
, then the generated project don't include:
{% if values.database == 'quarkus-jdbc-postgresql' %}
# Kubernetes Service name to access the DB should be as defined within the helm chart => postgresql:5432
# apiVersion: v1
# kind: Service
# metadata:
# name: {{ include "postgresql.primary.fullname" . }}
# see: https://github.com/bitnami/charts/blob/9ba6ba51cf7c094e457396c423f5843df46023a2/bitnami/postgresql/templates/primary/svc.yaml#L4
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://${{ values.database_name }}-postgresql:5432/${{ values.database_name }}
%prod.quarkus.datasource.username=${{ values.database_username }}
{% elif values.database == 'quarkus-jdbc-mysql' %}
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://${{ values.component_id }}-db:3306/${{values.component_id}}-db
%prod.quarkus.datasource.username=root
{% elif values.database == 'quarkus-jdbc-h2' %}
%prod.quarkus.datasource.db-kind=h2
%prod.quarkus.datasource.jdbc.url=jdbc:h2:mem:quarkus
{% endif %}
%prod.quarkus.hibernate-orm.sql-load-script=import.sql
%prod.quarkus.hibernate-orm.database.generation=drop-and-create
-- This file allow to write SQL commands that will be emitted in test and dev.
insert into myentity (id, field) values(1, 'field-1');
insert into myentity (id, field) values(2, 'field-2');
insert into myentity (id, field) values(3, 'field-3');
alter sequence myentity_seq restart with 4;
Query: https://code.quarkus.io/?e=rest&e=hibernate-orm-rest-data-panache&e=jdbc-postgresql&extension-search=postgres
The PipelineRun name is not unique when we populate the resource using the helm chart
// source: https://github.com/q-shift/qshift-templates/blob/main/qshift/templates/quarkus-application/manifests/helm/build-test-push/templates/03-pipelinerun-quarkus-build-test-push.yaml
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: quarkus-build-test-push
namespace: {{ .Values.app.namespace }}
labels:
{{- include "backstage.labels" . | nindent 4 }}
By consequence, it is not possible within a namespace to create several quarkus applications
Add the link/url of the OpenShift Route exposing the quarkus application within the Component
See doc: https://backstage.io/docs/features/software-catalog/descriptor-format/#links-optional
Example of links:
kind: Component
metadata:
name: "my-quarkus-app"
description: "A cool quarkus app"
annotations:
argocd/app-name: my-quarkus-app-dev
backstage.io/kubernetes-id: my-quarkus-app
backstage.io/kubernetes-namespace: my-quarkus-app-dev
janus-idp.io/tekton: my-quarkus-app
backstage.io/source-location: url:https://gitlab-gitlab.apps.cluster-8z65j.sandbox1430.opentlc.com/development/my-quarkus-app
backstage.io/techdocs-ref: url:https://gitlab-gitlab.apps.cluster-8z65j.sandbox1430.opentlc.com/development/my-quarkus-app
gitlab.com/project-slug: development/my-quarkus-app
quay.io/repository-slug: "quayadmin/my-quarkus-app"
tags:
- java
- quarkus
links:
- url: https://devspaces.apps.cluster-8z65j.sandbox1430.opentlc.com/#https://gitlab-gitlab.apps.cluster-8z65j.sandbox1430.opentlc.com/development/my-quarkus-app
title: OpenShift Dev Spaces (VS Code)
icon: web
- url: https://devspaces.apps.cluster-8z65j.sandbox1430.opentlc.com/#https://gitlab-gitlab.apps.cluster-8z65j.sandbox1430.opentlc.com/development/my-quarkus-app?che-editor=che-incubator/che-idea/latest
title: OpenShift Dev Spaces (JetBrains IntelliJ)
icon: web
WDYT ? @iocanel @aureamunoz
When the template is deployed on RHDH iusing helm chart version 1.1, we got this error
2024-03-26T15:14:37.960Z catalog warn YAML error at url:https://github.com/q-shift/qshift-templates/tree/main/qshift/templates/quarkus-application/template.yaml, YAMLParseError: Map keys must be unique at line 44, column 11:
- User
default: user:guest
^
as default: user:guest
is defined twice
owner:
title: Owner
type: string
default: user:guest <== HERE
ui:field: EntityPicker
ui:options:
catalogFilter:
kind:
- Group
- User
default: user:guest <== AND HERE
The name
of the resources: deployment, service, route, etc generated by the Helm chart is too long:
Example:
When we scaffold a project using as application name (= component_id): my-quarkus-app
then the deployment name
becomes: my-quarkus-app-deploy-quarkus-deploy
Chart name is: quarkus-deploy
Chart Release name: my-quarkus-app-deploy
The following logic should be reviewed as currently it concatenates: <Chart Release name>-<Chart name>
to produce a very long name OR we should use as chart name
, the component_id
Remark: Apparently the argocd:create
action create the chart release name using the Argocd App name which is in our case: my-quarkus-app-deploy
or `<component_id>-deploy
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "quarkus-template.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
Remove port field - 8080 (or hide as non used)
Argocd fails to generate the Helm template due to
Failed to load target state: failed to generate manifest for source 1 of 1: r
pc error: code = Unknown desc = `helm template . --name-template my-quarkus-app-deploy --namespace openshift-gitops --kube-version 1.27 --values /tmp/9f46bb0b-0982-4bdb-8a46-52c507662f6e <api versions removed> --include-crds`
failed exit status 1: Error: template: quarkus-deploy/templates/deployment.yaml:7:8:
executing "quarkus-deploy/templates/deployment.yaml" at <include "quarkus-template.annotations" .>:
error calling include: template: no template "quarkus-template.annotations" associated with template "gotpl" Use --debug flag to render out invalid YAML
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.