Skip to content

Commit af89a02

Browse files
jharrodjwebster7emmahardisontorirevilla
authored
Feature automated failover
Co-authored-by: Joe Webster <[email protected]> Co-authored-by: emmahardison <[email protected]> Co-authored-by: Tori Revilla <[email protected]>
1 parent 77cc614 commit af89a02

File tree

142 files changed

+7530
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+7530
-698
lines changed

cli/cmd/install.go

Lines changed: 122 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
12471353
func createAndEnsureCRDs() error {
12481354
var bundleCRDYAML string

cli/cmd/install_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,7 @@ func TestPrepareYAMLFilePaths(t *testing.T) {
27392739
assert.NotEmpty(t, setupPath)
27402740
assert.Contains(t, setupPath, "setup")
27412741

2742-
assert.Len(t, setupYAMLPaths, 18)
2742+
assert.Len(t, setupYAMLPaths, 20)
27432743

27442744
assert.Contains(t, setupYAMLPaths, namespacePath)
27452745
assert.Contains(t, setupYAMLPaths, controllerServiceAccountPath)
@@ -2759,7 +2759,7 @@ func TestPrepareYAMLFilePaths(t *testing.T) {
27592759
assert.NotEmpty(t, installerDirectoryPath)
27602760
assert.NotEmpty(t, setupPath)
27612761

2762-
assert.Len(t, setupYAMLPaths, 21)
2762+
assert.Len(t, setupYAMLPaths, 23)
27632763

27642764
assert.Contains(t, setupYAMLPaths, controllerSCCPath)
27652765
assert.Contains(t, setupYAMLPaths, nodeLinuxSCCPath)
@@ -2817,7 +2817,7 @@ func TestPrepareYAMLFiles(t *testing.T) {
28172817
mockClient.EXPECT().ServerVersion().Return(versionutils.MustParseSemantic("v1.25.0")).AnyTimes()
28182818
},
28192819
expectedError: "",
2820-
expectedFiles: 12,
2820+
expectedFiles: 14,
28212821
},
28222822
{
28232823
name: "successful_kubernetes_with_windows",
@@ -2829,7 +2829,7 @@ func TestPrepareYAMLFiles(t *testing.T) {
28292829
mockClient.EXPECT().ServerVersion().Return(versionutils.MustParseSemantic("v1.25.0")).AnyTimes()
28302830
},
28312831
expectedError: "",
2832-
expectedFiles: 14,
2832+
expectedFiles: 16,
28332833
},
28342834
{
28352835
name: "successful_openshift_linux_only",
@@ -2841,7 +2841,7 @@ func TestPrepareYAMLFiles(t *testing.T) {
28412841
mockClient.EXPECT().ServerVersion().Return(versionutils.MustParseSemantic("v1.25.0")).AnyTimes()
28422842
},
28432843
expectedError: "",
2844-
expectedFiles: 14,
2844+
expectedFiles: 16,
28452845
},
28462846
{
28472847
name: "successful_openshift_with_windows",
@@ -2853,7 +2853,7 @@ func TestPrepareYAMLFiles(t *testing.T) {
28532853
mockClient.EXPECT().ServerVersion().Return(versionutils.MustParseSemantic("v1.25.0")).AnyTimes()
28542854
},
28552855
expectedError: "",
2856-
expectedFiles: 17,
2856+
expectedFiles: 19,
28572857
},
28582858
{
28592859
name: "with_cloud_identity",
@@ -2865,7 +2865,7 @@ func TestPrepareYAMLFiles(t *testing.T) {
28652865
mockClient.EXPECT().ServerVersion().Return(versionutils.MustParseSemantic("v1.25.0")).AnyTimes()
28662866
},
28672867
expectedError: "",
2868-
expectedFiles: 12,
2868+
expectedFiles: 14,
28692869
},
28702870
}
28712871

@@ -2890,6 +2890,8 @@ func TestPrepareYAMLFiles(t *testing.T) {
28902890
controllerSCCPath = filepath.Join(tempDir, "controller-scc.yaml")
28912891
nodeLinuxSCCPath = filepath.Join(tempDir, "node-scc.yaml")
28922892
nodeWindowsSCCPath = filepath.Join(tempDir, "windows-scc.yaml")
2893+
nodeRemediationTemplatePath = filepath.Join(tempDir, "node-remediation-template.yaml")
2894+
nodeRemediationClusterRolePath = filepath.Join(tempDir, "node-remediation-cluster-role.yaml")
28932895

28942896
windows = tt.windows
28952897
cloudIdentity = tt.cloudIdentity

0 commit comments

Comments
 (0)