@@ -37,22 +37,24 @@ const (
3737 PreferredNamespace = tridentconfig .OrchestratorName
3838
3939 // CRD names
40- ActionMirrorUpdateCRDName = "tridentactionmirrorupdates.trident.netapp.io"
41- ActionSnapshotRestoreCRDName = "tridentactionsnapshotrestores.trident.netapp.io"
42- BackendConfigCRDName = "tridentbackendconfigs.trident.netapp.io"
43- BackendCRDName = "tridentbackends.trident.netapp.io"
44- MirrorRelationshipCRDName = "tridentmirrorrelationships.trident.netapp.io"
45- NodeCRDName = "tridentnodes.trident.netapp.io"
46- SnapshotCRDName = "tridentsnapshots.trident.netapp.io"
47- SnapshotInfoCRDName = "tridentsnapshotinfos.trident.netapp.io"
48- GroupSnapshotCRDName = "tridentgroupsnapshots.trident.netapp.io"
49- StorageClassCRDName = "tridentstorageclasses.trident.netapp.io"
50- TransactionCRDName = "tridenttransactions.trident.netapp.io"
51- VersionCRDName = "tridentversions.trident.netapp.io"
52- VolumeCRDName = "tridentvolumes.trident.netapp.io"
53- VolumePublicationCRDName = "tridentvolumepublications.trident.netapp.io"
54- VolumeReferenceCRDName = "tridentvolumereferences.trident.netapp.io"
55- ConfiguratorCRDName = "tridentconfigurators.trident.netapp.io"
40+ ActionMirrorUpdateCRDName = "tridentactionmirrorupdates.trident.netapp.io"
41+ ActionSnapshotRestoreCRDName = "tridentactionsnapshotrestores.trident.netapp.io"
42+ BackendConfigCRDName = "tridentbackendconfigs.trident.netapp.io"
43+ BackendCRDName = "tridentbackends.trident.netapp.io"
44+ MirrorRelationshipCRDName = "tridentmirrorrelationships.trident.netapp.io"
45+ NodeCRDName = "tridentnodes.trident.netapp.io"
46+ NodeRemediationCRDName = "tridentnoderemediations.trident.netapp.io"
47+ NodeRemediationTemplateCRDName = "tridentnoderemediationtemplates.trident.netapp.io"
48+ SnapshotCRDName = "tridentsnapshots.trident.netapp.io"
49+ SnapshotInfoCRDName = "tridentsnapshotinfos.trident.netapp.io"
50+ GroupSnapshotCRDName = "tridentgroupsnapshots.trident.netapp.io"
51+ StorageClassCRDName = "tridentstorageclasses.trident.netapp.io"
52+ TransactionCRDName = "tridenttransactions.trident.netapp.io"
53+ VersionCRDName = "tridentversions.trident.netapp.io"
54+ VolumeCRDName = "tridentvolumes.trident.netapp.io"
55+ VolumePublicationCRDName = "tridentvolumepublications.trident.netapp.io"
56+ VolumeReferenceCRDName = "tridentvolumereferences.trident.netapp.io"
57+ ConfiguratorCRDName = "tridentconfigurators.trident.netapp.io"
5658
5759 ControllerRoleFilename = "trident-controller-role.yaml"
5860 ControllerClusterRoleFilename = "trident-controller-clusterrole.yaml"
@@ -79,6 +81,9 @@ const (
7981 ServiceFilename = "trident-service.yaml"
8082 ResourceQuotaFilename = "trident-resourcequota.yaml"
8183
84+ NodeRemediationTemplateFilename = "trident-node-remediation-template.yaml"
85+ NodeRemediationClusterRoleFilename = "trident-node-remediation-clusterrole.yaml"
86+
8287 TridentEncryptionKeys = "trident-encryption-keys"
8388
8489 TridentCSI = "trident-csi"
@@ -161,6 +166,8 @@ var (
161166 nodeLinuxSCCPath string
162167 nodeWindowsSCCPath string
163168 setupYAMLPaths []string
169+ nodeRemediationTemplatePath string
170+ nodeRemediationClusterRolePath string
164171
165172 appLabel string
166173 appLabelKey string
@@ -176,6 +183,8 @@ var (
176183 BackendCRDName ,
177184 MirrorRelationshipCRDName ,
178185 NodeCRDName ,
186+ NodeRemediationCRDName ,
187+ NodeRemediationTemplateCRDName ,
179188 VolumeReferenceCRDName ,
180189 SnapshotCRDName ,
181190 GroupSnapshotCRDName ,
@@ -555,6 +564,8 @@ func prepareYAMLFilePaths() error {
555564 deploymentPath = path .Join (setupPath , DeploymentFilename )
556565 resourceQuotaPath = path .Join (setupPath , ResourceQuotaFilename )
557566 windowsDaemonSetPath = path .Join (setupPath , WindowsDaemonSetFilename )
567+ nodeRemediationTemplatePath = path .Join (setupPath , NodeRemediationTemplateFilename )
568+ nodeRemediationClusterRolePath = path .Join (setupPath , NodeRemediationClusterRoleFilename )
558569
559570 setupYAMLPaths = []string {
560571 namespacePath ,
@@ -575,6 +586,8 @@ func prepareYAMLFilePaths() error {
575586 daemonsetPath ,
576587 windowsDaemonSetPath ,
577588 resourceQuotaPath ,
589+ nodeRemediationClusterRolePath ,
590+ nodeRemediationTemplatePath ,
578591 }
579592
580593 if client .Flavor () == k8sclient .FlavorOpenShift {
@@ -667,6 +680,17 @@ func prepareYAMLFiles() error {
667680 return fmt .Errorf ("could not write resource quota YAML file; %v" , err )
668681 }
669682
683+ // TridentNodeRemediation resources
684+ nodeRemediationTemplateYaml := k8sclient .GetNodeRemediationTemplateYAML (TridentPodNamespace )
685+ if err = writeFile (nodeRemediationTemplatePath , nodeRemediationTemplateYaml ); err != nil {
686+ return fmt .Errorf ("could not write file %s; %v" , NodeRemediationTemplateFilename , err )
687+ }
688+
689+ nodeRemediationClusterRoleYaml := k8sclient .GetNodeRemediationClusterRoleYAML ()
690+ if err = writeFile (nodeRemediationClusterRolePath , nodeRemediationClusterRoleYaml ); err != nil {
691+ return fmt .Errorf ("could not write file %s; %v" , NodeRemediationClusterRoleFilename , err )
692+ }
693+
670694 deploymentArgs := & k8sclient.DeploymentYAMLArguments {
671695 DeploymentName : getDeploymentName (),
672696 TridentImage : tridentImage ,
@@ -1198,6 +1222,22 @@ func installTrident() (returnError error) {
11981222
11991223 Log ().WithFields (logFields ).Info ("Created Trident daemonset." )
12001224
1225+ // Remove any TridentNodeRemediation resources objects from a previous Trident installation
1226+ if returnError = deleteNodeRemediationResources (TridentPodNamespace ); returnError != nil {
1227+ returnError = fmt .Errorf ("could not remove tridentNodeRemediation resources; " +
1228+ "please delete them manually and try again" )
1229+ return
1230+ }
1231+
1232+ // Create TridentNodeRemediation resources
1233+ if enableForceDetach {
1234+ if returnError = createNodeRemediationResources (); returnError != nil {
1235+ returnError = fmt .Errorf ("could not create TridentNodeRemediation resources for automatic force-detach; %v" ,
1236+ returnError )
1237+ return
1238+ }
1239+ }
1240+
12011241 // Wait for Trident pod to be running
12021242 var tridentPod * v1.Pod
12031243
@@ -1243,6 +1283,72 @@ func createNamespace() (returnError error) {
12431283 return nil
12441284}
12451285
1286+ func deleteNodeRemediationResources (namespace string ) error {
1287+ yaml := k8sclient .GetNodeRemediationClusterRoleYAML ()
1288+ err := client .DeleteObjectByYAML (yaml , true )
1289+ if err != nil {
1290+ return fmt .Errorf ("could not delete TridentNodeRemediation clusterRole; %v" , err )
1291+ }
1292+
1293+ yaml = k8sclient .GetNodeRemediationTemplateCRDYAML ()
1294+ err = client .DeleteObjectByYAML (yaml , true )
1295+ if err != nil {
1296+ return fmt .Errorf ("could not delete TridentNodeRemediationTemplate CR; %v" , err )
1297+ }
1298+
1299+ return nil
1300+ }
1301+
1302+ func createNodeRemediationClusterRole () (returnError error ) {
1303+ var logFields LogFields
1304+
1305+ // Create resources
1306+ if useYAML && fileExists (nodeRemediationClusterRolePath ) {
1307+ logFields = LogFields {"path" : nodeRemediationClusterRolePath }
1308+ returnError = client .CreateObjectByFile (nodeRemediationClusterRolePath )
1309+ } else {
1310+ yaml := k8sclient .GetNodeRemediationClusterRoleYAML ()
1311+ returnError = client .CreateObjectByYAML (yaml )
1312+ }
1313+
1314+ if returnError != nil {
1315+ returnError = fmt .Errorf ("could not create TridentNodeRemediation clusterRole; %v" , returnError )
1316+ return
1317+ }
1318+ Log ().WithFields (logFields ).Info ("Created TridentNodeRemediation clusterRole." )
1319+ return nil
1320+ }
1321+
1322+ func createNodeRemediationTemplate () (returnError error ) {
1323+ var logFields LogFields
1324+
1325+ // Create resources
1326+ if useYAML && fileExists (nodeRemediationTemplatePath ) {
1327+ logFields = LogFields {"path" : nodeRemediationTemplatePath }
1328+ returnError = client .CreateObjectByFile (nodeRemediationTemplatePath )
1329+ } else {
1330+ yaml := k8sclient .GetNodeRemediationTemplateYAML (TridentPodNamespace )
1331+ returnError = client .CreateObjectByYAML (yaml )
1332+ }
1333+
1334+ if returnError != nil {
1335+ returnError = fmt .Errorf ("could not create TridentNodeRemediationTemplate; %v" , returnError )
1336+ return
1337+ }
1338+ Log ().WithFields (logFields ).Info ("Created TridentNodeRemediationTemplate." )
1339+ return nil
1340+ }
1341+
1342+ func createNodeRemediationResources () (returnError error ) {
1343+ if returnError = createNodeRemediationClusterRole (); returnError != nil {
1344+ return
1345+ }
1346+ if returnError = createNodeRemediationTemplate (); returnError != nil {
1347+ return
1348+ }
1349+ return nil
1350+ }
1351+
12461352// createAndEnsureCRDs creates CRDs or updates existing ones. If we are on an upgrade install, CRDs should be updated.
12471353func createAndEnsureCRDs () error {
12481354 var bundleCRDYAML string
0 commit comments