From b160d8412651d5e186cb0c307e11ae5f9f51285e Mon Sep 17 00:00:00 2001 From: gazarenkov Date: Mon, 5 Feb 2024 11:37:51 +0200 Subject: [PATCH 01/12] remove hardcoded images --- api/v1alpha1/backstage_types.go | 6 - .../default-config/db-statefulset.yaml | 2 +- config/manager/default-config/deployment.yaml | 5 +- controllers/backstage_controller.go | 25 +++-- controllers/backstage_controller_test.go | 12 +- controllers/backstage_deployment.go | 103 +----------------- controllers/local_db_statefulset.go | 8 +- main.go | 12 +- 8 files changed, 39 insertions(+), 134 deletions(-) diff --git a/api/v1alpha1/backstage_types.go b/api/v1alpha1/backstage_types.go index 56367fd8..6e9d2098 100644 --- a/api/v1alpha1/backstage_types.go +++ b/api/v1alpha1/backstage_types.go @@ -27,12 +27,6 @@ const ( DeployInProgress string = "DeployInProgress" ) -// Constants for image placeholders -const ( - EnvPostGresImage string = "RELATED_IMAGE_postgresql" - EnvBackstageImage string = "RELATED_IMAGE_backstage" -) - // BackstageSpec defines the desired state of Backstage type BackstageSpec struct { // Configuration for Backstage. Optional. diff --git a/config/manager/default-config/db-statefulset.yaml b/config/manager/default-config/db-statefulset.yaml index f8abbafd..859ab235 100644 --- a/config/manager/default-config/db-statefulset.yaml +++ b/config/manager/default-config/db-statefulset.yaml @@ -29,7 +29,7 @@ spec: envFrom: - secretRef: name: # will be replaced with 'backstage-psql-secrets-' - image: # will be replaced with the actual image + image: quay.io/fedora/postgresql-15:latest imagePullPolicy: IfNotPresent securityContext: runAsNonRoot: true diff --git a/config/manager/default-config/deployment.yaml b/config/manager/default-config/deployment.yaml index 24c0debc..aea45d79 100644 --- a/config/manager/default-config/deployment.yaml +++ b/config/manager/default-config/deployment.yaml @@ -36,7 +36,8 @@ spec: env: - name: NPM_CONFIG_USERCONFIG value: /opt/app-root/src/.npmrc.dynamic-plugins - image: # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next + #image: # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next + image: quay.io/janus-idp/backstage-showcase:next imagePullPolicy: IfNotPresent name: install-dynamic-plugins volumeMounts: @@ -50,7 +51,7 @@ spec: containers: - name: backstage-backend - image: # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next + image: quay.io/janus-idp/backstage-showcase:next imagePullPolicy: IfNotPresent args: - "--config" diff --git a/controllers/backstage_controller.go b/controllers/backstage_controller.go index d52322af..eb6bc762 100644 --- a/controllers/backstage_controller.go +++ b/controllers/backstage_controller.go @@ -41,6 +41,12 @@ const ( BackstageAppLabel = "janus-idp.io/app" ) +// Constants for image placeholders +const ( + EnvPostgresImage string = "RELATED_IMAGE_postgresql" + EnvBackstageImage string = "RELATED_IMAGE_backstage" +) + // BackstageReconciler reconciles a Backstage object type BackstageReconciler struct { client.Client @@ -57,9 +63,9 @@ type BackstageReconciler struct { IsOpenShift bool - PsqlImage string - - BackstageImage string + //PsqlImage string + // + //BackstageImage string } //+kubebuilder:rbac:groups=janus-idp.io,resources=backstages,verbs=get;list;watch;create;update;patch;delete @@ -295,14 +301,13 @@ func (r *BackstageReconciler) labels(meta *v1.ObjectMeta, backstage bs.Backstage // SetupWithManager sets up the controller with the Manager. func (r *BackstageReconciler) SetupWithManager(mgr ctrl.Manager, log logr.Logger) error { - if len(r.PsqlImage) == 0 { - r.PsqlImage = "quay.io/fedora/postgresql-15:latest" - log.Info("Enviroment variable is not set, default is used", bs.EnvPostGresImage, r.PsqlImage) - } - if len(r.BackstageImage) == 0 { - r.BackstageImage = "quay.io/janus-idp/backstage-showcase:next" - log.Info("Enviroment variable is not set, default is used", bs.EnvBackstageImage, r.BackstageImage) + const imageNotSet = "environment variable %s is not set, default will be used" + if _, ok := os.LookupEnv(EnvPostgresImage); !ok { + log.Info(imageNotSet, EnvPostgresImage) + } + if _, ok := os.LookupEnv(EnvBackstageImage); !ok { + log.Info(imageNotSet, EnvBackstageImage) } builder := ctrl.NewControllerManagedBy(mgr). diff --git a/controllers/backstage_controller_test.go b/controllers/backstage_controller_test.go index efd34ed2..c759fc9a 100644 --- a/controllers/backstage_controller_test.go +++ b/controllers/backstage_controller_test.go @@ -61,12 +61,12 @@ var _ = Describe("Backstage controller", func() { Expect(err).To(Not(HaveOccurred())) backstageReconciler = &BackstageReconciler{ - Client: k8sClient, - Scheme: k8sClient.Scheme(), - Namespace: ns, - OwnsRuntime: true, - PsqlImage: "test-postgresql-15:latest", - BackstageImage: "test-backstage-showcase:next", + Client: k8sClient, + Scheme: k8sClient.Scheme(), + Namespace: ns, + OwnsRuntime: true, + //PsqlImage: "test-postgresql-15:latest", + //BackstageImage: "test-backstage-showcase:next", } }) diff --git a/controllers/backstage_deployment.go b/controllers/backstage_deployment.go index 6966ea13..19ab4c9e 100644 --- a/controllers/backstage_deployment.go +++ b/controllers/backstage_deployment.go @@ -17,6 +17,7 @@ package controller import ( "context" "fmt" + "os" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" @@ -33,103 +34,6 @@ const ( _containersWorkingDir = "/opt/app-root/src" ) -//var ( -// DefaultBackstageDeployment = fmt.Sprintf(` -//apiVersion: apps/v1 -//kind: Deployment -//metadata: -// name: backstage -//spec: -// replicas: 1 -// selector: -// matchLabels: -// janus-idp.io/app: # placeholder for 'backstage-' -// template: -// metadata: -// labels: -// janus-idp.io/app: # placeholder for 'backstage-' -// spec: -//# serviceAccountName: default -// -// volumes: -// - ephemeral: -// volumeClaimTemplate: -// spec: -// accessModes: -// - ReadWriteOnce -// resources: -// requests: -// storage: 1Gi -// name: dynamic-plugins-root -// - name: dynamic-plugins-npmrc -// secret: -// defaultMode: 420 -// optional: true -// secretName: dynamic-plugins-npmrc -// -// initContainers: -// - command: -// - ./install-dynamic-plugins.sh -// - /dynamic-plugins-root -// env: -// - name: NPM_CONFIG_USERCONFIG -// value: %[3]s/.npmrc.dynamic-plugins -// image: 'quay.io/janus-idp/backstage-showcase:next' -// imagePullPolicy: IfNotPresent -// name: %[1]s -// volumeMounts: -// - mountPath: /dynamic-plugins-root -// name: dynamic-plugins-root -// - mountPath: %[3]s/.npmrc.dynamic-plugins -// name: dynamic-plugins-npmrc -// readOnly: true -// subPath: .npmrc -// workingDir: %[3]s -// -// containers: -// - name: %[2]s -// image: quay.io/janus-idp/backstage-showcase:next -// imagePullPolicy: IfNotPresent -// args: -// - "--config" -// - "dynamic-plugins-root/app-config.dynamic-plugins.yaml" -// readinessProbe: -// failureThreshold: 3 -// httpGet: -// path: /healthcheck -// port: 7007 -// scheme: HTTP -// initialDelaySeconds: 30 -// periodSeconds: 10 -// successThreshold: 2 -// timeoutSeconds: 2 -// livenessProbe: -// failureThreshold: 3 -// httpGet: -// path: /healthcheck -// port: 7007 -// scheme: HTTP -// initialDelaySeconds: 60 -// periodSeconds: 10 -// successThreshold: 1 -// timeoutSeconds: 2 -// ports: -// - name: http -// containerPort: 7007 -// env: -// - name: APP_CONFIG_backend_listen_port -// value: "7007" -// envFrom: -// - secretRef: -// name: postgres-secrets -//# - secretRef: -//# name: backstage-secrets -// volumeMounts: -// - mountPath: %[3]s/dynamic-plugins-root -// name: dynamic-plugins-root -//`, _defaultBackstageInitContainerName, _defaultBackstageMainContainerName, _containersWorkingDir) -//) - // ContainerVisitor is called with each container type ContainerVisitor func(container *v1.Container) @@ -291,9 +195,10 @@ func (r *BackstageReconciler) validateAndUpdatePsqlSecretRef(backstage bs.Backst } func (r *BackstageReconciler) setDefaultDeploymentImage(deployment *appsv1.Deployment) { + visitContainers(&deployment.Spec.Template, func(container *v1.Container) { - if len(container.Image) == 0 || container.Image == fmt.Sprintf("<%s>", bs.EnvBackstageImage) { - container.Image = r.BackstageImage + if val, ok := os.LookupEnv(EnvBackstageImage); ok { + container.Image = val } }) } diff --git a/controllers/local_db_statefulset.go b/controllers/local_db_statefulset.go index ec8a1cda..06d873b0 100644 --- a/controllers/local_db_statefulset.go +++ b/controllers/local_db_statefulset.go @@ -18,6 +18,7 @@ package controller import ( "context" "fmt" + "os" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" @@ -219,9 +220,12 @@ func (r *BackstageReconciler) patchLocalDbStatefulSetObj(statefulSet *appsv1.Sta func (r *BackstageReconciler) setDefaultStatefulSetImage(statefulSet *appsv1.StatefulSet) { visitContainers(&statefulSet.Spec.Template, func(container *v1.Container) { - if len(container.Image) == 0 || container.Image == fmt.Sprintf("<%s>", bs.EnvPostGresImage) { - container.Image = r.PsqlImage + if val, ok := os.LookupEnv(EnvPostgresImage); ok { + container.Image = val } + //if len(container.Image) == 0 || container.Image == fmt.Sprintf("<%s>", bs.EnvPostgresImage) { + // container.Image = r.PsqlImage + //} }) } diff --git a/main.go b/main.go index a58f4c30..63ba642f 100644 --- a/main.go +++ b/main.go @@ -104,12 +104,10 @@ func main() { } if err = (&controller.BackstageReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - OwnsRuntime: ownRuntime, - IsOpenShift: isOpenShift, - PsqlImage: os.Getenv(backstageiov1alpha1.EnvPostGresImage), - BackstageImage: os.Getenv(backstageiov1alpha1.EnvBackstageImage), + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + OwnsRuntime: ownRuntime, + IsOpenShift: isOpenShift, }).SetupWithManager(mgr, setupLog); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Backstage") os.Exit(1) @@ -129,8 +127,6 @@ func main() { "own-runtime", ownRuntime, "env.LOCALBIN", os.Getenv("LOCALBIN"), "isOpenShift", isOpenShift, - backstageiov1alpha1.EnvPostGresImage, os.Getenv(backstageiov1alpha1.EnvPostGresImage), - backstageiov1alpha1.EnvBackstageImage, os.Getenv(backstageiov1alpha1.EnvBackstageImage), ) if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager") From c659cc962f4519444bcdc554fa92eb1c2e62320c Mon Sep 17 00:00:00 2001 From: gazarenkov Date: Tue, 6 Feb 2024 13:42:43 +0200 Subject: [PATCH 02/12] fix image --- config/manager/default-config/deployment.yaml | 4 ++-- controllers/backstage_controller.go | 6 +++--- examples/janus-cr-with-app-configs.yaml | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/manager/default-config/deployment.yaml b/config/manager/default-config/deployment.yaml index aea45d79..977fe724 100644 --- a/config/manager/default-config/deployment.yaml +++ b/config/manager/default-config/deployment.yaml @@ -37,7 +37,7 @@ spec: - name: NPM_CONFIG_USERCONFIG value: /opt/app-root/src/.npmrc.dynamic-plugins #image: # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next - image: quay.io/janus-idp/backstage-showcase:next + image: quay.io/janus-idp/backstage-showcase:latest imagePullPolicy: IfNotPresent name: install-dynamic-plugins volumeMounts: @@ -51,7 +51,7 @@ spec: containers: - name: backstage-backend - image: quay.io/janus-idp/backstage-showcase:next + image: quay.io/janus-idp/backstage-showcase:latest imagePullPolicy: IfNotPresent args: - "--config" diff --git a/controllers/backstage_controller.go b/controllers/backstage_controller.go index eb6bc762..dc16fc11 100644 --- a/controllers/backstage_controller.go +++ b/controllers/backstage_controller.go @@ -302,12 +302,12 @@ func (r *BackstageReconciler) labels(meta *v1.ObjectMeta, backstage bs.Backstage // SetupWithManager sets up the controller with the Manager. func (r *BackstageReconciler) SetupWithManager(mgr ctrl.Manager, log logr.Logger) error { - const imageNotSet = "environment variable %s is not set, default will be used" + const imageNotSet = "environment variable is not set, default will be used:" if _, ok := os.LookupEnv(EnvPostgresImage); !ok { - log.Info(imageNotSet, EnvPostgresImage) + log.Info(imageNotSet, "", EnvPostgresImage) } if _, ok := os.LookupEnv(EnvBackstageImage); !ok { - log.Info(imageNotSet, EnvBackstageImage) + log.Info(imageNotSet, "", EnvBackstageImage) } builder := ctrl.NewControllerManagedBy(mgr). diff --git a/examples/janus-cr-with-app-configs.yaml b/examples/janus-cr-with-app-configs.yaml index 1f08edad..b18e0ddf 100644 --- a/examples/janus-cr-with-app-configs.yaml +++ b/examples/janus-cr-with-app-configs.yaml @@ -80,6 +80,7 @@ data: target: https://github.com/ododev/odo-backstage-software-template/blob/main/template.yaml rules: - allow: [Template] + # # catalog.providers.githubOrg.default.orgUrl --- apiVersion: v1 @@ -132,8 +133,8 @@ data: endpoints: /explore-backend-completed: target: 'http://localhost:7017' - ---- + + --- apiVersion: v1 kind: ConfigMap metadata: From 087e105ee9cfdb6187b9ad088a13c550b5c9f44f Mon Sep 17 00:00:00 2001 From: Gennady Azarenkov Date: Fri, 9 Feb 2024 14:49:32 +0200 Subject: [PATCH 03/12] Update examples/janus-cr-with-app-configs.yaml Co-authored-by: Armel Soro --- examples/janus-cr-with-app-configs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/janus-cr-with-app-configs.yaml b/examples/janus-cr-with-app-configs.yaml index b18e0ddf..2ddaf4ba 100644 --- a/examples/janus-cr-with-app-configs.yaml +++ b/examples/janus-cr-with-app-configs.yaml @@ -134,7 +134,7 @@ data: /explore-backend-completed: target: 'http://localhost:7017' - --- +--- apiVersion: v1 kind: ConfigMap metadata: From 324c2951d4bc29fae69bc695c5bdbee5dace74f9 Mon Sep 17 00:00:00 2001 From: gazarenkov Date: Fri, 9 Feb 2024 23:23:33 +0200 Subject: [PATCH 04/12] change lookup --- controllers/backstage_controller.go | 23 +++--- controllers/backstage_deployment.go | 5 +- controllers/local_db_statefulset.go | 113 +--------------------------- 3 files changed, 15 insertions(+), 126 deletions(-) diff --git a/controllers/backstage_controller.go b/controllers/backstage_controller.go index dc16fc11..7484fa5a 100644 --- a/controllers/backstage_controller.go +++ b/controllers/backstage_controller.go @@ -41,10 +41,9 @@ const ( BackstageAppLabel = "janus-idp.io/app" ) -// Constants for image placeholders -const ( - EnvPostgresImage string = "RELATED_IMAGE_postgresql" - EnvBackstageImage string = "RELATED_IMAGE_backstage" +var ( + envPostgresImage string + envBackstageImage string ) // BackstageReconciler reconciles a Backstage object @@ -62,10 +61,10 @@ type BackstageReconciler struct { Namespace string IsOpenShift bool +} + +func init() { - //PsqlImage string - // - //BackstageImage string } //+kubebuilder:rbac:groups=janus-idp.io,resources=backstages,verbs=get;list;watch;create;update;patch;delete @@ -302,12 +301,12 @@ func (r *BackstageReconciler) labels(meta *v1.ObjectMeta, backstage bs.Backstage // SetupWithManager sets up the controller with the Manager. func (r *BackstageReconciler) SetupWithManager(mgr ctrl.Manager, log logr.Logger) error { - const imageNotSet = "environment variable is not set, default will be used:" - if _, ok := os.LookupEnv(EnvPostgresImage); !ok { - log.Info(imageNotSet, "", EnvPostgresImage) + var ok bool + if envPostgresImage, ok = os.LookupEnv("RELATED_IMAGE_postgresql"); !ok { + log.Info("RELATED_IMAGE_postgresql environment variable is not set, default will be used") } - if _, ok := os.LookupEnv(EnvBackstageImage); !ok { - log.Info(imageNotSet, "", EnvBackstageImage) + if envBackstageImage, ok = os.LookupEnv("RELATED_IMAGE_backstage"); !ok { + log.Info("RELATED_IMAGE_backstage environment variable is not set, default will be used") } builder := ctrl.NewControllerManagedBy(mgr). diff --git a/controllers/backstage_deployment.go b/controllers/backstage_deployment.go index 19ab4c9e..970cf4d5 100644 --- a/controllers/backstage_deployment.go +++ b/controllers/backstage_deployment.go @@ -17,7 +17,6 @@ package controller import ( "context" "fmt" - "os" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" @@ -197,8 +196,8 @@ func (r *BackstageReconciler) validateAndUpdatePsqlSecretRef(backstage bs.Backst func (r *BackstageReconciler) setDefaultDeploymentImage(deployment *appsv1.Deployment) { visitContainers(&deployment.Spec.Template, func(container *v1.Container) { - if val, ok := os.LookupEnv(EnvBackstageImage); ok { - container.Image = val + if envBackstageImage != "" { + container.Image = envBackstageImage } }) } diff --git a/controllers/local_db_statefulset.go b/controllers/local_db_statefulset.go index 06d873b0..a4b78e18 100644 --- a/controllers/local_db_statefulset.go +++ b/controllers/local_db_statefulset.go @@ -18,7 +18,6 @@ package controller import ( "context" "fmt" - "os" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" @@ -29,111 +28,6 @@ import ( bs "janus-idp.io/backstage-operator/api/v1alpha1" ) -//var ( -// DefaultLocalDbDeployment = `apiVersion: apps/v1 -//kind: StatefulSet -//metadata: -// name: backstage-psql-cr1 # placeholder for 'backstage-psql-' -//spec: -// podManagementPolicy: OrderedReady -// replicas: 1 -// selector: -// matchLabels: -// janus-idp.io/app: backstage-psql-cr1 # placeholder for 'backstage-psql-' -// serviceName: backstage-psql-cr1-hl # placeholder for 'backstage-psql--hl' -// template: -// metadata: -// labels: -// janus-idp.io/app: backstage-psql-cr1 # placeholder for 'backstage-psql-' -// name: backstage-db-cr1 # placeholder for 'backstage-psql-' -// spec: -// containers: -// - env: -// - name: POSTGRESQL_PORT_NUMBER -// value: "5432" -// - name: POSTGRESQL_VOLUME_DIR -// value: /var/lib/pgsql/data -// - name: PGDATA -// value: /var/lib/pgsql/data/userdata -// envFrom: -// - secretRef: -// name: postgres-secrets -// image: quay.io/fedora/postgresql-15:latest -// imagePullPolicy: IfNotPresent -// securityContext: -// runAsNonRoot: true -// allowPrivilegeEscalation: false -// seccompProfile: -// type: RuntimeDefault -// capabilities: -// drop: -// - ALL -// livenessProbe: -// exec: -// command: -// - /bin/sh -// - -c -// - exec pg_isready -U ${POSTGRES_USER} -h 127.0.0.1 -p 5432 -// failureThreshold: 6 -// initialDelaySeconds: 30 -// periodSeconds: 10 -// successThreshold: 1 -// timeoutSeconds: 5 -// name: postgresql -// ports: -// - containerPort: 5432 -// name: tcp-postgresql -// protocol: TCP -// readinessProbe: -// exec: -// command: -// - /bin/sh -// - -c -// - -e -// - | -// exec pg_isready -U ${POSTGRES_USER} -h 127.0.0.1 -p 5432 -// failureThreshold: 6 -// initialDelaySeconds: 5 -// periodSeconds: 10 -// successThreshold: 1 -// timeoutSeconds: 5 -// resources: -// requests: -// cpu: 250m -// memory: 256Mi -// limits: -// memory: 1024Mi -// volumeMounts: -// - mountPath: /dev/shm -// name: dshm -// - mountPath: /var/lib/pgsql/data -// name: data -// restartPolicy: Always -// securityContext: {} -// serviceAccount: default -// serviceAccountName: default -// volumes: -// - emptyDir: -// medium: Memory -// name: dshm -// updateStrategy: -// rollingUpdate: -// partition: 0 -// type: RollingUpdate -// volumeClaimTemplates: -// - apiVersion: v1 -// kind: PersistentVolumeClaim -// metadata: -// name: data -// spec: -// accessModes: -// - ReadWriteOnce -// resources: -// requests: -// storage: 1Gi -//` -//) - const ( ownerRefFmt = "failed to set owner reference: %s" ) @@ -220,12 +114,9 @@ func (r *BackstageReconciler) patchLocalDbStatefulSetObj(statefulSet *appsv1.Sta func (r *BackstageReconciler) setDefaultStatefulSetImage(statefulSet *appsv1.StatefulSet) { visitContainers(&statefulSet.Spec.Template, func(container *v1.Container) { - if val, ok := os.LookupEnv(EnvPostgresImage); ok { - container.Image = val + if envPostgresImage != "" { + container.Image = envPostgresImage } - //if len(container.Image) == 0 || container.Image == fmt.Sprintf("<%s>", bs.EnvPostgresImage) { - // container.Image = r.PsqlImage - //} }) } From b7dda01250e4c7529794830257262841909d6cd5 Mon Sep 17 00:00:00 2001 From: Gennady Azarenkov Date: Fri, 9 Feb 2024 23:25:21 +0200 Subject: [PATCH 05/12] Update config/manager/default-config/db-statefulset.yaml Co-authored-by: Armel Soro --- config/manager/default-config/db-statefulset.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/manager/default-config/db-statefulset.yaml b/config/manager/default-config/db-statefulset.yaml index 859ab235..f3b2f2d2 100644 --- a/config/manager/default-config/db-statefulset.yaml +++ b/config/manager/default-config/db-statefulset.yaml @@ -29,6 +29,7 @@ spec: envFrom: - secretRef: name: # will be replaced with 'backstage-psql-secrets-' + # image will be replaced by the value of the `RELATED_IMAGE_postgresql` env var, if set image: quay.io/fedora/postgresql-15:latest imagePullPolicy: IfNotPresent securityContext: From a20200b517bb3ae0ad8df59f88c294ba384ad2cd Mon Sep 17 00:00:00 2001 From: Gennady Azarenkov Date: Fri, 9 Feb 2024 23:25:44 +0200 Subject: [PATCH 06/12] Update config/manager/default-config/deployment.yaml Co-authored-by: Armel Soro --- config/manager/default-config/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/manager/default-config/deployment.yaml b/config/manager/default-config/deployment.yaml index 977fe724..375de8b8 100644 --- a/config/manager/default-config/deployment.yaml +++ b/config/manager/default-config/deployment.yaml @@ -36,7 +36,7 @@ spec: env: - name: NPM_CONFIG_USERCONFIG value: /opt/app-root/src/.npmrc.dynamic-plugins - #image: # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next + # image will be replaced by the value of the `RELATED_IMAGE_backstage` env var, if set image: quay.io/janus-idp/backstage-showcase:latest imagePullPolicy: IfNotPresent name: install-dynamic-plugins From 6f120f04aa65aade7aac4e5e0748c5f82bbd2c6e Mon Sep 17 00:00:00 2001 From: gazarenkov Date: Fri, 9 Feb 2024 23:33:40 +0200 Subject: [PATCH 07/12] change lookup --- controllers/backstage_controller.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/controllers/backstage_controller.go b/controllers/backstage_controller.go index 7484fa5a..e3c2a65c 100644 --- a/controllers/backstage_controller.go +++ b/controllers/backstage_controller.go @@ -63,10 +63,6 @@ type BackstageReconciler struct { IsOpenShift bool } -func init() { - -} - //+kubebuilder:rbac:groups=janus-idp.io,resources=backstages,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=janus-idp.io,resources=backstages/status,verbs=get;update;patch //+kubebuilder:rbac:groups=janus-idp.io,resources=backstages/finalizers,verbs=update From 63ecb40d61a01f1fe39d7d128bd50053fad7b577 Mon Sep 17 00:00:00 2001 From: gazarenkov Date: Fri, 9 Feb 2024 23:50:17 +0200 Subject: [PATCH 08/12] change lookup --- controllers/backstage_deployment.go | 10 +++++----- controllers/local_db_statefulset.go | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/controllers/backstage_deployment.go b/controllers/backstage_deployment.go index 970cf4d5..e8080ef8 100644 --- a/controllers/backstage_deployment.go +++ b/controllers/backstage_deployment.go @@ -194,12 +194,12 @@ func (r *BackstageReconciler) validateAndUpdatePsqlSecretRef(backstage bs.Backst } func (r *BackstageReconciler) setDefaultDeploymentImage(deployment *appsv1.Deployment) { - - visitContainers(&deployment.Spec.Template, func(container *v1.Container) { - if envBackstageImage != "" { + if envBackstageImage != "" { + visitContainers(&deployment.Spec.Template, func(container *v1.Container) { container.Image = envBackstageImage - } - }) + + }) + } } func (r *BackstageReconciler) applyBackstageLabels(backstage bs.Backstage, deployment *appsv1.Deployment) { diff --git a/controllers/local_db_statefulset.go b/controllers/local_db_statefulset.go index a4b78e18..327f63ce 100644 --- a/controllers/local_db_statefulset.go +++ b/controllers/local_db_statefulset.go @@ -113,11 +113,11 @@ func (r *BackstageReconciler) patchLocalDbStatefulSetObj(statefulSet *appsv1.Sta } func (r *BackstageReconciler) setDefaultStatefulSetImage(statefulSet *appsv1.StatefulSet) { - visitContainers(&statefulSet.Spec.Template, func(container *v1.Container) { - if envPostgresImage != "" { + if envPostgresImage != "" { + visitContainers(&statefulSet.Spec.Template, func(container *v1.Container) { container.Image = envPostgresImage - } - }) + }) + } } // cleanupLocalDbResources removes all local db related resources, including statefulset, services and generated secret. From db63b44e40fee540c22fe78c808266aa9578db05 Mon Sep 17 00:00:00 2001 From: Gennady Azarenkov Date: Mon, 12 Feb 2024 14:30:36 +0200 Subject: [PATCH 09/12] Update config/manager/default-config/deployment.yaml Co-authored-by: Armel Soro --- config/manager/default-config/deployment.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/manager/default-config/deployment.yaml b/config/manager/default-config/deployment.yaml index 375de8b8..a656100a 100644 --- a/config/manager/default-config/deployment.yaml +++ b/config/manager/default-config/deployment.yaml @@ -51,6 +51,7 @@ spec: containers: - name: backstage-backend + # image will be replaced by the value of the `RELATED_IMAGE_backstage` env var, if set image: quay.io/janus-idp/backstage-showcase:latest imagePullPolicy: IfNotPresent args: From 3dab91e9f21dba4ea31d78e6f509130205dedc8f Mon Sep 17 00:00:00 2001 From: gazarenkov Date: Mon, 12 Feb 2024 16:46:30 +0200 Subject: [PATCH 10/12] add generated files --- .../manifests/backstage-default-config_v1_configmap.yaml | 8 +++++--- .../backstage-operator.clusterserviceversion.yaml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bundle/manifests/backstage-default-config_v1_configmap.yaml b/bundle/manifests/backstage-default-config_v1_configmap.yaml index 4ddbf903..48dc3797 100644 --- a/bundle/manifests/backstage-default-config_v1_configmap.yaml +++ b/bundle/manifests/backstage-default-config_v1_configmap.yaml @@ -76,7 +76,8 @@ data: envFrom: - secretRef: name: # will be replaced with 'backstage-psql-secrets-' - image: # will be replaced with the actual image + # image will be replaced by the value of the `RELATED_IMAGE_postgresql` env var, if set + image: quay.io/fedora/postgresql-15:latest imagePullPolicy: IfNotPresent securityContext: runAsNonRoot: true @@ -188,7 +189,8 @@ data: env: - name: NPM_CONFIG_USERCONFIG value: /opt/app-root/src/.npmrc.dynamic-plugins - image: # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next + # image will be replaced by the value of the `RELATED_IMAGE_backstage` env var, if set + image: quay.io/janus-idp/backstage-showcase:latest imagePullPolicy: IfNotPresent name: install-dynamic-plugins volumeMounts: @@ -202,7 +204,7 @@ data: containers: - name: backstage-backend - image: # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next + image: quay.io/janus-idp/backstage-showcase:latest imagePullPolicy: IfNotPresent args: - "--config" diff --git a/bundle/manifests/backstage-operator.clusterserviceversion.yaml b/bundle/manifests/backstage-operator.clusterserviceversion.yaml index 6ccfb951..ecd07b7a 100644 --- a/bundle/manifests/backstage-operator.clusterserviceversion.yaml +++ b/bundle/manifests/backstage-operator.clusterserviceversion.yaml @@ -21,7 +21,7 @@ metadata: } ] capabilities: Seamless Upgrades - createdAt: "2024-01-29T20:18:14Z" + createdAt: "2024-02-12T14:45:30Z" operatorframework.io/suggested-namespace: backstage-system operators.operatorframework.io/builder: operator-sdk-v1.33.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 From d1030265b322cf8ef4ae24a5d529404a56253050 Mon Sep 17 00:00:00 2001 From: gazarenkov Date: Tue, 13 Feb 2024 09:12:59 +0200 Subject: [PATCH 11/12] fix image --- ...backstage-default-config_v1_configmap.yaml | 26 +++++++++++++++---- ...kstage-operator.clusterserviceversion.yaml | 8 +++--- config/manager/manager.yaml | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bundle/manifests/backstage-default-config_v1_configmap.yaml b/bundle/manifests/backstage-default-config_v1_configmap.yaml index 48dc3797..5e6056f0 100644 --- a/bundle/manifests/backstage-default-config_v1_configmap.yaml +++ b/bundle/manifests/backstage-default-config_v1_configmap.yaml @@ -62,9 +62,13 @@ data: janus-idp.io/app: backstage-psql-cr1 # placeholder for 'backstage-psql-' name: backstage-db-cr1 # placeholder for 'backstage-psql-' spec: - persistentVolumeClaimRetentionPolicy: - whenDeleted: Retain - whenScaled: Retain + automountServiceAccountToken: false + ## https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/ + ## The optional .spec.persistentVolumeClaimRetentionPolicy field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. + ## You must enable the StatefulSetAutoDeletePVC feature gate on the API server and the controller manager to use this field. + # persistentVolumeClaimRetentionPolicy: + # whenDeleted: Retain + # whenScaled: Retain containers: - env: - name: POSTGRESQL_PORT_NUMBER @@ -121,7 +125,9 @@ data: cpu: 250m memory: 256Mi limits: + cpu: 250m memory: 1024Mi + ephemeral-storage: 20Mi volumeMounts: - mountPath: /dev/shm name: dshm @@ -165,7 +171,7 @@ data: labels: janus-idp.io/app: # placeholder for 'backstage-' spec: - # serviceAccountName: default + automountServiceAccountToken: false volumes: - ephemeral: volumeClaimTemplate: @@ -201,9 +207,14 @@ data: readOnly: true subPath: .npmrc workingDir: /opt/app-root/src - + resources: + limits: + cpu: 1000m + memory: 2.5Gi + ephemeral-storage: 5Gi containers: - name: backstage-backend + # image will be replaced by the value of the `RELATED_IMAGE_backstage` env var, if set image: quay.io/janus-idp/backstage-showcase:latest imagePullPolicy: IfNotPresent args: @@ -243,6 +254,11 @@ data: volumeMounts: - mountPath: /opt/app-root/src/dynamic-plugins-root name: dynamic-plugins-root + resources: + limits: + cpu: 1000m + memory: 2.5Gi + ephemeral-storage: 5Gi dynamic-plugins-configmap.yaml: |- apiVersion: v1 kind: ConfigMap diff --git a/bundle/manifests/backstage-operator.clusterserviceversion.yaml b/bundle/manifests/backstage-operator.clusterserviceversion.yaml index ecd07b7a..bc3be853 100644 --- a/bundle/manifests/backstage-operator.clusterserviceversion.yaml +++ b/bundle/manifests/backstage-operator.clusterserviceversion.yaml @@ -21,7 +21,7 @@ metadata: } ] capabilities: Seamless Upgrades - createdAt: "2024-02-12T14:45:30Z" + createdAt: "2024-02-13T07:11:47Z" operatorframework.io/suggested-namespace: backstage-system operators.operatorframework.io/builder: operator-sdk-v1.33.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 @@ -185,6 +185,7 @@ spec: operator: In values: - linux + automountServiceAccountToken: true containers: - args: - --secure-listen-address=0.0.0.0:8443 @@ -219,7 +220,7 @@ spec: - name: RELATED_IMAGE_postgresql value: quay.io/fedora/postgresql-15:latest - name: RELATED_IMAGE_backstage - value: quay.io/janus-idp/backstage-showcase:next + value: quay.io/janus-idp/backstage-showcase:latest image: quay.io/janus-idp/operator:0.0.1 livenessProbe: httpGet: @@ -237,6 +238,7 @@ spec: resources: limits: cpu: 500m + ephemeral-storage: 20Mi memory: 128Mi requests: cpu: 10m @@ -322,6 +324,6 @@ spec: relatedImages: - image: quay.io/fedora/postgresql-15:latest name: postgresql - - image: quay.io/janus-idp/backstage-showcase:next + - image: quay.io/janus-idp/backstage-showcase:latest name: backstage version: 0.0.1 diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 914f0aa8..f11e35fb 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -76,7 +76,7 @@ spec: - name: RELATED_IMAGE_postgresql value: quay.io/fedora/postgresql-15:latest - name: RELATED_IMAGE_backstage - value: quay.io/janus-idp/backstage-showcase:next + value: quay.io/janus-idp/backstage-showcase:latest image: controller:latest name: manager securityContext: From 7f4ec9de3926283c300a53ee6f08de33e4c5ffbe Mon Sep 17 00:00:00 2001 From: gazarenkov Date: Thu, 15 Feb 2024 15:03:17 +0200 Subject: [PATCH 12/12] fix service raw config --- controllers/backstage_controller.go | 4 ++-- controllers/backstage_service.go | 7 +++++++ controllers/local_db_services.go | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/controllers/backstage_controller.go b/controllers/backstage_controller.go index e3c2a65c..3cffea8c 100644 --- a/controllers/backstage_controller.go +++ b/controllers/backstage_controller.go @@ -183,13 +183,13 @@ func (r *BackstageReconciler) readConfigMapOrDefault(ctx context.Context, name s val, ok := cm.Data[key] if !ok { // key not found, default - lg.V(1).Info("custom configuration configMap and data exists, trying to apply it", "configMap", cm.Name, "key", key) + lg.V(1).Info("custom configuration configMap exists but no such key, applying default config", "configMap", cm.Name, "key", key) err := readYamlFile(defFile(key), object) if err != nil { return fmt.Errorf("failed to read YAML file: %w", err) } } else { - lg.V(1).Info("custom configuration configMap exists but no such key, applying default config", "configMap", cm.Name, "key", key) + lg.V(1).Info("custom configuration configMap and data exists, trying to apply it", "configMap", cm.Name, "key", key) err := readYaml([]byte(val), object) if err != nil { return fmt.Errorf("failed to read YAML: %w", err) diff --git a/controllers/backstage_service.go b/controllers/backstage_service.go index 1176f732..f479a2bb 100644 --- a/controllers/backstage_service.go +++ b/controllers/backstage_service.go @@ -33,14 +33,19 @@ func (r *BackstageReconciler) reconcileBackstageService(ctx context.Context, bac Namespace: ns, }, } + if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, service, r.serviceObjectMutFun(ctx, service, *backstage, backstage.Spec.RawRuntimeConfig.BackstageConfigName, "service.yaml", service.Name, service.Name)); err != nil { + if errors.IsConflict(err) { return retryReconciliation(err) } msg := fmt.Sprintf("failed to deploy Backstage Service: %s", err) + setStatusCondition(backstage, bs.ConditionDeployed, metav1.ConditionFalse, bs.DeployFailed, msg) + return fmt.Errorf("%s %w", msg, err) } + return nil } @@ -49,6 +54,7 @@ func (r *BackstageReconciler) reconcileBackstageService(ctx context.Context, bac func (r *BackstageReconciler) serviceObjectMutFun(ctx context.Context, targetService *corev1.Service, backstage bs.Backstage, configName, configKey, serviceName, label string) controllerutil.MutateFn { return func() error { + service := &corev1.Service{} targetService.ObjectMeta.DeepCopyInto(&service.ObjectMeta) @@ -75,6 +81,7 @@ func (r *BackstageReconciler) serviceObjectMutFun(ctx context.Context, targetSer service.ObjectMeta.DeepCopyInto(&targetService.ObjectMeta) service.Spec.DeepCopyInto(&targetService.Spec) + return nil } } diff --git a/controllers/local_db_services.go b/controllers/local_db_services.go index a64441e5..51418bc8 100644 --- a/controllers/local_db_services.go +++ b/controllers/local_db_services.go @@ -85,6 +85,7 @@ func (r *BackstageReconciler) reconcilePsqlService(ctx context.Context, backstag } msg := fmt.Sprintf("failed to deploy database service: %s", err) setStatusCondition(backstage, bs.ConditionDeployed, metav1.ConditionFalse, bs.DeployFailed, msg) + return fmt.Errorf("%s %w", msg, err) } return nil }