Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Shelly Kagan <skagan@redhat.com>
  • Loading branch information
ShellyKa13 committed Dec 7, 2023
1 parent edf37ad commit 69e8fdb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
16 changes: 8 additions & 8 deletions pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ const (

AnnDefaultStorageClass = "storageclass.kubernetes.io/is-default-class"

ErrNoDefaultStorageClass = "No default storage class."
ErrMultipleDefaultStorageClasses = "There are multiple default storage classes."
ErrEmptyClaimPropertySets = "There are StorageProfiles with empty ClaimPropertySets (unknown provisioners)."
ErrNoDefaultStorageClass = "no default storage class"
ErrMultipleDefaultStorageClasses = "there are multiple default storage classes"
ErrEmptyClaimPropertySets = "there are StorageProfiles with empty ClaimPropertySets (unknown provisioners)"
// FIXME: need to decide of we want to return errors in this cases
// errMissingVolumeSnapshotClass = "There are StorageProfiles missing VolumeSnapshotClass."
// errVMsWithNonVirtRbdStorageClass = "There are VMs using the plain RBD storageclass when the virtualization storageclass exists."
ErrVMsWithUnsetEfsStorageClass = "There are VMs using an EFS storageclass where the gid and uid are not set in the storageclass."
ErrGoldenImagesNotUpToDate = "There are golden images whose DataImportCron is not up to date or DataSource is not ready."
ErrGoldenImageNoDataSource = "DataSource has no PVC or Snapshot source"
// errMissingVolumeSnapshotClass = "there are StorageProfiles missing VolumeSnapshotClass"
// errVMsWithNonVirtRbdStorageClass = "there are VMs using the plain RBD storageclass when the virtualization storageclass exists"
ErrVMsWithUnsetEfsStorageClass = "there are VMs using an EFS storageclass where the gid and uid are not set in the storageclass"
ErrGoldenImagesNotUpToDate = "there are golden images whose DataImportCron is not up to date or DataSource is not ready"
ErrGoldenImageNoDataSource = "dataSource has no PVC or Snapshot source"
MessageSkipNoGoldenImage = "Skip check - no golden image PVC or Snapshot"
MessageSkipNoVMI = "Skip check - no VMI"

Expand Down
34 changes: 20 additions & 14 deletions pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,27 @@ func TestCheckupShouldReturnErrorWhen(t *testing.T) {
expectedErr: checkup.ErrMultipleDefaultStorageClasses,
},
"storageProfileIncomplete": {
clientConfig: clientConfig{spIncomplete: true},
expectedResults: map[string]string{reporter.StorageProfilesWithEmptyClaimPropertySetsKey: testScName, reporter.StorageProfilesWithSpecClaimPropertySetsKey: testScName, reporter.StorageWithRWXKey: ""},
expectedErr: checkup.ErrEmptyClaimPropertySets,
clientConfig: clientConfig{spIncomplete: true},
expectedResults: map[string]string{reporter.StorageProfilesWithEmptyClaimPropertySetsKey: testScName,
reporter.StorageProfilesWithSpecClaimPropertySetsKey: testScName, reporter.StorageWithRWXKey: ""},
expectedErr: checkup.ErrEmptyClaimPropertySets,
},
"noVolumeSnapshotClasses": {
clientConfig: clientConfig{noVolumeSnapshotClasses: true},
expectedResults: map[string]string{reporter.StorageMissingVolumeSnapshotClassKey: testScName},
expectedErr: "",
},
"dataSourceNotReady": {
clientConfig: clientConfig{dataSourceNotReady: true, expectNoVMI: true},
expectedResults: map[string]string{reporter.GoldenImagesNotUpToDateKey: testNamespace + "/" + testDIC, reporter.VMBootFromGoldenImageKey: checkup.MessageSkipNoGoldenImage},
expectedErr: checkup.ErrGoldenImagesNotUpToDate,
clientConfig: clientConfig{dataSourceNotReady: true, expectNoVMI: true},
expectedResults: map[string]string{reporter.GoldenImagesNotUpToDateKey: testNamespace + "/" + testDIC,
reporter.VMBootFromGoldenImageKey: checkup.MessageSkipNoGoldenImage},
expectedErr: checkup.ErrGoldenImagesNotUpToDate,
},
"dicNoDataSource": {
clientConfig: clientConfig{dicNoDataSource: true, expectNoVMI: true},
expectedResults: map[string]string{reporter.GoldenImagesNoDataSourceKey: testNamespace + "/" + testDIC, reporter.VMBootFromGoldenImageKey: checkup.MessageSkipNoGoldenImage},
expectedErr: checkup.ErrGoldenImageNoDataSource,
clientConfig: clientConfig{dicNoDataSource: true, expectNoVMI: true},
expectedResults: map[string]string{reporter.GoldenImagesNoDataSourceKey: testNamespace + "/" + testDIC,
reporter.VMBootFromGoldenImageKey: checkup.MessageSkipNoGoldenImage},
expectedErr: checkup.ErrGoldenImageNoDataSource,
},
"vmisWithUnsetEfsSC": {
clientConfig: clientConfig{unsetEfsStorageClass: true},
Expand Down Expand Up @@ -182,7 +185,6 @@ func expectedResultsNoVMI(expectedResults map[string]string) {
expectedResults[reporter.VMHotplugVolumeKey] = checkup.MessageSkipNoVMI
expectedResults[reporter.VMLiveMigrationKey] = checkup.MessageSkipNoVMI
expectedResults[reporter.VMVolumeCloneKey] = ""

}

// FIXME: fill relevant results
Expand Down Expand Up @@ -441,7 +443,9 @@ func (cs *clientStub) ListStorageProfiles(ctx context.Context) (*cdiv1.StoragePr
}
if cs.spIncomplete {
spList.Items[0].Status.ClaimPropertySets = []cdiv1.ClaimPropertySet{}
spList.Items[0].Spec.ClaimPropertySets = []cdiv1.ClaimPropertySet{{AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany}}}
spList.Items[0].Spec.ClaimPropertySets = []cdiv1.ClaimPropertySet{
{AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany}},
}
}
return spList, nil
}
Expand Down Expand Up @@ -500,9 +504,11 @@ func (cs *clientStub) ListVirtualMachinesInstances(ctx context.Context, namespac
{
Name: "test-vol",
VolumeSource: kvcorev1.VolumeSource{
PersistentVolumeClaim: &kvcorev1.PersistentVolumeClaimVolumeSource{PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "test-pvc",
}},
PersistentVolumeClaim: &kvcorev1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "test-pvc",
},
},
},
},
},
Expand Down
32 changes: 24 additions & 8 deletions pkg/internal/launcher/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,30 @@ func TestLauncherRunShouldFailWhen(t *testing.T) {
reporter reporterStub
errors []string
}{
"report fails": {checkup: checkupStub{}, reporter: reporterStub{failReport: errReport}, errors: []string{errReport.Error()}},
"setup fails": {checkup: checkupStub{failSetup: errSetup}, reporter: reporterStub{}, errors: []string{errSetup.Error()}},
"run fails": {checkup: checkupStub{failRun: errRun}, reporter: reporterStub{}, errors: []string{errRun.Error()}},
"teardown fails": {checkup: checkupStub{failTeardown: errTeardown}, reporter: reporterStub{}, errors: []string{errTeardown.Error()}},
"setup and 2nd report fail": {checkup: checkupStub{failSetup: errSetup}, reporter: reporterStub{failReport: errReport, failOnSecondReport: true}, errors: []string{errSetup.Error(), errReport.Error()}},
"run and report fail": {checkup: checkupStub{failRun: errRun}, reporter: reporterStub{failReport: errReport, failOnSecondReport: true}, errors: []string{errRun.Error(), errReport.Error()}},
"teardown and report fail": {checkup: checkupStub{failTeardown: errTeardown}, reporter: reporterStub{failReport: errReport, failOnSecondReport: true}, errors: []string{errTeardown.Error(), errReport.Error()}},
"run, teardown and report fail": {checkup: checkupStub{failRun: errRun, failTeardown: errTeardown}, reporter: reporterStub{failReport: errReport, failOnSecondReport: true}, errors: []string{errRun.Error(), errTeardown.Error(), errReport.Error()}},
"report fails": {checkup: checkupStub{},
reporter: reporterStub{failReport: errReport},
errors: []string{errReport.Error()}},
"setup fails": {checkup: checkupStub{failSetup: errSetup},
reporter: reporterStub{},
errors: []string{errSetup.Error()}},
"run fails": {checkup: checkupStub{failRun: errRun},
reporter: reporterStub{},
errors: []string{errRun.Error()}},
"teardown fails": {checkup: checkupStub{failTeardown: errTeardown},
reporter: reporterStub{},
errors: []string{errTeardown.Error()}},
"setup and 2nd report fail": {checkup: checkupStub{failSetup: errSetup},
reporter: reporterStub{failReport: errReport, failOnSecondReport: true},
errors: []string{errSetup.Error(), errReport.Error()}},
"run and report fail": {checkup: checkupStub{failRun: errRun},
reporter: reporterStub{failReport: errReport, failOnSecondReport: true},
errors: []string{errRun.Error(), errReport.Error()}},
"teardown and report fail": {checkup: checkupStub{failTeardown: errTeardown},
reporter: reporterStub{failReport: errReport, failOnSecondReport: true},
errors: []string{errTeardown.Error(), errReport.Error()}},
"run, teardown and report fail": {checkup: checkupStub{failRun: errRun, failTeardown: errTeardown},
reporter: reporterStub{failReport: errReport, failOnSecondReport: true},
errors: []string{errRun.Error(), errTeardown.Error(), errReport.Error()}},
}

for name, tc := range tests {
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *Reporter) Report(checkupStatus status.Status) error {
return r.Reporter.Report(checkupStatus.Status)
}

//FormatResults returns a map representing the checkup results
// FormatResults returns a map representing the checkup results
func FormatResults(checkupResults status.Results) map[string]string {
var emptyResults status.Results
if checkupResults == emptyResults {
Expand Down

0 comments on commit 69e8fdb

Please sign in to comment.