Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Refactor operator logic #70

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
cfb83b2
yaml/configMap default configuration
gazarenkov Nov 28, 2023
c952470
Merge remote-tracking branch 'upstream/main' into status2
gazarenkov Nov 28, 2023
9563358
fix make test
gazarenkov Nov 28, 2023
46f0e7f
Merge remote-tracking branch 'upstream/main' into status2
gazarenkov Nov 30, 2023
99b4e54
fix with new objects
gazarenkov Nov 30, 2023
cffa417
fix with new objects
gazarenkov Nov 30, 2023
2bf0716
config small fixes
gazarenkov Nov 30, 2023
47ba2f9
fix for https://github.com/janus-idp/operator/issues/51
gazarenkov Nov 30, 2023
5882f62
Merge branch 'main' of https://github.com/janus-idp/operator into sta…
gazarenkov Dec 2, 2023
4863874
Merge branch 'main' of https://github.com/janus-idp/operator into doc
gazarenkov Dec 6, 2023
4bdb1a0
fix for https://github.com/janus-idp/operator/issues/58
gazarenkov Dec 6, 2023
971a50c
init next (design improvement)
gazarenkov Dec 7, 2023
93d3de7
initial model
gazarenkov Dec 12, 2023
6da447e
initial model
gazarenkov Dec 12, 2023
8d8b84c
initial
gazarenkov Dec 13, 2023
f6a37c0
Merge remote-tracking branch 'upstream/main' into next
gazarenkov Dec 13, 2023
ac60557
initial
gazarenkov Dec 13, 2023
eb5f305
initial
gazarenkov Dec 15, 2023
19d923d
format and license
gazarenkov Dec 15, 2023
267a166
factory and pswd generator
gazarenkov Dec 17, 2023
20fbc03
delete onCreate handler
gazarenkov Dec 18, 2023
089f56c
support configmapfiles, dynamic-plugins
gazarenkov Dec 19, 2023
a1a671a
initial model test framework
gazarenkov Dec 19, 2023
a138de1
configurations
gazarenkov Dec 26, 2023
48a88ab
more comments and tests
gazarenkov Dec 28, 2023
8436faa
add more tests, remove old logic of object creation
gazarenkov Jan 4, 2024
18119c6
add more tests, remove old logic of object creation
gazarenkov Jan 5, 2024
7f937ba
add support of keys, integration tests passed
gazarenkov Jan 8, 2024
bb311a7
add support of keys, integration tests passed
gazarenkov Jan 8, 2024
63254a0
fix npe
gazarenkov Jan 8, 2024
3ddc1a6
cm envs
gazarenkov Jan 9, 2024
a8546da
Merge remote-tracking branch 'upstream/main' into next
gazarenkov Jan 9, 2024
e01826c
tmp
gazarenkov Jan 9, 2024
f413fc4
maintain images env var
gazarenkov Jan 9, 2024
6df33bd
fix lint
gazarenkov Jan 9, 2024
14dfdc6
remove unused params in status
gazarenkov Jan 9, 2024
9517959
fix make release-build
gazarenkov Jan 10, 2024
e24518d
fix default images
gazarenkov Jan 11, 2024
90acacd
several fixes
gazarenkov Jan 11, 2024
e9e115e
fix route.Spec.To.Name
gazarenkov Jan 11, 2024
2bd9697
fix image env vars
gazarenkov Jan 11, 2024
aca67ba
fix dynamic plugins
gazarenkov Jan 12, 2024
fd2e042
Merge remote-tracking branch 'upstream/main' into next
gazarenkov Jan 12, 2024
3a58242
fix
gazarenkov Jan 12, 2024
6c5cb9d
dynamic-plugins test
gazarenkov Jan 15, 2024
2c44c4e
remove ownership of depl, ss, service
gazarenkov Jan 15, 2024
245c6c1
DbSecret and Route
gazarenkov Jan 22, 2024
3877ae9
clean up
gazarenkov Jan 22, 2024
2dceb0d
make test
gazarenkov Jan 22, 2024
da7d4cd
Merge remote-tracking branch 'upstream/main' into next
gazarenkov Jan 23, 2024
ee7654e
clean db
gazarenkov Jan 24, 2024
dcd9d92
Merge remote-tracking branch 'upstream/main' into next
gazarenkov Jan 25, 2024
98255bb
status
gazarenkov Jan 25, 2024
6debb33
Merge remote-tracking branch 'upstream/main' into next
gazarenkov Jan 25, 2024
0d4552d
fix gosec
gazarenkov Jan 25, 2024
b087290
cleanup
gazarenkov Jan 26, 2024
52c9b87
route fix
gazarenkov Jan 26, 2024
abfd664
patch and route
gazarenkov Jan 29, 2024
a6d4d79
fix lint
gazarenkov Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Output:

## License

Copyright 2023 Red Hat Inc..
Copyright 2023 Red Hat Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
63 changes: 40 additions & 23 deletions api/v1alpha1/backstage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)

// Constants for status conditions
const (
// TODO: RuntimeConditionRunning string = "RuntimeRunning"
ConditionDeployed string = "Deployed"
DeployOK string = "DeployOK"
DeployFailed string = "DeployFailed"
DeployInProgress string = "DeployInProgress"
)
type BackstageConditionReason string

type BackstageConditionType string

// Constants for image placeholders
const (
EnvPostGresImage string = "RELATED_IMAGE_postgresql"
EnvBackstageImage string = "RELATED_IMAGE_backstage"
BackstageConditionTypeDeployed BackstageConditionType = "Deployed"

BackstageConditionReasonDeployed BackstageConditionReason = "Deployed"
BackstageConditionReasonFailed BackstageConditionReason = "DeployFailed"
BackstageConditionReasonInProgress BackstageConditionReason = "DeployInProgress"
)

// BackstageSpec defines the desired state of Backstage
Expand All @@ -39,10 +37,10 @@ type BackstageSpec struct {
Application *Application `json:"application,omitempty"`

// Raw Runtime Objects configuration. For Advanced scenarios.
RawRuntimeConfig RuntimeConfig `json:"rawRuntimeConfig,omitempty"`
RawRuntimeConfig string `json:"rawRuntimeConfig,omitempty"`

// Configuration for database access. Optional.
Database Database `json:"database,omitempty"`
Database *Database `json:"database,omitempty"`
}

type Database struct {
Expand All @@ -51,8 +49,8 @@ type Database struct {
//+kubebuilder:default=true
EnableLocalDb *bool `json:"enableLocalDb,omitempty"`

// Name of the secret for database authentication. Optional.
// For a local database deployment (EnableLocalDb=true), a secret will be auto generated if it does not exist.
// Name of the secret for database authentication. Required for external database access.
// Optional for a local database (EnableLocalDb=true) and if absent a secret will be auto generated.
// The secret shall include information used for the database access.
// An example for PostgreSQL DB access:
// "POSTGRES_PASSWORD": "rl4s3Fh4ng3M4"
Expand Down Expand Up @@ -103,7 +101,7 @@ type Application struct {

// Image Pull Secrets to use in all containers (including Init Containers)
// +optional
ImagePullSecrets *[]string `json:"imagePullSecrets,omitempty"`
ImagePullSecrets []string `json:"imagePullSecrets,omitempty"`

// Route configuration. Used for OpenShift only.
Route *Route `json:"route,omitempty"`
Expand Down Expand Up @@ -183,13 +181,6 @@ type Env struct {
Value string `json:"value"`
}

type RuntimeConfig struct {
// Name of ConfigMap containing Backstage runtime objects configuration
BackstageConfigName string `json:"backstageConfig,omitempty"`
// Name of ConfigMap containing LocalDb (P|ostgreSQL) runtime objects configuration
LocalDbConfigName string `json:"localDbConfig,omitempty"`
}

// BackstageStatus defines the observed state of Backstage
type BackstageStatus struct {
// Conditions is the list of conditions describing the state of the runtime
Expand Down Expand Up @@ -274,3 +265,29 @@ type TLS struct {
func init() {
SchemeBuilder.Register(&Backstage{}, &BackstageList{})
}

func (s BackstageSpec) IsLocalDbEnabled() bool {
if s.Database == nil {
return true
}
return pointer.BoolDeref(s.Database.EnableLocalDb, true)
}

func (s BackstageSpec) IsRouteEnabled() bool {
if s.Application == nil || s.Application.Route == nil {
return false
}
return pointer.BoolDeref(s.Application.Route.Enabled, true)
}

func (s BackstageSpec) IsRouteEmpty() bool {
route := s.Application.Route
if route.Host != "" && route.Subdomain != "" && route.TLS != nil && *route.TLS != (TLS{}) {
return true
}
return false
}

func (s BackstageSpec) IsAuthSecretSpecified() bool {
return s.Database != nil && s.Database.AuthSecretName != ""
}
30 changes: 7 additions & 23 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 42 additions & 20 deletions bundle/manifests/backstage-default-config_v1_configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
apiVersion: v1
data:
backend-auth-configmap.yaml: |
app-config.yaml: |-
apiVersion: v1
kind: ConfigMap
metadata:
name: # placeholder for '<cr-name>-backend-auth'
name: my-backstage-config-cm1 # placeholder for <bs>-default-appconfig
data:
"app-config.backend-auth.default.yaml": |
default.app-config.yaml: |
backend:
database:
connection:
password: ${POSTGRES_PASSWORD}
user: ${POSTGRES_USER}
auth:
keys:
# This is a default value, which you should change by providing your own app-config
- secret: "pl4s3Ch4ng3M3"
db-secret.yaml: |
db-secret.yaml: |-
apiVersion: v1
kind: Secret
metadata:
name: # placeholder for 'backstage-psql-secret-<cr-name>'
name: postgres-secrets # will be replaced
namespace: backstage
type: Opaque
stringData:
"POSTGRES_PASSWORD": "rl4s3Fh4ng3M4" # default value, change to your own value
"POSTGRES_PORT": "5432"
"POSTGRES_USER": "postgres"
"POSTGRESQL_ADMIN_PASSWORD": "rl4s3Fh4ng3M4" # default value, change to your own value
"POSTGRES_HOST": "" # set to your Postgres DB host. If the local DB is deployed, set to 'backstage-psql-<cr-name>'
POSTGRES_PASSWORD: #wrgd5688 #admin123 # leave it empty to make it autogenerated
POSTGRES_PORT: "5432"
POSTGRES_USER: postgres
POSTGRESQL_ADMIN_PASSWORD: admin123
POSTGRES_HOST: bs1-db-service #placeholder <crname>-db-service
db-service-hl.yaml: |
apiVersion: v1
kind: Service
Expand All @@ -44,7 +50,7 @@ data:
janus-idp.io/app: backstage-psql-cr1 # placeholder for 'backstage-psql-<cr-name>'
ports:
- port: 5432
db-statefulset.yaml: |
db-statefulset.yaml: |-
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand Down Expand Up @@ -74,8 +80,9 @@ data:
- name: PGDATA
value: /var/lib/pgsql/data/userdata
envFrom:
- secretRef:
name: <POSTGRESQL_SECRET> # will be replaced with 'backstage-psql-secrets-<cr-name>'
# - secretRef:
# name: <POSTGRESQL_SECRET> # will be replaced with 'backstage-psql-secrets-<cr-name>'
# image: quay.io/fedora/postgresql-15:latest
image: <RELATED_IMAGE_postgresql> # will be replaced with the actual image
imagePullPolicy: IfNotPresent
securityContext:
Expand Down Expand Up @@ -180,6 +187,13 @@ data:
defaultMode: 420
optional: true
secretName: dynamic-plugins-npmrc
- name: dynamic-plugins-conf
configMap:
name: default-dynamic-plugins
optional: true
items:
- key: dynamic-plugins.yaml
path: dynamic-plugins.yaml

initContainers:
- command:
Expand All @@ -198,6 +212,10 @@ data:
name: dynamic-plugins-npmrc
readOnly: true
subPath: .npmrc
- mountPath: /opt/app-root/src/dynamic-plugins.yaml
subPath: dynamic-plugins.yaml
name: dynamic-plugins-conf
readOnly: true
workingDir: /opt/app-root/src

containers:
Expand Down Expand Up @@ -233,19 +251,14 @@ data:
env:
- name: APP_CONFIG_backend_listen_port
value: "7007"
envFrom:
- secretRef:
name: <POSTGRESQL_SECRET> # will be replaced with 'backstage-psql-secrets-<cr-name>'
# - secretRef:
# name: backstage-secrets
volumeMounts:
- mountPath: /opt/app-root/src/dynamic-plugins-root
name: dynamic-plugins-root
dynamic-plugins-configmap.yaml: |-
dynamic-plugins.yaml: |-
apiVersion: v1
kind: ConfigMap
metadata:
name: # placeholder for '<cr-name>-dynamic-plugins'
name: default-dynamic-plugins # must be the same as (deployment.yaml).spec.template.spec.volumes.name.dynamic-plugins-conf.configMap.name
data:
"dynamic-plugins.yaml": |
includes:
Expand All @@ -266,6 +279,15 @@ data:
to:
kind: Service
name: # placeholder for 'backstage-<cr-name>'
secret-envs.yaml: |
apiVersion: v1
kind: Secret
metadata:
name: backend-auth-secret
stringData:
# generated with the command below (from https://janus-idp.io/docs/auth/service-to-service-auth/#setup):
# node -p 'require("crypto").randomBytes(24).toString("base64")'
BACKEND_SECRET: "R2FxRVNrcmwzYzhhN3l0V1VRcnQ3L1pLT09WaVhDNUEK" # notsecret
service.yaml: |-
apiVersion: v1
kind: Service
Expand Down
11 changes: 1 addition & 10 deletions bundle/manifests/janus-idp.io_backstages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,7 @@ spec:
type: object
rawRuntimeConfig:
description: Raw Runtime Objects configuration. For Advanced scenarios.
properties:
backstageConfig:
description: Name of ConfigMap containing Backstage runtime objects
configuration
type: string
localDbConfig:
description: Name of ConfigMap containing LocalDb (P|ostgreSQL)
runtime objects configuration
type: string
type: object
type: string
type: object
status:
description: BackstageStatus defines the observed state of Backstage
Expand Down
26 changes: 9 additions & 17 deletions config/crd/bases/janus-idp.io_backstages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,14 @@ spec:
properties:
authSecretName:
description: 'Name of the secret for database authentication.
Optional. For a local database deployment (EnableLocalDb=true),
a secret will be auto generated if it does not exist. The secret
shall include information used for the database access. An example
for PostgreSQL DB access: "POSTGRES_PASSWORD": "rl4s3Fh4ng3M4"
"POSTGRES_PORT": "5432" "POSTGRES_USER": "postgres" "POSTGRESQL_ADMIN_PASSWORD":
"rl4s3Fh4ng3M4" "POSTGRES_HOST": "backstage-psql-bs1" # For
local database, set to "backstage-psql-<CR name>".'
Required for external database access. Optional for a local
database (EnableLocalDb=true) and if absent a secret will be
auto generated. The secret shall include information used for
the database access. An example for PostgreSQL DB access: "POSTGRES_PASSWORD":
"rl4s3Fh4ng3M4" "POSTGRES_PORT": "5432" "POSTGRES_USER": "postgres"
"POSTGRESQL_ADMIN_PASSWORD": "rl4s3Fh4ng3M4" "POSTGRES_HOST":
"backstage-psql-bs1" # For local database, set to "backstage-psql-<CR
name>".'
type: string
enableLocalDb:
default: true
Expand All @@ -284,16 +285,7 @@ spec:
type: object
rawRuntimeConfig:
description: Raw Runtime Objects configuration. For Advanced scenarios.
properties:
backstageConfig:
description: Name of ConfigMap containing Backstage runtime objects
configuration
type: string
localDbConfig:
description: Name of ConfigMap containing LocalDb (P|ostgreSQL)
runtime objects configuration
type: string
type: object
type: string
type: object
status:
description: BackstageStatus defines the observed state of Backstage
Expand Down
15 changes: 15 additions & 0 deletions config/manager/default-config/app-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: my-backstage-config-cm1 # placeholder for <bs>-default-appconfig
data:
default.app-config.yaml: |
backend:
database:
connection:
password: ${POSTGRES_PASSWORD}
user: ${POSTGRES_USER}
auth:
keys:
# This is a default value, which you should change by providing your own app-config
- secret: "pl4s3Ch4ng3M3"
11 changes: 0 additions & 11 deletions config/manager/default-config/backend-auth-configmap.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions config/manager/default-config/configmap-envs.yaml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: my-env-cm-1
data:
CM_ENV1: "cm env 1"
CM_ENV2: "cm env 2"
Loading
Loading