Skip to content

Commit

Permalink
overwrite only backstage and init-dynamic-plugins image. fix for http…
Browse files Browse the repository at this point in the history
…s://issues.redhat.com/browse/RHIDP-1701  (#279)

* overwrite only backstage and init-dynamic-plugins image

* overwrite only backstage and init-dynamic-plugins image

* overwrite only backstage and init-dynamic-plugins image

* overwrite only backstage and init-dynamic-plugins image

* fix Postgre description
  • Loading branch information
gazarenkov committed Apr 2, 2024
1 parent aa586ee commit 8643ba5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
31 changes: 28 additions & 3 deletions controllers/backstage_controller_test.go
Expand Up @@ -490,14 +490,23 @@ spec:
app: bs1
spec:
containers:
- name: bs1
- name: backstage-backend
image: busybox
- name: sidecar
image: busybox
initContainers:
- name: install-dynamic-plugins
image: busybox
`,
})
err := k8sClient.Create(ctx, backstageConfigMap)
Expect(err).To(Not(HaveOccurred()))

img := "backstage"
backstage = buildBackstageCR(bsv1alpha1.BackstageSpec{
Application: &bsv1alpha1.Application{
Image: &img,
},
RawRuntimeConfig: bsv1alpha1.RuntimeConfig{
BackstageConfigName: backstageConfigMap.Name,
},
Expand All @@ -523,7 +532,21 @@ spec:
By("Checking if Deployment was successfully created in the reconciliation")
Eventually(func() error {
found := &appsv1.Deployment{}
return k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: getDefaultObjName(*backstage)}, found)
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: getDefaultObjName(*backstage)}, found); err != nil {
return err
}
Expect(len(found.Spec.Template.Spec.Containers)).To(Equal(2))
for i, c := range found.Spec.Template.Spec.Containers {
if c.Name == _defaultBackstageMainContainerName {
Expect(found.Spec.Template.Spec.Containers[i].Image).To(Equal("backstage"))
} else {
Expect(found.Spec.Template.Spec.Containers[i].Image).To(Equal("busybox"))
}
}
Expect(len(found.Spec.Template.Spec.InitContainers)).To(Equal(1))
Expect(found.Spec.Template.Spec.InitContainers[0].Image).To(Equal("backstage"))

return nil
}, time.Minute, time.Second).Should(Succeed())

By("Checking the latest Status added to the Backstage instance")
Expand Down Expand Up @@ -1315,7 +1338,9 @@ plugins: []
By("Checking that the image was set on all containers in the Pod Spec")
visitContainers(&found.Spec.Template, func(container *corev1.Container) {
By(fmt.Sprintf("Checking Image in the Backstage Deployment - container: %q", container.Name), func() {
Expect(container.Image).Should(Equal(imageName))
if container.Name == _defaultBackstageMainContainerName || container.Name == _defaultBackstageInitContainerName {
Expect(container.Image).Should(Equal(imageName))
}
})
})

Expand Down
17 changes: 10 additions & 7 deletions controllers/backstage_deployment.go
Expand Up @@ -195,10 +195,7 @@ func (r *BackstageReconciler) validateAndUpdatePsqlSecretRef(backstage bs.Backst

func (r *BackstageReconciler) setDefaultDeploymentImage(deployment *appsv1.Deployment) {
if envBackstageImage != "" {
visitContainers(&deployment.Spec.Template, func(container *v1.Container) {
container.Image = envBackstageImage

})
setBackstageImage(deployment, envBackstageImage)
}
}

Expand All @@ -212,9 +209,7 @@ func (r *BackstageReconciler) applyApplicationParamsFromCR(backstage bs.Backstag
if backstage.Spec.Application != nil {
deployment.Spec.Replicas = backstage.Spec.Application.Replicas
if backstage.Spec.Application.Image != nil {
visitContainers(&deployment.Spec.Template, func(container *v1.Container) {
container.Image = *backstage.Spec.Application.Image
})
setBackstageImage(deployment, *backstage.Spec.Application.Image)
}
if backstage.Spec.Application.ImagePullSecrets != nil { // use image pull secrets from the CR spec
deployment.Spec.Template.Spec.ImagePullSecrets = nil
Expand All @@ -236,3 +231,11 @@ func getDefaultObjName(backstage bs.Backstage) string {
func getDefaultDbObjName(backstage bs.Backstage) string {
return fmt.Sprintf("backstage-psql-%s", backstage.Name)
}

func setBackstageImage(deployment *appsv1.Deployment, imageName string) {
visitContainers(&deployment.Spec.Template, func(container *v1.Container) {
if container.Name == _defaultBackstageMainContainerName || container.Name == _defaultBackstageInitContainerName {
container.Image = imageName
}
})
}

0 comments on commit 8643ba5

Please sign in to comment.