Skip to content

Commit

Permalink
fix: replacing of namespace annotation when openshift-cnv namespace is
Browse files Browse the repository at this point in the history
set
When ssp CR contains openshift-cnv namespace as a target namespace
for pipelines, ssp operator recognized this namespace as user defined
and deployed configmaps and roleBindings to a single namespace, instead
of two namespaces. That broke our default installation path in ds. This
change adds a check if the pipeline namespace in the CR is openshift-cnv,
then it is not used as a user defined namespace and
kubevirt.io/deploy-namespace annotation is used instead.

Signed-off-by: Karel Simon <[email protected]>
  • Loading branch information
ksimon1 committed Sep 7, 2023
1 parent 72c7fba commit 9e737a4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/operands/tekton-pipelines/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
tektonCrd = "tasks.tekton.dev"
deployNamespaceAnnotation = "kubevirt.io/deploy-namespace"
pipelineServiceAccountName = "pipeline"
openshiftCNVNamespace = "openshift-cnv"
)

var namespaceRegex = regexp.MustCompile(namespacePattern)
Expand Down Expand Up @@ -281,7 +282,7 @@ func reconcileRoleBindingsFuncs(rolebindings []rbac.RoleBinding) []common.Reconc
}

func getTektonPipelinesNamespace(request *common.Request) (string, bool) {
if request.Instance.Spec.TektonPipelines != nil && request.Instance.Spec.TektonPipelines.Namespace != "" {
if request.Instance.Spec.TektonPipelines != nil && request.Instance.Spec.TektonPipelines.Namespace != "" && request.Instance.Spec.TektonPipelines.Namespace != openshiftCNVNamespace {
return request.Instance.Spec.TektonPipelines.Namespace, true
}
return request.Instance.Namespace, false
Expand Down
47 changes: 47 additions & 0 deletions internal/operands/tekton-pipelines/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,53 @@ var _ = Describe("environments", func() {
})
})

Context("With openshift-cnv namespace in ssp CR for pipelines", func() {
BeforeEach(func() {
request.Instance.Spec.FeatureGates.DeployTektonTaskResources = true
request.Instance.Spec.TektonPipelines = &ssp.TektonPipelines{
Namespace: openshiftCNVNamespace,
}
})

It("kubevirt.io/deploy-namespace annotation in configMaps should not be replaced", func() {
_, err := operand.Reconcile(request)
Expect(err).ToNot(HaveOccurred())

for _, configMap := range bundle.ConfigMaps {
objNamespace := namespace

if configMap.Name == "test-cm" {
configMap.Namespace = testDifferentNamespace
objNamespace = testDifferentNamespace
}

key := client.ObjectKeyFromObject(&configMap)
cm := &v1.ConfigMap{}
Expect(request.Client.Get(request.Context, key, cm)).ToNot(HaveOccurred())
Expect(cm.Namespace).To(Equal(objNamespace), cm.Name+" configMap namespace should equal")
}
})

It("kubevirt.io/deploy-namespace annotation in roleBindings should not be replaced", func() {
_, err := operand.Reconcile(request)
Expect(err).ToNot(HaveOccurred())

for _, roleBinding := range bundle.RoleBindings {
objNamespace := namespace

if roleBinding.Name == "test-rb" {
roleBinding.Namespace = testDifferentNamespace
objNamespace = testDifferentNamespace
}

key := client.ObjectKeyFromObject(&roleBinding)
rb := &rbac.RoleBinding{}
Expect(request.Client.Get(request.Context, key, rb)).ToNot(HaveOccurred())
Expect(rb.Namespace).To(Equal(objNamespace), rb.Name+" roleBinding namespace should equal")
}
})
})

Context("Without user defined namespace in ssp CR for pipelines", func() {
BeforeEach(func() {
request.Instance.Spec.FeatureGates.DeployTektonTaskResources = true
Expand Down

0 comments on commit 9e737a4

Please sign in to comment.