Skip to content

Commit

Permalink
add constant viewerContainerName for registry viewer container
Browse files Browse the repository at this point in the history
Signed-off-by: Horiodino <[email protected]>
  • Loading branch information
Horiodino committed Dec 19, 2024
1 parent 02e3de4 commit 4001349
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions controllers/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const viewerContainerName = "registry-viewer"

// updateDeployment ensures that a devfile registry deployment exists on the cluster and is up to date with the custom resource
func (r *DevfileRegistryReconciler) updateDeployment(ctx context.Context, cr *registryv1alpha1.DevfileRegistry, dep *appsv1.Deployment) error {
// Check to see if the existing devfile registry deployment needs to be updated
Expand Down Expand Up @@ -254,7 +256,7 @@ func updateRegistryHeadlessEnv(envVars []corev1.EnvVar, headless bool) []corev1.
func removeViewerContainer(containers []corev1.Container) []corev1.Container {
var newContainers []corev1.Container
for _, container := range containers {
if container.Name != "registry-viewer" {
if container.Name != viewerContainerName {
newContainers = append(newContainers, container)
}
}
Expand All @@ -272,7 +274,7 @@ func (r *DevfileRegistryReconciler) updateDeploymentForHeadlessChange(cr *regist
// Check if viewer container already exists before adding
viewerExists := false
for _, container := range dep.Spec.Template.Spec.Containers {
if container.Name == "registry-viewer" {
if container.Name == viewerContainerName {
viewerExists = true
break
}
Expand All @@ -297,7 +299,7 @@ func (r *DevfileRegistryReconciler) updateDeploymentForHeadlessChange(cr *regist
dep.Spec.Template.Spec.Containers = append(dep.Spec.Template.Spec.Containers, corev1.Container{
Image: registry.GetRegistryViewerImage(cr),
ImagePullPolicy: registry.GetRegistryViewerImagePullPolicy(cr),
Name: "registry-viewer",
Name: viewerContainerName,
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: &allowPrivilegeEscalation,
RunAsNonRoot: &runAsNonRoot,
Expand Down Expand Up @@ -374,7 +376,7 @@ func (r *DevfileRegistryReconciler) updateDeploymentForHeadlessChange(cr *regist
// Check if viewer container needs to be removed
viewerExists := false
for _, container := range dep.Spec.Template.Spec.Containers {
if container.Name == "registry-viewer" {
if container.Name == viewerContainerName {
viewerExists = true
break
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestUpdateDeploymentForHeadlessChange(t *testing.T) {
Env: []corev1.EnvVar{{Name: "REGISTRY_HEADLESS", Value: "false"}},
},
{
Name: "registry-viewer",
Name: viewerContainerName,
},
}
return dep
Expand All @@ -92,7 +92,7 @@ func TestUpdateDeploymentForHeadlessChange(t *testing.T) {
Env: []corev1.EnvVar{{Name: "REGISTRY_HEADLESS", Value: "false"}},
},
{
Name: "registry-viewer",
Name: viewerContainerName,
},
}
return dep
Expand Down

0 comments on commit 4001349

Please sign in to comment.