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

Commit 59c878f

Browse files
openshift-cherrypick-robotgazarenkovrm3l
authored
[1.1.x] Avoid hardcoded images (#196)
* remove hardcoded images * fix image * Update examples/janus-cr-with-app-configs.yaml Co-authored-by: Armel Soro <armel@rm3l.org> * change lookup * Update config/manager/default-config/db-statefulset.yaml Co-authored-by: Armel Soro <armel@rm3l.org> * Update config/manager/default-config/deployment.yaml Co-authored-by: Armel Soro <armel@rm3l.org> * change lookup * change lookup * Update config/manager/default-config/deployment.yaml Co-authored-by: Armel Soro <armel@rm3l.org> * add generated files * fix image --------- Co-authored-by: gazarenkov <gazarenkov@gmail.com> Co-authored-by: Armel Soro <armel@rm3l.org>
1 parent a10844d commit 59c878f

12 files changed

+72
-259
lines changed

api/v1alpha1/backstage_types.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ const (
2727
DeployInProgress string = "DeployInProgress"
2828
)
2929

30-
// Constants for image placeholders
31-
const (
32-
EnvPostGresImage string = "RELATED_IMAGE_postgresql"
33-
EnvBackstageImage string = "RELATED_IMAGE_backstage"
34-
)
35-
3630
// BackstageSpec defines the desired state of Backstage
3731
type BackstageSpec struct {
3832
// Configuration for Backstage. Optional.

bundle/manifests/backstage-default-config_v1_configmap.yaml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ data:
6262
janus-idp.io/app: backstage-psql-cr1 # placeholder for 'backstage-psql-<cr-name>'
6363
name: backstage-db-cr1 # placeholder for 'backstage-psql-<cr-name>'
6464
spec:
65-
persistentVolumeClaimRetentionPolicy:
66-
whenDeleted: Retain
67-
whenScaled: Retain
65+
automountServiceAccountToken: false
66+
## https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/
67+
## The optional .spec.persistentVolumeClaimRetentionPolicy field controls if and how PVCs are deleted during the lifecycle of a StatefulSet.
68+
## You must enable the StatefulSetAutoDeletePVC feature gate on the API server and the controller manager to use this field.
69+
# persistentVolumeClaimRetentionPolicy:
70+
# whenDeleted: Retain
71+
# whenScaled: Retain
6872
containers:
6973
- env:
7074
- name: POSTGRESQL_PORT_NUMBER
@@ -76,7 +80,8 @@ data:
7680
envFrom:
7781
- secretRef:
7882
name: <POSTGRESQL_SECRET> # will be replaced with 'backstage-psql-secrets-<cr-name>'
79-
image: <RELATED_IMAGE_postgresql> # will be replaced with the actual image
83+
# image will be replaced by the value of the `RELATED_IMAGE_postgresql` env var, if set
84+
image: quay.io/fedora/postgresql-15:latest
8085
imagePullPolicy: IfNotPresent
8186
securityContext:
8287
runAsNonRoot: true
@@ -120,7 +125,9 @@ data:
120125
cpu: 250m
121126
memory: 256Mi
122127
limits:
128+
cpu: 250m
123129
memory: 1024Mi
130+
ephemeral-storage: 20Mi
124131
volumeMounts:
125132
- mountPath: /dev/shm
126133
name: dshm
@@ -164,7 +171,7 @@ data:
164171
labels:
165172
janus-idp.io/app: # placeholder for 'backstage-<cr-name>'
166173
spec:
167-
# serviceAccountName: default
174+
automountServiceAccountToken: false
168175
volumes:
169176
- ephemeral:
170177
volumeClaimTemplate:
@@ -188,7 +195,8 @@ data:
188195
env:
189196
- name: NPM_CONFIG_USERCONFIG
190197
value: /opt/app-root/src/.npmrc.dynamic-plugins
191-
image: <RELATED_IMAGE_backstage> # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next
198+
# image will be replaced by the value of the `RELATED_IMAGE_backstage` env var, if set
199+
image: quay.io/janus-idp/backstage-showcase:latest
192200
imagePullPolicy: IfNotPresent
193201
name: install-dynamic-plugins
194202
volumeMounts:
@@ -199,10 +207,15 @@ data:
199207
readOnly: true
200208
subPath: .npmrc
201209
workingDir: /opt/app-root/src
202-
210+
resources:
211+
limits:
212+
cpu: 1000m
213+
memory: 2.5Gi
214+
ephemeral-storage: 5Gi
203215
containers:
204216
- name: backstage-backend
205-
image: <RELATED_IMAGE_backstage> # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next
217+
# image will be replaced by the value of the `RELATED_IMAGE_backstage` env var, if set
218+
image: quay.io/janus-idp/backstage-showcase:latest
206219
imagePullPolicy: IfNotPresent
207220
args:
208221
- "--config"
@@ -241,6 +254,11 @@ data:
241254
volumeMounts:
242255
- mountPath: /opt/app-root/src/dynamic-plugins-root
243256
name: dynamic-plugins-root
257+
resources:
258+
limits:
259+
cpu: 1000m
260+
memory: 2.5Gi
261+
ephemeral-storage: 5Gi
244262
dynamic-plugins-configmap.yaml: |-
245263
apiVersion: v1
246264
kind: ConfigMap

bundle/manifests/backstage-operator.clusterserviceversion.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ metadata:
2121
}
2222
]
2323
capabilities: Seamless Upgrades
24-
createdAt: "2024-01-29T20:18:14Z"
24+
createdAt: "2024-02-13T07:11:47Z"
2525
operatorframework.io/suggested-namespace: backstage-system
2626
operators.operatorframework.io/builder: operator-sdk-v1.33.0
2727
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
@@ -185,6 +185,7 @@ spec:
185185
operator: In
186186
values:
187187
- linux
188+
automountServiceAccountToken: true
188189
containers:
189190
- args:
190191
- --secure-listen-address=0.0.0.0:8443
@@ -219,7 +220,7 @@ spec:
219220
- name: RELATED_IMAGE_postgresql
220221
value: quay.io/fedora/postgresql-15:latest
221222
- name: RELATED_IMAGE_backstage
222-
value: quay.io/janus-idp/backstage-showcase:next
223+
value: quay.io/janus-idp/backstage-showcase:latest
223224
image: quay.io/janus-idp/operator:0.0.1
224225
livenessProbe:
225226
httpGet:
@@ -237,6 +238,7 @@ spec:
237238
resources:
238239
limits:
239240
cpu: 500m
241+
ephemeral-storage: 20Mi
240242
memory: 128Mi
241243
requests:
242244
cpu: 10m
@@ -322,6 +324,6 @@ spec:
322324
relatedImages:
323325
- image: quay.io/fedora/postgresql-15:latest
324326
name: postgresql
325-
- image: quay.io/janus-idp/backstage-showcase:next
327+
- image: quay.io/janus-idp/backstage-showcase:latest
326328
name: backstage
327329
version: 0.0.1

config/manager/default-config/db-statefulset.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ spec:
3333
envFrom:
3434
- secretRef:
3535
name: <POSTGRESQL_SECRET> # will be replaced with 'backstage-psql-secrets-<cr-name>'
36-
image: <RELATED_IMAGE_postgresql> # will be replaced with the actual image
36+
# image will be replaced by the value of the `RELATED_IMAGE_postgresql` env var, if set
37+
image: quay.io/fedora/postgresql-15:latest
3738
imagePullPolicy: IfNotPresent
3839
securityContext:
3940
runAsNonRoot: true

config/manager/default-config/deployment.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ spec:
3636
env:
3737
- name: NPM_CONFIG_USERCONFIG
3838
value: /opt/app-root/src/.npmrc.dynamic-plugins
39-
image: <RELATED_IMAGE_backstage> # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next
39+
# image will be replaced by the value of the `RELATED_IMAGE_backstage` env var, if set
40+
image: quay.io/janus-idp/backstage-showcase:latest
4041
imagePullPolicy: IfNotPresent
4142
name: install-dynamic-plugins
4243
volumeMounts:
@@ -54,7 +55,8 @@ spec:
5455
ephemeral-storage: 5Gi
5556
containers:
5657
- name: backstage-backend
57-
image: <RELATED_IMAGE_backstage> # will be replaced with the actual image quay.io/janus-idp/backstage-showcase:next
58+
# image will be replaced by the value of the `RELATED_IMAGE_backstage` env var, if set
59+
image: quay.io/janus-idp/backstage-showcase:latest
5860
imagePullPolicy: IfNotPresent
5961
args:
6062
- "--config"

config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ spec:
7676
- name: RELATED_IMAGE_postgresql
7777
value: quay.io/fedora/postgresql-15:latest
7878
- name: RELATED_IMAGE_backstage
79-
value: quay.io/janus-idp/backstage-showcase:next
79+
value: quay.io/janus-idp/backstage-showcase:latest
8080
image: controller:latest
8181
name: manager
8282
securityContext:

controllers/backstage_controller.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ const (
4141
BackstageAppLabel = "janus-idp.io/app"
4242
)
4343

44+
var (
45+
envPostgresImage string
46+
envBackstageImage string
47+
)
48+
4449
// BackstageReconciler reconciles a Backstage object
4550
type BackstageReconciler struct {
4651
client.Client
@@ -56,10 +61,6 @@ type BackstageReconciler struct {
5661
Namespace string
5762

5863
IsOpenShift bool
59-
60-
PsqlImage string
61-
62-
BackstageImage string
6364
}
6465

6566
//+kubebuilder:rbac:groups=janus-idp.io,resources=backstages,verbs=get;list;watch;create;update;patch;delete
@@ -295,14 +296,13 @@ func (r *BackstageReconciler) labels(meta *v1.ObjectMeta, backstage bs.Backstage
295296

296297
// SetupWithManager sets up the controller with the Manager.
297298
func (r *BackstageReconciler) SetupWithManager(mgr ctrl.Manager, log logr.Logger) error {
298-
if len(r.PsqlImage) == 0 {
299-
r.PsqlImage = "quay.io/fedora/postgresql-15:latest"
300-
log.Info("Enviroment variable is not set, default is used", bs.EnvPostGresImage, r.PsqlImage)
301-
}
302299

303-
if len(r.BackstageImage) == 0 {
304-
r.BackstageImage = "quay.io/janus-idp/backstage-showcase:next"
305-
log.Info("Enviroment variable is not set, default is used", bs.EnvBackstageImage, r.BackstageImage)
300+
var ok bool
301+
if envPostgresImage, ok = os.LookupEnv("RELATED_IMAGE_postgresql"); !ok {
302+
log.Info("RELATED_IMAGE_postgresql environment variable is not set, default will be used")
303+
}
304+
if envBackstageImage, ok = os.LookupEnv("RELATED_IMAGE_backstage"); !ok {
305+
log.Info("RELATED_IMAGE_backstage environment variable is not set, default will be used")
306306
}
307307

308308
builder := ctrl.NewControllerManagedBy(mgr).

controllers/backstage_controller_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ var _ = Describe("Backstage controller", func() {
6161
Expect(err).To(Not(HaveOccurred()))
6262

6363
backstageReconciler = &BackstageReconciler{
64-
Client: k8sClient,
65-
Scheme: k8sClient.Scheme(),
66-
Namespace: ns,
67-
OwnsRuntime: true,
68-
PsqlImage: "test-postgresql-15:latest",
69-
BackstageImage: "test-backstage-showcase:next",
64+
Client: k8sClient,
65+
Scheme: k8sClient.Scheme(),
66+
Namespace: ns,
67+
OwnsRuntime: true,
68+
//PsqlImage: "test-postgresql-15:latest",
69+
//BackstageImage: "test-backstage-showcase:next",
7070
}
7171
})
7272

controllers/backstage_deployment.go

Lines changed: 6 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -33,103 +33,6 @@ const (
3333
_containersWorkingDir = "/opt/app-root/src"
3434
)
3535

36-
//var (
37-
// DefaultBackstageDeployment = fmt.Sprintf(`
38-
//apiVersion: apps/v1
39-
//kind: Deployment
40-
//metadata:
41-
// name: backstage
42-
//spec:
43-
// replicas: 1
44-
// selector:
45-
// matchLabels:
46-
// janus-idp.io/app: # placeholder for 'backstage-<cr-name>'
47-
// template:
48-
// metadata:
49-
// labels:
50-
// janus-idp.io/app: # placeholder for 'backstage-<cr-name>'
51-
// spec:
52-
//# serviceAccountName: default
53-
//
54-
// volumes:
55-
// - ephemeral:
56-
// volumeClaimTemplate:
57-
// spec:
58-
// accessModes:
59-
// - ReadWriteOnce
60-
// resources:
61-
// requests:
62-
// storage: 1Gi
63-
// name: dynamic-plugins-root
64-
// - name: dynamic-plugins-npmrc
65-
// secret:
66-
// defaultMode: 420
67-
// optional: true
68-
// secretName: dynamic-plugins-npmrc
69-
//
70-
// initContainers:
71-
// - command:
72-
// - ./install-dynamic-plugins.sh
73-
// - /dynamic-plugins-root
74-
// env:
75-
// - name: NPM_CONFIG_USERCONFIG
76-
// value: %[3]s/.npmrc.dynamic-plugins
77-
// image: 'quay.io/janus-idp/backstage-showcase:next'
78-
// imagePullPolicy: IfNotPresent
79-
// name: %[1]s
80-
// volumeMounts:
81-
// - mountPath: /dynamic-plugins-root
82-
// name: dynamic-plugins-root
83-
// - mountPath: %[3]s/.npmrc.dynamic-plugins
84-
// name: dynamic-plugins-npmrc
85-
// readOnly: true
86-
// subPath: .npmrc
87-
// workingDir: %[3]s
88-
//
89-
// containers:
90-
// - name: %[2]s
91-
// image: quay.io/janus-idp/backstage-showcase:next
92-
// imagePullPolicy: IfNotPresent
93-
// args:
94-
// - "--config"
95-
// - "dynamic-plugins-root/app-config.dynamic-plugins.yaml"
96-
// readinessProbe:
97-
// failureThreshold: 3
98-
// httpGet:
99-
// path: /healthcheck
100-
// port: 7007
101-
// scheme: HTTP
102-
// initialDelaySeconds: 30
103-
// periodSeconds: 10
104-
// successThreshold: 2
105-
// timeoutSeconds: 2
106-
// livenessProbe:
107-
// failureThreshold: 3
108-
// httpGet:
109-
// path: /healthcheck
110-
// port: 7007
111-
// scheme: HTTP
112-
// initialDelaySeconds: 60
113-
// periodSeconds: 10
114-
// successThreshold: 1
115-
// timeoutSeconds: 2
116-
// ports:
117-
// - name: http
118-
// containerPort: 7007
119-
// env:
120-
// - name: APP_CONFIG_backend_listen_port
121-
// value: "7007"
122-
// envFrom:
123-
// - secretRef:
124-
// name: postgres-secrets
125-
//# - secretRef:
126-
//# name: backstage-secrets
127-
// volumeMounts:
128-
// - mountPath: %[3]s/dynamic-plugins-root
129-
// name: dynamic-plugins-root
130-
//`, _defaultBackstageInitContainerName, _defaultBackstageMainContainerName, _containersWorkingDir)
131-
//)
132-
13336
// ContainerVisitor is called with each container
13437
type ContainerVisitor func(container *v1.Container)
13538

@@ -291,11 +194,12 @@ func (r *BackstageReconciler) validateAndUpdatePsqlSecretRef(backstage bs.Backst
291194
}
292195

293196
func (r *BackstageReconciler) setDefaultDeploymentImage(deployment *appsv1.Deployment) {
294-
visitContainers(&deployment.Spec.Template, func(container *v1.Container) {
295-
if len(container.Image) == 0 || container.Image == fmt.Sprintf("<%s>", bs.EnvBackstageImage) {
296-
container.Image = r.BackstageImage
297-
}
298-
})
197+
if envBackstageImage != "" {
198+
visitContainers(&deployment.Spec.Template, func(container *v1.Container) {
199+
container.Image = envBackstageImage
200+
201+
})
202+
}
299203
}
300204

301205
func (r *BackstageReconciler) applyBackstageLabels(backstage bs.Backstage, deployment *appsv1.Deployment) {

0 commit comments

Comments
 (0)