Skip to content

Commit 2e23ef2

Browse files
authored
Merge pull request #693 from igorpick/pick/noobaa-operator/allow-rejected
Skip namespacestores with invalid configuration only
2 parents 19f4ded + d7b0490 commit 2e23ef2

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

pkg/system/phase4_configuring.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,6 @@ func (r *Reconciler) SetDesiredDeploymentEndpoint() error {
399399

400400
func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container *corev1.Container) error {
401401

402-
log := r.Logger.WithField("source", "SystemReconciler:setDesiredEndpointMounts")
403-
404402
namespaceStoreList := &nbv1.NamespaceStoreList{}
405403
if !util.KubeList(namespaceStoreList, client.InNamespace(options.Namespace)) {
406404
return fmt.Errorf("Error: Cant list namespacestores")
@@ -409,8 +407,10 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
409407
container.VolumeMounts = r.DefaultDeploymentEndpoint.Containers[0].VolumeMounts
410408

411409
for _, nsStore := range namespaceStoreList.Items {
412-
if nsStore.Status.Phase == nbv1.NamespaceStorePhaseRejected {
413-
log.Warnf("namespacestore %s is in rejected phase", nsStore.Name)
410+
// Since namespacestore is able to get a rejected state on runtime errors,
411+
// we want to skip namespacestores with invalid configuration only.
412+
// Remove this validation when the kubernetes validations hooks will be available.
413+
if !r.validateNsStoreNSFS(&nsStore) {
414414
continue
415415
}
416416
if nsStore.Spec.NSFS != nil {
@@ -455,6 +455,37 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
455455
return nil
456456
}
457457

458+
// Duplicate code from validation.go namespacetore pkg.
459+
// Cannot import the namespacestore pkg, because the pkg imports the system pkg
460+
// TODO remove the code
461+
func (r *Reconciler) validateNsStoreNSFS(nsStore *nbv1.NamespaceStore) bool {
462+
nsfs := nsStore.Spec.NSFS
463+
464+
if nsfs == nil {
465+
return true
466+
}
467+
468+
//pvcName validation
469+
if nsfs.PvcName == "" {
470+
return false
471+
}
472+
473+
//SubPath validation
474+
if nsfs.SubPath != "" {
475+
path := nsfs.SubPath
476+
if len(path) > 0 && path[0] == '/' {
477+
return false
478+
}
479+
parts := strings.Split(path, "/")
480+
for _, item := range parts {
481+
if item == ".." {
482+
return false
483+
}
484+
}
485+
}
486+
return true
487+
}
488+
458489
// awaitEndpointDeploymentPods wait for the the endpoint deployment to become ready
459490
// before creating the controlling HPA
460491
// See https://bugzilla.redhat.com/show_bug.cgi?id=1885524

0 commit comments

Comments
 (0)