Skip to content

Commit

Permalink
Add the versions to the checkup report
Browse files Browse the repository at this point in the history
Signed-off-by: Arnon Gilboa <[email protected]>
  • Loading branch information
arnongilboa committed Jan 7, 2024
1 parent 2271c8a commit 45ca3f9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
5 changes: 5 additions & 0 deletions pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,17 @@ func (c *Checkup) checkVersions(ctx context.Context) error {
if err != nil {
return err
}
if len(cdis.Items) == 0 {
return errors.New("no CDI deployed in cluster")
}
if len(cdis.Items) != 1 {
return errors.New("expecting single CDI instance in cluster")
}
cnvVersion := cdis.Items[0].Labels["app.kubernetes.io/version"]

log.Printf("OCP version: %s, CNV version: %s", ocpVersion, cnvVersion)
c.results.OCPVersion = ocpVersion
c.results.CNVVersion = cnvVersion

return nil
}
Expand Down
26 changes: 19 additions & 7 deletions pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ const (
)

var (
testVMIName = "test-vmi"
testScName = "test-sc"
testScName2 = "test-sc2"
efsSc = "efs.csi.aws.com"
testDIC = "test-dic"
testVMIName = "test-vmi"
testScName = "test-sc"
testScName2 = "test-sc2"
efsSc = "efs.csi.aws.com"
testDIC = "test-dic"
testOCPVersion = "1.2.3"
testCNVVersion = "4.5.6"
)

func TestCheckupShouldSucceed(t *testing.T) {
Expand Down Expand Up @@ -191,6 +193,8 @@ func expectedResultsNoVMI(expectedResults map[string]string) {
// FIXME: fill relevant results
func successfulRunResults(vmiUnderTestName string) map[string]string {
return map[string]string{
reporter.OCPVersionKey: testOCPVersion,
reporter.CNVVersionKey: testCNVVersion,
reporter.DefaultStorageClassKey: testScName,
reporter.StorageProfilesWithEmptyClaimPropertySetsKey: "",
reporter.StorageProfilesWithSpecClaimPropertySetsKey: "",
Expand Down Expand Up @@ -627,9 +631,17 @@ func (cs *clientStub) GetClusterVersion(ctx context.Context, name string) (*conf
ver := &configv1.ClusterVersion{
Status: configv1.ClusterVersionStatus{
History: []configv1.UpdateHistory{
{
State: configv1.PartialUpdate,
Version: "partial-version",
},
{
State: configv1.CompletedUpdate,
Version: testOCPVersion,
},
{
State: configv1.CompletedUpdate,
Version: "1.2.3",
Version: "old-version",
},
},
},
Expand All @@ -644,7 +656,7 @@ func (cs *clientStub) ListCDIs(ctx context.Context) (*cdiv1.CDIList, error) {
{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/version": "4.5.6",
"app.kubernetes.io/version": testCNVVersion,
},
},
},
Expand Down
26 changes: 15 additions & 11 deletions pkg/internal/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
)

const (
OCPVersionKey = "ocpVersion"
CNVVersionKey = "cnvVersion"
DefaultStorageClassKey = "defaultStorageClass"
StorageProfilesWithEmptyClaimPropertySetsKey = "storageProfilesWithEmptyClaimPropertySets"
StorageProfilesWithSpecClaimPropertySetsKey = "storageProfilesWithSpecClaimPropertySets"
Expand Down Expand Up @@ -72,19 +74,21 @@ func FormatResults(checkupResults status.Results) map[string]string {
}

formattedResults := map[string]string{
DefaultStorageClassKey: checkupResults.DefaultStorageClass,
OCPVersionKey: checkupResults.OCPVersion,
CNVVersionKey: checkupResults.CNVVersion,
DefaultStorageClassKey: checkupResults.DefaultStorageClass,
StorageProfilesWithEmptyClaimPropertySetsKey: checkupResults.StorageProfilesWithEmptyClaimPropertySets,
StorageProfilesWithSpecClaimPropertySetsKey: checkupResults.StorageProfilesWithSpecClaimPropertySets,
StorageWithRWXKey: checkupResults.StorageWithRWX,
StorageMissingVolumeSnapshotClassKey: checkupResults.StorageMissingVolumeSnapshotClass,
GoldenImagesNotUpToDateKey: checkupResults.GoldenImagesNotUpToDate,
GoldenImagesNoDataSourceKey: checkupResults.GoldenImagesNoDataSource,
VMsWithNonVirtRbdStorageClassKey: checkupResults.VMsWithNonVirtRbdStorageClass,
VMsWithUnsetEfsStorageClassKey: checkupResults.VMsWithUnsetEfsStorageClass,
VMBootFromGoldenImageKey: checkupResults.VMBootFromGoldenImage,
VMVolumeCloneKey: checkupResults.VMVolumeClone,
VMLiveMigrationKey: checkupResults.VMLiveMigration,
VMHotplugVolumeKey: checkupResults.VMHotplugVolume,
StorageWithRWXKey: checkupResults.StorageWithRWX,
StorageMissingVolumeSnapshotClassKey: checkupResults.StorageMissingVolumeSnapshotClass,
GoldenImagesNotUpToDateKey: checkupResults.GoldenImagesNotUpToDate,
GoldenImagesNoDataSourceKey: checkupResults.GoldenImagesNoDataSource,
VMsWithNonVirtRbdStorageClassKey: checkupResults.VMsWithNonVirtRbdStorageClass,
VMsWithUnsetEfsStorageClassKey: checkupResults.VMsWithUnsetEfsStorageClass,
VMBootFromGoldenImageKey: checkupResults.VMBootFromGoldenImage,
VMVolumeCloneKey: checkupResults.VMVolumeClone,
VMLiveMigrationKey: checkupResults.VMLiveMigration,
VMHotplugVolumeKey: checkupResults.VMHotplugVolume,
}

return formattedResults
Expand Down
9 changes: 5 additions & 4 deletions pkg/internal/reporter/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ func TestReportShouldSuccessfullyReportResults(t *testing.T) {
var checkupStatus status.Status
checkupStatus.StartTimestamp = time.Now()
assert.NoError(t, testReporter.Report(checkupStatus))

checkupStatus.FailureReason = []string{}
checkupStatus.CompletionTimestamp = time.Now()
checkupStatus.Results = status.Results{
DefaultStorageClass: "test_sc",
OCPVersion: "1.2.3",
CNVVersion: "4.5.6",
DefaultStorageClass: "test_sc",
StorageProfilesWithEmptyClaimPropertySets: "sc1, sc2",
StorageProfilesWithSpecClaimPropertySets: "sc3, sc4",
StorageWithRWX: "sc5, sc6",
Expand All @@ -80,14 +81,15 @@ func TestReportShouldSuccessfullyReportResults(t *testing.T) {
VMLiveMigration: "success",
VMHotplugVolume: "fail",
}

assert.NoError(t, testReporter.Report(checkupStatus))

expectedReportData := map[string]string{
"status.succeeded": strconv.FormatBool(true),
"status.failureReason": "",
"status.startTimestamp": timestamp(checkupStatus.StartTimestamp),
"status.completionTimestamp": timestamp(checkupStatus.CompletionTimestamp),
"status.result.ocpVersion": checkupStatus.Results.OCPVersion,
"status.result.cnvVersion": checkupStatus.Results.CNVVersion,
"status.result.defaultStorageClass": checkupStatus.Results.DefaultStorageClass,
"status.result.storageProfilesWithEmptyClaimPropertySets": checkupStatus.Results.StorageProfilesWithEmptyClaimPropertySets,
"status.result.storageProfilesWithSpecClaimPropertySets": checkupStatus.Results.StorageProfilesWithSpecClaimPropertySets,
Expand All @@ -102,7 +104,6 @@ func TestReportShouldSuccessfullyReportResults(t *testing.T) {
"status.result.vmLiveMigration": checkupStatus.Results.VMLiveMigration,
"status.result.vmHotplugVolume": checkupStatus.Results.VMHotplugVolume,
}

assert.Equal(t, expectedReportData, getCheckupData(t, fakeClient, testNamespace, testConfigMapName))
})

Expand Down
2 changes: 2 additions & 0 deletions pkg/internal/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
)

type Results struct {
OCPVersion string
CNVVersion string
DefaultStorageClass string
StorageProfilesWithEmptyClaimPropertySets string
StorageProfilesWithSpecClaimPropertySets string
Expand Down

0 comments on commit 45ca3f9

Please sign in to comment.