@@ -23,6 +23,8 @@ export class ExistingPvcComponent implements OnInit {
23
23
@Input ( ) pvcGroup : FormGroup ;
24
24
25
25
pvcs : PVCResponseObject [ ] = [ ] ;
26
+ protectedBPvcs : Set < string > = new Set < string > ( ) ;
27
+ unclassifiedPvcs : Set < string > = new Set < string > ( ) ;
26
28
private mountedVolumes : Set < string > = new Set < string > ( ) ; //AAW
27
29
matcher = new PvcErrorStateMatcher ( ) ; //AAW
28
30
subscriptions = new Subscription ( ) ; //AAW
@@ -36,6 +38,13 @@ export class ExistingPvcComponent implements OnInit {
36
38
this . ns . getSelectedNamespace ( ) . subscribe ( ns => {
37
39
this . backend . getPVCs ( ns ) . subscribe ( pvcs => {
38
40
this . pvcs = pvcs ;
41
+ this . protectedBPvcs . clear ( ) ;
42
+ this . unclassifiedPvcs . clear ( ) ;
43
+ pvcs . forEach ( pvc =>
44
+ pvc . labels ?. [ 'data.statcan.gc.ca/classification' ] === 'protected-b'
45
+ ? this . protectedBPvcs . add ( pvc . name )
46
+ : this . unclassifiedPvcs . add ( pvc . name ) ,
47
+ ) ;
39
48
} ) ;
40
49
} ) ;
41
50
// Get the list of mounted volumes of the existing Notebooks in the selected Namespace, AAW
@@ -53,7 +62,11 @@ export class ExistingPvcComponent implements OnInit {
53
62
) ;
54
63
this . pvcGroup
55
64
. get ( 'claimName' )
56
- . setValidators ( [ Validators . required , this . isMountedValidator ( ) ] ) ; //AAW
65
+ . setValidators ( [
66
+ Validators . required ,
67
+ this . isMountedValidator ( ) ,
68
+ this . isProtectedBValidator ( ) ,
69
+ ] ) ; //AAW
57
70
}
58
71
59
72
// AAW
@@ -66,6 +79,12 @@ export class ExistingPvcComponent implements OnInit {
66
79
if ( volumeName . hasError ( 'isMounted' ) ) {
67
80
return $localize `Is mounted` ;
68
81
}
82
+ if ( volumeName . hasError ( 'isNotProb' ) ) {
83
+ return $localize `Notebook is protected B but volume is unclassified` ;
84
+ }
85
+ if ( volumeName . hasError ( 'isNotUnclassified' ) ) {
86
+ return $localize `Notebook is unclassified but volume is protected B` ;
87
+ }
69
88
}
70
89
71
90
//Method that disables selecting a mounted pvc, AAW
@@ -75,6 +94,29 @@ export class ExistingPvcComponent implements OnInit {
75
94
return exists ? { isMounted : true } : null ;
76
95
} ;
77
96
}
97
+
98
+ //Method that disables selecting a mounted pvc, AAW
99
+ private isProtectedBValidator ( ) : ValidatorFn {
100
+ return ( control : AbstractControl ) : { [ key : string ] : any } => {
101
+ const protB =
102
+ control . parent . parent . parent . parent . parent . get ( 'prob' ) . value ;
103
+ // Check for each volume if it's ok.
104
+ if ( protB && ! this . protectedBPvcs . has ( control . value ) ) {
105
+ return { isNotProb : true } ;
106
+ } else if ( ! protB && ! this . unclassifiedPvcs . has ( control . value ) ) {
107
+ return { isNotUnclassified : true } ;
108
+ }
109
+ return null ;
110
+ } ;
111
+ }
112
+
113
+ public isProtectedLabel ( pvc ) : string {
114
+ let status = '' ;
115
+ if ( pvc . labels ?. [ 'data.statcan.gc.ca/classification' ] === 'protected-b' ) {
116
+ status = '(protected-b)' ;
117
+ }
118
+ return status ;
119
+ }
78
120
}
79
121
80
122
// Error when invalid control is dirty, touched, or submitted, AAW
0 commit comments